Skip to content

Instantly share code, notes, and snippets.

@lnxslck
Forked from ruario/README.md
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lnxslck/9a5a9b4b8ba2e030e1ef to your computer and use it in GitHub Desktop.
Save lnxslck/9a5a9b4b8ba2e030e1ef to your computer and use it in GitHub Desktop.

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

Whilst Opera currently only provide .deb packages, it is possible to install Opera on different distros. This install script automates the process.

If you don't already have the script, fetch it like so:

git clone https://gist.github.com/ace4fb780216aa28d922.git

To install the latest stable release, issue:

sudo sh install-opera.sh --stable

To install the latest beta release, issue:

sudo sh install-opera.sh --beta

To install the latest developer release:

sudo sh install-opera.sh --developer

Alternatively you can install a specific build like so:

sudo sh install-opera.sh opera-stable_26.0.1656.32_amd64.deb

After install, you may need to re-login to your desktop environment before Opera is detected.

Note: A script to uninstall Opera is also placed on your system, to aid removing Opera later, should you wish to.

If you would like to ensure that Opera developer is automatically kept up to date, move the script to /usr/local/bin and make it executable:

sudo mv install-opera.sh /usr/local/bin/install-opera
sudo chmod +x /usr/local/bin/install-opera

You could then add the following to root's crontab:

00 18 * * 1-5 /usr/local/bin/install-opera --stable >/dev/null 2>&1

This would execute the script once a day at 18:00 (6pm), every Monday through Friday.

If you would like to schedule the script to run at different times, or would like to log the output and/or errors, read one of the many crontab guides found on the internet.

Note: You should not run this script more once per day, since we never release so frequently. Hammering Opera servers with requests could get your IP address banned and you would then receive no updates. In any case, If you ever notice that a new Opera is out and the script has not yet run, simply issue install-opera --stable manually to trigger an update right away.

