chrome-wrapper 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash
  2. # Copyright (c) 2011 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Running Chromium via this script makes it possible to set Chromium as the
  6. # default browser directly out of a compile, without needing to package it.
  7. DESKTOP="chromium-devel"
  8. TITLE="Chromium"
  9. usage() {
  10. echo "$0 [--gdb] [--help] [--man-page] [--] [chrome-options]"
  11. echo
  12. echo " --gdb Start within gdb"
  13. echo " --help This help screen"
  14. echo " --man-page Open the man page in the tree"
  15. }
  16. # Check to see if there is a desktop file of the given name.
  17. exists_desktop_file() {
  18. # Build a search list from $XDG_DATA_HOME and $XDG_DATA_DIRS, the latter
  19. # of which can itself be a colon-separated list of directories to search.
  20. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  21. IFS=:
  22. for dir in $search; do
  23. unset IFS
  24. [ "$dir" -a -d "$dir/applications" ] || continue
  25. [ -r "$dir/applications/$DESKTOP.desktop" ] && return
  26. done
  27. # Didn't find it in the search path.
  28. return 1
  29. }
  30. # Checks a file to see if it's a 32 or 64-bit.
  31. check_executable() {
  32. out=$(file $(readlink -f $1) 2> /dev/null)
  33. echo $out | grep -qs "ELF 32-bit LSB"
  34. if [ $? = 0 ]; then
  35. echo 32
  36. return
  37. fi
  38. echo $out | grep -qs "ELF 64-bit LSB"
  39. if [ $? = 0 ]; then
  40. echo 64
  41. return
  42. fi
  43. echo neither
  44. }
  45. # Generate a desktop file that will run this script.
  46. generate_desktop_file() {
  47. apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
  48. mkdir -p "$apps"
  49. cat > "$apps/$DESKTOP.desktop" << EOF
  50. [Desktop Entry]
  51. Version=1.0
  52. Encoding=UTF-8
  53. Name=$TITLE
  54. Exec=$CHROME_WRAPPER %U
  55. Terminal=false
  56. Icon=$HERE/product_logo_48.png
  57. Type=Application
  58. Categories=Application;Network;WebBrowser;
  59. MimeType=text/html;text/xml;application/xhtml_xml;
  60. EOF
  61. }
  62. # Let the wrapped binary know that it has been run through the wrapper.
  63. export CHROME_WRAPPER="`readlink -f "$0"`"
  64. export CHROME_DESKTOP="$DESKTOP.desktop"
  65. HERE="`dirname "$CHROME_WRAPPER"`"
  66. # We include some xdg utilities next to the binary, and we want to prefer them
  67. # over the system versions when we know the system versions are very old. We
  68. # detect whether the system xdg utilities are sufficiently new to be likely to
  69. # work for us by looking for xdg-settings. If we find it, we leave $PATH alone,
  70. # so that the system xdg utilities (including any distro patches) will be used.
  71. if ! which xdg-settings &> /dev/null; then
  72. # Old xdg utilities. Prepend $HERE to $PATH to use ours instead.
  73. export PATH="$HERE:$PATH"
  74. else
  75. # Use system xdg utilities. But first create mimeapps.list if it doesn't
  76. # exist; some systems have bugs in xdg-mime that make it fail without it.
  77. xdg_app_dir="${XDG_DATA_HOME:-$HOME/.local/share/applications}"
  78. mkdir -p "$xdg_app_dir"
  79. [ -f "$xdg_app_dir/mimeapps.list" ] || touch "$xdg_app_dir/mimeapps.list"
  80. fi
  81. # Always use our ffmpeg and other shared libs.
  82. export LD_LIBRARY_PATH="$HERE:$HERE/lib:$HERE/lib.target${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
  83. MISSING_LIBS=$(ldd "$HERE/chrome" 2> /dev/null |grep "not found$" | cut -d" " -f 1|sed 's/\t//')
  84. CHROME_ARCH=$(check_executable "$HERE/chrome")
  85. uname -m | grep -qs x86_64
  86. if [ $? = 1 ]; then
  87. LIBDIRS="/lib /lib32 /usr/lib /usr/lib32"
  88. else
  89. LIBDIRS="/lib64 /lib /usr/lib64 /usr/lib"
  90. fi
  91. echo $MISSING_LIBS | grep -qs libbz2.so.1.0
  92. if [ $? = 0 ]; then
  93. for dir in $LIBDIRS
  94. do
  95. if [ -e "$dir/libbz2.so.1" ]; then
  96. LIB_ARCH=$(check_executable "$dir/libbz2.so.1")
  97. if [ "$CHROME_ARCH" = "$LIB_ARCH" ]; then
  98. ln -snf "$dir/libbz2.so.1" "$HERE/libbz2.so.1.0"
  99. break;
  100. fi
  101. fi
  102. done
  103. fi
  104. for lib in libnspr4.so.0d libnss3.so.1d libnssutil3.so.1d libplc4.so.0d libplds4.so.0d libsmime3.so.1d libssl3.so.1d
  105. do
  106. echo $MISSING_LIBS | grep -qs $lib
  107. if [ $? = 0 ]; then
  108. reallib=$(echo $lib | sed 's/\.[01]d$//')
  109. for dir in $LIBDIRS
  110. do
  111. if [ -e "$dir/$reallib" ]; then
  112. LIB_ARCH=$(check_executable "$dir/$reallib")
  113. if [ "$CHROME_ARCH" = "$LIB_ARCH" ]; then
  114. ln -snf "$dir/$reallib" "$HERE/$lib"
  115. break;
  116. fi
  117. fi
  118. done
  119. fi
  120. done
  121. # Custom version string for this release. This can be used to add a downstream
  122. # vendor string or release channel information.
  123. export CHROME_VERSION_EXTRA="custom"
  124. exists_desktop_file || generate_desktop_file
  125. CMD_PREFIX=
  126. ARGS=()
  127. while [ "$#" -gt 0 ]; do
  128. case "$1" in
  129. "--")
  130. shift
  131. break ;;
  132. "--gdb")
  133. CMD_PREFIX="gdb --args" ;;
  134. "--help")
  135. usage
  136. exit 0 ;;
  137. "--man-page")
  138. exec man "$HERE/../../chrome/app/resources/manpage.1.in" ;;
  139. *)
  140. ARGS=( "${ARGS[@]}" "$1" ) ;;
  141. esac
  142. shift
  143. done
  144. set -- "${ARGS[@]}" "$@"
  145. exec $CMD_PREFIX "$HERE/chrome" "$@"