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