File: //snap/chromium/3248/bin/chromium.launcher
#!/bin/sh
# Move an existing profile directory over to $SNAP_USER_COMMON, which is shared
# across revisions of the snap. This addresses profile corruption when the snap
# is refreshed while running, until a proper solution is implemented in snapd.
# Ref: https://launchpad.net/bugs/1616650
if [ ! -d "$SNAP_USER_COMMON/chromium" ]; then
if [ -d "$SNAP_USER_DATA/.config/chromium" ]; then
mv "$SNAP_USER_DATA/.config/chromium" "$SNAP_USER_COMMON/"
fi
fi
# When running the snap for the first time, try and locate an existing chromium
# config in $HOME/.config/chromium, and import it if it was created by an older
# version of chromium (the profile data format is not guaranteed to be
# forward-compatible). This requires the personal-files plug to be connected.
# Also, open a new tab in the existing session to inform users that their
# browser is now packaged as a snap (and the underlying reasons, benefits and
# limitations). Ref: https://launchpad.net/bugs/1888380
FIRSTRUN_PAGE=""
if [ ! -d "$SNAP_USER_COMMON/chromium" ]; then
CHROMIUM_CONFIG="$SNAP_REAL_HOME/.config/chromium"
if [ -d "$CHROMIUM_CONFIG" ]; then
PREF_FILE="$CHROMIUM_CONFIG/Default/Preferences"
if [ -r "$PREF_FILE" ]; then
VERSION=$(sed -e 's/.*"last_chrome_version":"\([0-9\.]\+\)".*/\1/' "$PREF_FILE")
if [ ! -z "$VERSION" ]; then
OLD=$(printf "$VERSION\n$SNAP_VERSION" | sort -V | head -1)
if [ "$OLD" = "$VERSION" ]; then
SIZE=$(du -sb $CHROMIUM_CONFIG | cut -f 1)
AVAILABLE_BLOCKS=$(stat -f -c %a $SNAP_USER_COMMON)
BLOCK_SIZE=$(stat -f -c %s $SNAP_USER_COMMON)
AVAILABLE_SIZE=$(($AVAILABLE_BLOCKS*$BLOCK_SIZE))
if [ $AVAILABLE_SIZE -gt $SIZE ]; then
printf "Importing existing chromium profile from $CHROMIUM_CONFIG (version $VERSION)\n"
TS1=$(date +%s.%3N)
cp -R "$CHROMIUM_CONFIG" "$SNAP_USER_COMMON/"
TS2=$(date +%s.%3N)
T=$(printf "$TS1 $TS2" | awk '{printf "%.3f",$2-$1}')
printf "Import done in $T s\n"
else
printf "Not importing existing chromium profile from $CHROMIUM_CONFIG (version $VERSION) "
printf "because there is not enough available space in $SNAP_USER_COMMON "
printf "(required: $SIZE bytes / available: $AVAILABLE_SIZE bytes)\n"
fi
fi
fi
LANG_CODE=$(locale | grep LANG= | cut -d= -f2 | cut -d. -f1 | cut -d_ -f1)
FIRSTRUN_PAGE="$SNAP/firstrun/snap-$LANG_CODE.html"
if [ ! -f "$FIRSTRUN_PAGE" ]; then
# No localized version, fall back to English
FIRSTRUN_PAGE="$SNAP/firstrun/snap-en.html"
fi
fi
fi
fi
# Warn the user if policies are found in more than one place.
# Ref: https://launchpad.net/bugs/1714244
# Ref: https://launchpad.net/bugs/1866732
SNAP_POLICIES="$SNAP_DATA/policies"
if [ -d "$SNAP_POLICIES" ]; then
OLD_POLICIES="/etc/chromium-browser/policies"
if [ -d "$OLD_POLICIES" ]; then
printf "Warning: existing chromium policies in $OLD_POLICIES will be shadowed by new policies found in $SNAP_POLICIES\n"
fi
fi
# Specify that no encrypted password store (keyring) should be used when the
# password-manager-service interface is not plugged, because Chromium won't
# fall back to the basic store (no encryption) if it fails to talk to the
# default password store for the current desktop environment.
# Ref: https://launchpad.net/bugs/1763829
if snapctl is-connected password-manager-service; then
PASSWORD_STORE= # an empty string means detect the store based on the current DE (os_crypt::SelectBackend())
else
PASSWORD_STORE=basic
fi
# Custom version string for chrome://version
export CHROME_VERSION_EXTRA=snap
# Configuration for the "man" binary, which is invoked when chromium is called
# with the "-h" (or "--help") argument (see https://launchpad.net/bugs/1848083)
export MAN_TEST_DISABLE_SYSTEM_CONFIG=1
export MANPATH=$SNAP
export GROFF_FONT_PATH=$SNAP/usr/share/groff/current/font
export GROFF_TMAC_PATH=$SNAP/usr/share/groff/current/tmac
# This convinces Chromium that it is running from /snap/bin instead of the
# unconfined path, /snap/*/*/usr/lib/chromium-browser/chrome.
# As a result, it creates desktop files with an appropriate Exec= line.
export CHROME_WRAPPER=/snap/bin/$SNAP_INSTANCE_NAME
# Source ~/.chromium-browser.init for compatibility with the chromium-browser
# deb package (https://launchpad.net/bugs/1837746)
if [ -r $SNAP_REAL_HOME/.chromium-browser.init ]; then
. $SNAP_REAL_HOME/.chromium-browser.init
fi
WANT_TEMP_PROFILE=0
WANT_HEADLESS=0
for arg in "$@"; do
shift
if [ "$arg" = "--temp-profile" ]; then
WANT_TEMP_PROFILE=1
continue
elif [ "$arg" = "--headless" ]; then
WANT_HEADLESS=1
fi
set -- "$@" "$arg"
done
if [ $WANT_HEADLESS -eq 0 ] ; then
if [ ! -z "$FIRSTRUN_PAGE" ]; then
set -- "$@" "$FIRSTRUN_PAGE"
fi
fi
case "$CHROMIUM_FLAGS" in
*\ *)
1>&2 printf '%s\n' \
"Warning: Do not pass arguments with spaces via CHROMIUM_FLAGS." \
"See https://launchpad.net/bugs/1514484 for context."
;;
esac
# Allows translation of pages in foreign languages.
# Refer to https://bugs.archlinux.org/task/76268.
CHROMIUM_FLAGS="$CHROMIUM_FLAGS --disable-features=TFLiteLanguageDetectionEnabled"
# Use GTK3. LP:2106312, LP:2106342.
CHROMIUM_FLAGS="--gtk-version=3 $CHROMIUM_FLAGS"
# Check if the user wants to actually run chromium as a daemon
daemon="$(snapctl get daemon)"
if [ "$daemon" = "true" ]; then
# If chromium is running as a daemon, assume we're running as a kiosk.
CHROMIUM_FLAGS="$CHROMIUM_FLAGS --kiosk --no-sandbox --disable-dev-shm-usage"
# If we're running as a kiosk, we are using Frame, so use Wayland.
CHROMIUM_FLAGS="$CHROMIUM_FLAGS --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime"
# If we're running as a kiosk, we are loading a specific URL.
set -- "$@" "$(snapctl get url)"
fi
if [ $WANT_TEMP_PROFILE -eq 0 ] ; then
exec "$SNAP/usr/lib/chromium-browser/chrome" --password-store=$PASSWORD_STORE $CHROMIUM_FLAGS "$@"
else
TEMP_PROFILE=$(mktemp -d)
trap "rm -rf $TEMP_PROFILE" EXIT
# we can't exec here as we need to clean-up the temporary profile
"$SNAP/usr/lib/chromium-browser/chrome" --user-data-dir=$TEMP_PROFILE --password-store=$PASSWORD_STORE $CHROMIUM_FLAGS "$@"
fi