File opera-gx.sh.in of Package opera-gx
#!/bin/bash
# Authors:
# Shubin Alex aka Sylar <renard.corp@hotmail.com>
# Fabien Tassin <fta@sofaraway.org>
# Licence: GPLv2+
PROGNAME="opera-gx"
LIBDIR="__LIBDIR__/$PROGNAME"
# Try to find the actual executable name (it might be opera, opera_gx, or opera-gx)
if [ -f "$LIBDIR/opera_gx" ]; then
EXEC_NAME="opera_gx"
elif [ -f "$LIBDIR/opera-gx" ]; then
EXEC_NAME="opera-gx"
elif [ -f "$LIBDIR/opera" ]; then
EXEC_NAME="opera"
else
EXEC_NAME="opera_gx"
fi
# Try to find sandbox file
if [ -f "$LIBDIR/opera_gx_sandbox" ]; then
SANDBOX_FILE="$LIBDIR/opera_gx_sandbox"
elif [ -f "$LIBDIR/opera_sandbox" ]; then
SANDBOX_FILE="$LIBDIR/opera_sandbox"
elif [ -f "$LIBDIR/opera-gx_sandbox" ]; then
SANDBOX_FILE="$LIBDIR/opera-gx_sandbox"
else
SANDBOX_FILE="$LIBDIR/${EXEC_NAME}_sandbox"
fi
# Allow users to override command-line options.
# Based on Gentoo's chromium package (and by extension, Debian's).
if [ -r "__SYSCONFDIR__/default/$PROGNAME" ]; then
. "__SYSCONFDIR__/default/$PROGNAME"
fi
# Prefer user defined OPERA_GX_USER_FLAGS (from env) over system
# default OPERA_GX_FLAGS (from /etc/default/opera-gx).
OPERA_GX_FLAGS="${OPERA_GX_USER_FLAGS:-$OPERA_GX_FLAGS}"
# Check if CLONE_NEWUSER exists (setuid sandboxing is required).
if [ ! -f "/proc/$$/ns/user" ]; then
REQUIRE_SETUID_SANDBOX=1
else
REQUIRE_SETUID_SANDBOX=
fi
# Check if sandbox binary has a setuid flag.
if [ -f "$SANDBOX_FILE" ] && [[ "$(stat -c '%a %u:%g' "$SANDBOX_FILE")" == '4755 0:0' ]]; then
HAS_SETUID_SANDBOX=1
else
HAS_SETUID_SANDBOX=
fi
# SUID sandboxing is required but does not exist. Let's try and fix it.
if [ -n "$REQUIRE_SETUID_SANDBOX" ] && [ -z "$HAS_SETUID_SANDBOX" ]; then
if [[ "$OPERA_GX_FLAGS" =~ '--sandbox' ]]; then
if ( ! which xdg-su &> /dev/null ) || \
( ! xdg-su -c "chmod 4755 \"$SANDBOX_FILE\"; chown 0:0 \"$SANDBOX_FILE\"" &> /dev/null ); then
echo "Permission granting failed, falling back to disabled sandboxing." >&2
OPERA_GX_FLAGS="$OPERA_GX_FLAGS --no-sandbox"
fi
else
OPERA_GX_FLAGS="$OPERA_GX_FLAGS --no-sandbox"
fi
fi
exec "$LIBDIR/$EXEC_NAME" $SANDBOX $CHROMIUM_FLAGS $OPERA_GX_FLAGS "$@"