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