#!/bin/sh
available () {
command -v "$1" >/dev/null 2>&1
}
updatedbs () {
# Setup menu entries
if available update-desktop-database; then
update-desktop-database -q /usr/local/share/applications
fi
# Setup icons
touch -c /usr/local/share/icons/hicolor
if available gtk-update-icon-cache; then
gtk-update-icon-cache -tq /usr/local/share/icons/hicolor
fi
}
# Uninstall function to be used by the removal script
removefiles () {
while read f; do
# '-e' alone would not find broken symlinks
if [ -e "$f" -o -h "$f" ]; then
if [ -d "$f" ]; then
if ! ls -A "$f" | grep -q ^; then
# Don't remove a symlink pointing to a directory, as it could have
# been created by the user or the distribution
if [ ! -h "$f" ]; then
rmdir -v "$f"
fi
fi
else
rm -v "$f"
fi
fi
done
} #
# Ar (Binutils) or BSD tar are needed to extract from a Debian package
if available bsdtar; then
AR_EXTRACT="bsdtar xOf"
elif available ar; then
AR_EXTRACT="ar p"
else
echo "You must install BSD Tar or GNU Binutils to use this script" >&2
exit 1
fi
# Quit if you can't write to /usr/local
if [ ! -w "/usr/local" ]; then
echo "You do not have write permission to /usr/local" >&2
echo "Re-run this script as root or prefaced with sudo, e.g." >&2
echo " \$ sudo $0 $@" >&2
exit 1
fi
# Check if automatic download has been selected
while [ 0 ]; do
if [ "$1" = "-d" -o "$1" = "--developer" ]; then
OPERA_STREAM=opera-developer
shift 1
elif [ "$1" = "-b" -o "$1" = "--beta" ]; then
OPERA_STREAM=opera-beta
shift 1
elif [ "$1" = "-s" -o "$1" = "--stable" ]; then
OPERA_STREAM=opera-stable
shift 1
else
break
fi
done
DESTROY_DEB=N
OPERA_AUTO_FETCH=N
if [ -n "$OPERA_STREAM" ]; then
OPERA_AUTO_FETCH=Y
DESTROY_DEB=Y
# Set architecture information
ARCH=$(uname -m | sed 's/i.86/i386/')
case "$ARCH" in
x86_64) DEBARCH=amd64; LIBDIRSUFFIX="64" ;;
i386) DEBARCH=$ARCH; LIBDIRSUFFIX="" ;;
*) echo "The architecture $ARCH is not supported." >&2 ; exit 1 ;;
esac
# Make sure we have wget or curl
if available wget; then
SILENT_DL="wget -qO-"
LOUD_DL="wget"
DL_OUTPUT="-O"
elif available curl; then
SILENT_DL="curl -s"
LOUD_DL="curl -O"
DL_OUTPUT="-o"
else
echo "Install wget or curl" >&2
exit 1
fi
# Work out the latest stable Google Chrome if VERSION is unset
OPERA_VERSION=$($SILENT_DL http://deb.opera.com/opera/dists/stable/non-free/binary-$DEBARCH/Packages.gz | gzip -d | grep -A1 -x "Package: $OPERA_STREAM" | sed -n "/Version/s/.* //p")
# Error out if $OPERA_VERISON is unset, e.g. because previous command failed
if [ -z "$OPERA_VERSION" ]; then
echo "Could not work out the latest version of $OPERA_STREAM for $ARCH; exiting" >&2
exit 1
fi
if [ -e "/usr/local/lib$LIBDIRSUFFIX/$(echo $OPERA_STREAM | sed 's/\-stable//')/VERSION_$OPERA_VERSION" ]; then
echo "The latest version of $OPERA_STREAM ($OPERA_VERSION) is already installed; exiting"
exit 0
fi
OPERA_DEB=$(mktemp -t opera-deb.XXXXXX)
$LOUD_DL http://deb.opera.com/opera/pool/non-free/o/$OPERA_STREAM/${OPERA_STREAM}_${OPERA_VERSION}_${DEBARCH}.deb $DL_OUTPUT $OPERA_DEB
if ! [ "$?" = 0 ]; then
echo "Download failed!" >&2
exit 1
fi
fi
# Check if this is being run as a self extractor
if [ -z "$1" -a -z "$OPERA_DEB" ]; then
if [ $(sed '1,/^exit$/d' "$0" | head -n 1 | wc -l) = "1" ]; then
OPERA_DEB=$(mktemp -t opera-deb.XXXXXX)
sed '1,/^exit$/d' "$0" > "$OPERA_DEB"
DESTROY_DEB=Y
else
echo "You must provide the name of an Opera package, e.g." >&2
echo " # $(basename $0) opera.deb" >&2
exit 1
fi
fi
# Run some checks to see if a proper package was provided
if [ -z "$OPERA_DEB" ]; then
if ! echo "$1" | grep -q 'opera.*\.deb$'; then
echo "$1 is not named like an Opera Debian package" >&2
exit 1
fi
if [ -r "$1" ]; then
OPERA_DEB="$1"
else
echo "$1 is either not present or cannot be read" >&2
exit 1
fi
fi
# Extract information from control file
if [ -z "$OPERA_STREAM" ]; then
OPERA_STREAM_VERSION_DEBARCH=$($AR_EXTRACT "$OPERA_DEB" control.tar.gz | tar -xzOf- ./control | sed -n 's/^Package: //p;s/^Version: //p;s/^Architecture: //p')
if [ -z "$OPERA_STREAM_VERSION_DEBARCH" ]; then
echo "Could extract the package name and architecture from the control file" >&2
exit 1
else
OPERA_STREAM=$(echo $OPERA_STREAM_VERSION_DEBARCH | cut -d' ' -f1)
OPERA_VERSION=$(echo $OPERA_STREAM_VERSION_DEBARCH | cut -d' ' -f2)
DEBARCH=$(echo $OPERA_STREAM_VERSION_DEBARCH | cut -d' ' -f3)
fi
# Set the architecture
case "$DEBARCH" in
amd64) ARCH=x86_64; LIBDIRSUFFIX="64" ;;
*) ARCH=$DEBARCH; LIBDIRSUFFIX="" ;;
esac
fi
# If Opera is already installed, assume this is an upgrade and remove it first
UNINSTALL_OPERA_SCRIPT=/usr/local/bin/remove-$OPERA_STREAM
if [ -x "$UNINSTALL_OPERA_SCRIPT" ]; then
echo "Removing previously installed Opera first"
sleep 1
. "$UNINSTALL_OPERA_SCRIPT"
fi
# Stop the script as soon as there is a problem
set -eu
# Extract files from the Debian package to a temporary location
OPERA_FILES=$(mktemp -d -t opera-files.XXXXXX)
printf "\nUncompressing Opera ...\n"
mkdir -p "$OPERA_FILES"
$AR_EXTRACT "$OPERA_DEB" data.tar.xz | xz -d | tar -xf- -C "$OPERA_FILES" \
--transform="s,^\./usr,./usr/local,;s,/lib/${ARCH}-linux-gnu,/lib$LIBDIRSUFFIX," \
--exclude="./usr/share/lintian" --exclude="./usr/share/menu"
# Create the first part of the uninstall script
mkdir -p "$(dirname $OPERA_FILES/$UNINSTALL_OPERA_SCRIPT)"
sed -n '1,/^} #$/p' "$0" > "$OPERA_FILES/$UNINSTALL_OPERA_SCRIPT"
# Remove the last part of stable stream name
OPERA_STREAM=$(echo $OPERA_STREAM | sed 's/\-stable//')
# Setup udev symlink if needed
cd "$OPERA_FILES"
if ! [ -e "/lib$LIBDIRSUFFIX/libudev.so.0" -o -e "/usr/lib$LIBDIRSUFFIX/libudev.so.0" -o -e "/lib/${ARCH}-linux-gnu/libudev.so.0" -o -e "/usr/lib/${ARCH}-linux-gnu/libudev.so.0" -o -e "/lib/libudev.so.0" -o -e "/usr/lib/libudev.so.0" ]; then
mkdir -p usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib
if [ -e "/lib$LIBDIRSUFFIX/libudev.so.1" ]; then
ln -s /lib$LIBDIRSUFFIX/libudev.so.1 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib/libudev.so.0
elif [ -e "/usr/lib$LIBDIRSUFFIX/libudev.so.1" ]; then
ln -s /usr/lib$LIBDIRSUFFIX/libudev.so.1 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib/libudev.so.0
elif [ -e "/lib/${ARCH}-linux-gnu/libudev.so.1" ]; then
ln -s /lib/${ARCH}-linux-gnu/libudev.so.1 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib/libudev.so.0
elif [ -e "/usr/lib/${ARCH}-linux-gnu/libudev.so.1" ]; then
ln -s /usr/lib/${ARCH}-linux-gnu/libudev.so.1 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib/libudev.so.0
elif [ -e "/lib/libudev.so.1" ]; then
ln -s /lib/libudev.so.1 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib/libudev.so.0
elif [ -e "/usr/lib/libudev.so.1" ]; then
ln -s /usr/lib/libudev.so.1 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib/libudev.so.0
else
echo "Neither libudev.so.0 nor libudev.so.1 was found." >&2
exit 1
fi
fi
# Setup libcrypto symlink on Fedora and derivatives
cd "$OPERA_FILES"
if [ -e "/usr/lib$LIBDIRSUFFIX/libcrypto.so.10" ]; then
mkdir -p usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib
ln -s /usr/lib$LIBDIRSUFFIX/libcrypto.so.10 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/lib/libcrypto.so.1.0.0
fi
# Correct the Opera sandbox permissions
chmod 4755 usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/opera_sandbox
# Record the version number in the package
touch usr/local/lib$LIBDIRSUFFIX/$OPERA_STREAM/VERSION_$OPERA_VERSION
# Finish uninstall script
printf 'set -e\nremovefiles << FILE_LIST\n' >> ".$UNINSTALL_OPERA_SCRIPT"
find . ! -type d ! -print | sed 's,\.,,' | grep -vF "$UNINSTALL_OPERA_SCRIPT" >> ".$UNINSTALL_OPERA_SCRIPT"
find . -depth -type d -print | sed 's,\.,,' | \
grep -vxE '(^$|/usr(/local(/bin|/lib(64)?|/share(/doc|/man(/man1)?)?)?)?)' >> ".$UNINSTALL_OPERA_SCRIPT"
printf "FILE_LIST\nupdatedbs\nrm -v \"$UNINSTALL_OPERA_SCRIPT\"\n" >> ".$UNINSTALL_OPERA_SCRIPT"
chmod 755 ".$UNINSTALL_OPERA_SCRIPT"
# Install the files only, *not* directories.
# This avoids changing system directory permissions/ownership
printf "Installing Opera ...\n\n"
find . ! -type d | tar -cf- -T- | tar -xf- -C /
# Note: Originally I used a cpio instead of a tar pipe but some
# systems might not have cpio installed by default.
# find . ! -type d | cpio --quiet -pmd /
# Remove temporary files
cd - >/dev/null
rm -r "$OPERA_FILES"
if [ "$DESTROY_DEB" = "Y" ]; then
rm "$OPERA_DEB"
fi
# Update the desktop and icons databases
updatedbs
# And ... we're done! ;)
echo 'Opera was successfully installed into "/usr/local/"'.
printf "\nTo uninstall, issue the following as root (or prefaced with sudo):\n\n"
printf " $UNINSTALL_OPERA_SCRIPT\n\n"
exit
@ruario
Copy link

ruario commented Mar 31, 2015

Your fork is out of date. ;)

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