]> git.pld-linux.org Git - packages/chromium-browser.git/blob - chromium-browser.sh
- pl
[packages/chromium-browser.git] / chromium-browser.sh
1 #!/bin/sh
2 APPNAME=chromium-browser
3 LIBDIR=@libdir@
4 GDB=/usr/bin/gdb
5
6 # Allow the user to override command-line flags, http://bugs.gentoo.org/357629
7 # This is based on Debian's chromium-browser package, and is intended
8 # to be consistent with Debian.
9 if [ -f /etc/$APPNAME/default ]; then
10         . /etc/$APPNAME/default
11 fi
12
13 die() {
14         echo >&2 "$*"
15         exit 1
16 }
17
18 usage() {
19         cat <<EOF
20 $APPNAME [-h|--help] [-g|--debug] [--temp-profile] [options] [URL]
21
22                 -g or --debug           Start within $GDB
23                 -h or --help            This help screen
24                 --temp-profile          Start with a new and temporary profile
25
26 Other supported options are:
27
28 @OPTIONS@
29 See 'man $APPNAME' for more details
30 EOF
31 }
32
33 export LD_LIBRARY_PATH=$LIBDIR${LD_LIBRARY_PATH:+:"$LD_LIBRARY_PATH"}
34
35 # for to find xdg-settings
36 export PATH=$LIBDIR${PATH:+:"$PATH"}
37
38 # chromium needs /dev/shm being mounted
39 m=$(awk '$2 == "/dev/shm" && $3 == "tmpfs" {print}' /proc/mounts)
40 if [ -z "$m" ]; then
41         cat >&2 <<-'EOF'
42         Chromium needs /dev/shm being mounted for Shared Memory access.
43
44         To do so, invoke (as root):
45         mount -t tmpfs -o rw,nosuid,nodev,noexec none /dev/shm
46
47         EOF
48 fi
49
50 # lsb_release is slow so try to source the static file /etc/lsb-release
51 # instead, and fallback to lsb_release if we didn't get the information we need
52 if [ -e /etc/lsb-release ]; then
53         . /etc/lsb-release
54 fi
55 DIST=${DISTRIB_ID:-$(lsb_release -si)}
56 RELEASE=${DISTRIB_CODENAME:-$(lsb_release -sc)}
57
58 # Set CHROME_VERSION_EXTRA visible in the About dialog and in about:version
59 export CHROME_VERSION_EXTRA="$DIST Linux $RELEASE"
60
61 # Let the wrapped binary know that it has been run through the wrapper
62 export CHROME_WRAPPER="$(readlink -f "$0")"
63
64 # Google Chrome has a number of command line switches which change the behavior of Chrome
65 # This param allows you to set extra args for browser startup.
66 # See: http://peter.sh/experiments/chromium-command-line-switches/
67 CHROME_FLAGS_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/chromium/Chrome Flags"
68 if [ -f "$CHROME_FLAGS_FILE" ]; then
69         # All lines starting with # are ignored
70         CHROMIUM_USER_FLAGS=$(grep -v '^#' "$CHROME_FLAGS_FILE")
71 fi
72
73 # Prefer user defined CHROMIUM_USER_FLAGS (from env) over system
74 # default CHROMIUM_FLAGS (from /etc/chromium-browser/default).
75 CHROMIUM_FLAGS=${CHROMIUM_USER_FLAGS:-"$CHROMIUM_FLAGS"}
76
77 # Google guys cannot properly handle comma, so download speed/est is shown
78 # as not a number (NaN). Workaround that with LC_NUMERIC=C
79 export LC_NUMERIC=C
80
81 # load PepperFlash if present
82 PEPFLASH=$(readlink -f $LIBDIR/../browser-plugins/PepperFlash)
83 if [ -f $PEPFLASH/manifest.ver ]; then
84         . $PEPFLASH/manifest.ver
85         CHROMIUM_FLAGS="$CHROMIUM_FLAGS --ppapi-flash-path=$PEPFLASH/libpepflashplayer.so --ppapi-flash-version=$version"
86 fi
87
88 want_debug=0
89 want_temp_profile=0
90 while [ $# -gt 0 ]; do
91         case "$1" in
92         -h | --help | -help)
93                 usage
94                 exit 0 ;;
95         -g | --debug)
96                 want_debug=1
97                 shift ;;
98         --temp-profile)
99                 want_temp_profile=1
100                 shift ;;
101         -- ) # Stop option prcessing
102                 shift
103                 break ;;
104         *)
105                 break ;;
106         esac
107 done
108
109 if [ $want_temp_profile -eq 1 ]; then
110         TEMP_PROFILE=$(mktemp -d) || exit 1
111         CHROMIUM_FLAGS="$CHROMIUM_FLAGS --user-data-dir=$TEMP_PROFILE"
112 fi
113
114 if [ $want_debug -eq 1 ]; then
115         if [ ! -x $GDB ]; then
116                 die "Sorry, can't find usable $GDB. Please install it."
117         fi
118
119         tmpfile=$(mktemp /tmp/chromiumargs.XXXXXX) || die "Cannot create temporary file"
120         trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
121         echo "set args $CHROMIUM_FLAGS ${1+"$@"}" > $tmpfile
122         echo "# Env:"
123         echo "#     LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
124         echo "#                PATH=$PATH"
125         echo "#            GTK_PATH=$GTK_PATH"
126         echo "# CHROMIUM_USER_FLAGS=$CHROMIUM_USER_FLAGS"
127         echo "#      CHROMIUM_FLAGS=$CHROMIUM_FLAGS"
128         echo "$GDB $LIBDIR/$APPNAME -x $tmpfile"
129         $GDB "$LIBDIR/$APPNAME" -x $tmpfile
130         rc=$?
131         if [ $want_temp_profile -eq 1 ]; then
132                 rm -rf $TEMP_PROFILE
133         fi
134         exit $rc
135 else
136         if [ $want_temp_profile -eq 0 ]; then
137                 exec $LIBDIR/$APPNAME $CHROMIUM_FLAGS "$@"
138         else
139                 # we can't exec here as we need to clean-up the temporary profile
140                 $LIBDIR/$APPNAME $CHROMIUM_FLAGS "$@"
141                 rm -rf $TEMP_PROFILE
142         fi
143 fi
This page took 0.046466 seconds and 3 git commands to generate.