Create a gist now

Instantly share code, notes, and snippets.

@ruario /README.md
Last active Aug 29, 2015

Unpacks an Opera Debian package into a similarly named directory and creates a startup script that will cause Opera to save its profile within this directory (Useful for USB installs). Completely unofficial and unsupported.

Disclaimer: I wrote this script for my own personal usage. It is not officially supported by Opera Software.

This script converts an Opera Debian package into standalone (portable) format. If you do not already have it, fetch it as follows:

git clone https://gist.github.com/8416e36372f1a976a713.git

Now use the script to convert an Opera package as follows:

sh standalone-opera.sh opera-developer_27.0.1670.0_amd64.deb

When the script is done you will have a suitably directory called. You can run the copy of Opera stored within it as follows:

opera-developer_27.0.1670.0_amd64/run &

Copy or move the directory wherever you like.

#!/bin/sh
if command -v bsdtar >/dev/null 2>&1; then
_extract='bsdtar xOf'
elif command -v ar >/dev/null 2>&1; then
_extract='ar p'
else
echo 'You must install BSD tar or GNU binutils to use this script' >&2
exit 1
fi
if [ -z "$1" ]; then
echo 'You must specify the path to a locally stored Opera .deb package.' >&2
echo "Example usage: `basename $0` opera.deb" >&2
exit 1
fi
if ! echo "$1" | grep -q 'opera.*[_-]\([0-9]\+\.\)\{3,\}.*\.deb$'; then
echo "$1 is not named like a recent Opera .deb package" >&2
exit 1
fi
if [ ! -r "$1" ]; then
echo "$1 is either not present or cannot be read" >&2
exit 1
fi
outputdir="`basename $1 .deb`"
mkdir -p "$outputdir" || exit 1
${_extract} "$1" data.tar.xz | tar xJ -C "$outputdir"
cd "$outputdir"
# The SANDBOX section can be removed if you run Opera 29+ and have a Linux kernel of 3.17 or newer (Ubuntu 14.10's 3.16 kernel will also work).
## SANDBOX BEGIN
_sandbox="`find usr/lib* -name opera_sandbox -executable -type f -print`"
if [ -n "$OPERA_DEVEL_SANDBOX" ]; then
rm "${_sandbox}"
elif [ -r /etc/os-release ] && grep -qx 'ID=\(ubuntu\|linuxmint\)' /etc/os-release; then
echo "Calling sudo ... If prompted, please enter your password to give opera_sandbox sufficient permissions to function as it should."
sudo chown root:root ${_sandbox} && sudo chmod 4755 ${_sandbox}
else
echo "Please enter your root password to give opera_sandbox sufficient permissions to function as it should."
su -c "sh -c \"chown root:root ${_sandbox} && chmod 4755 ${_sandbox} \""
fi
## SANDBOX END
printf '#!/bin/sh\nexec "${0%%/*}/'`find usr/lib* -regextype posix-egrep -regex ".*opera(-(developer|beta|stable))?" -executable -type f -print`'" --user-data-dir="${0%%/*}/profile" "$@"\n' > run
chmod 755 run
printf "\nThe directory $outputdir has been created, issue the following to start Opera:\n"
printf "\n\t$outputdir/run &\n\n"
@Lex-2008
Lex-2008 commented Apr 8, 2014

nice script for a Nice browser!

@ruario
Owner
ruario commented Jan 6, 2015

If you want you can avoid escalating to root for every extraction. You will need to have variable OPERA_DEVEL_SANDBOX predefined and pointing to a valid root-owned, setuid sandbox application. You can actually take an Opera sandbox from any recent Opera package. You should be able to continue to use it for multiple releases before needing to update it. To extract and configure the one from Opera 28.0.1719.0 developer for example, issue:

ar p opera-developer_28.0.1719.0_amd64.deb data.tar.xz | tar -xJf- -C /var/tmp --strip 5 --wildcards '*/opera_sandbox'
sudo chown root:root /var/tmp/opera_sandbox 
sudo chmod 4755 /var/tmp/opera_sandbox

Then define the variable (export OPERA_DEVEL_SANDBOX=/var/tmp/opera_sandbox) in your ~/.bashrc or somewhere else you feel is appropriate.

@ruario
Owner
ruario commented Mar 31, 2015

You could actually remove the whole sandbox section if you want to run Opera 29+ on system with a Linux kernel of 3.17 or newer, as the sandbox does not need root privileges on newer kernels to work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment