Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ruario/9673716 to your computer and use it in GitHub Desktop.
Save ruario/9673716 to your computer and use it in GitHub Desktop.
Permits install and update of all Chrome channels side by side
#!/bin/bash
# Multichrome Version 0.7.1
# This script will find the latest Unstable, Beta or Stable Google
# Chrome package, download it and repackage it into a generic tar
# format. It allows for multiple versions to be installed side by side.
# I don't use Chrome for regular browsing but it is handy for
# comparative tests against Opera. :P
# Copyright 2013 Ruari Oedegaard, Oslo, Norway
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
make_desktop_shortcuts ()
{
for CHROMECHANNEL in stable beta unstable; do
case $CHROMECHANNEL in
stable) CHANNELNAME=google-chrome-stable ;;
beta) CHANNELNAME=google-chrome-beta ;;
unstable) CHANNELNAME=google-chrome-unstable ;;
esac
if [ -e "/opt/google/$CHANNELNAME/google-chrome" ]; then
for png in /opt/google/$CHANNELNAME/product_logo_*.png; do
pngsize="${png##*/product_logo_}"
mkdir -p "$HOME/.local/share/icons/hicolor/${pngsize%.png}x${pngsize%.png}/apps"
(
cd "$HOME/.local/share/icons/hicolor/${pngsize%.png}x${pngsize%.png}/apps/"
ln -fs /opt/google/$CHANNELNAME/product_logo_${pngsize} google-chrome-${CHROMECHANNEL}.png
)
echo "$HOME/.local/share/icons/hicolor/${pngsize%.png}x${pngsize%.png}/apps/google-chrome-${CHROMECHANNEL}.png"
done
mkdir -p "$HOME/.local/share/applications"
sed \
-e "s,^\(Exec=\)/usr/bin\(/google-chrome\).*,\1/opt/google/$CHANNELNAME\2," \
-e "s,^Icon=google-chrome,\0-$CHROMECHANNEL," \
/opt/google/$CHANNELNAME/google-chrome.desktop > "$HOME/.local/share/applications/google-chrome-${CHROMECHANNEL}.desktop"
echo "$HOME/.local/share/applications/google-chrome-${CHROMECHANNEL}.desktop"
else
find "$HOME/.local/share/icons/hicolor/" -name google-chrome-${CHROMECHANNEL}.png -type l -exec rm -v {} \;
if [ -e "$HOME/.local/share/applications/google-chrome-${CHROMECHANNEL}.desktop" ]; then
rm -v "$HOME/.local/share/applications/google-chrome-${CHROMECHANNEL}.desktop"
fi
fi
done
if command -v update-desktop-database >/dev/null 2>&1; then
update-desktop-database -q "$HOME/.local/share/applications"
fi
touch -c "$HOME/.local/share/icons/hicolor"
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
gtk-update-icon-cache -tq "$HOME/.local/share/icons/hicolor"
fi
if [[ -n $(find "$HOME/.local/share/applications" -regex ".*google-chrome-\(stable\|beta\|unstable\).desktop$" -print) ]]; then
echo "Note: You may need to restart your Desktop Environment for your new shortcuts to appear!"
fi
}
if [ -n "$1" ]; then
case $1 in
-s) make_desktop_shortcuts ; exit ;;
*) echo "$1 is not a valid option" >&2 ; exit 1 ;;
esac
fi
case ${ARCH:-$(uname -m)} in
i?86) ARCH=i386 ;;
x86_64) ARCH=x86_64 ;;
*) echo "The architecture $ARCH is not supported." >&2 ; exit 1 ;;
esac
if command -v curl >/dev/null 2>&1; then
DOWNLOAD="curl -O"
DOWNLOADSILENT="curl -s"
elif command -v wget >/dev/null 2>&1; then
DOWNLOAD=wget
DOWNLOADSILENT="wget -qO-"
else
echo "Neither cURL nor Wget is installed. Install one of these before you proceed." >&2
exit 1
fi
if [ -z $CHROMECHANNEL ]; then
echo "Do you want to check for the latest Unstable (Dev) [u], Beta [b] or Stable [s] build?"
read -p "Press Enter to accept the default, Unstable [U/b/s]: " CHROMECHANNEL
[ "${CHROMECHANNEL}" ] || CHROMECHANNEL=u
fi
case $CHROMECHANNEL in
[Ss]*) CHROMECHANNEL=stable ; CHANNELNAME=google-chrome-stable ;;
[Bb]*) CHROMECHANNEL=beta ; CHANNELNAME=google-chrome-beta ;;
[DdUu]*) CHROMECHANNEL=unstable ; CHANNELNAME=google-chrome-unstable ;;
*) echo "$CHROMECHANNEL is not a valid channel option." >&2 ; exit 1 ;;
esac
VERSION=${VERSION:-$($DOWNLOADSILENT https://dl.google.com/linux/direct/google-chrome-${CHROMECHANNEL}_current_${ARCH}.rpm | head -c96 | strings | sed -nr "s/^google-chrome-${CHROMECHANNEL}-([0-9\.]+-[0-9]+)$/\1/p")}
if [ -z $VERSION ]; then
echo "Could not work out the latest version; exiting" >&2
exit 1
fi
TMP=${TMP:-/tmp}
OUTPUT=${OUTPUT:-/tmp}
REPACKDIR=$TMP/repackage-google-chrome
FULLNAME=google-chrome-${CHROMECHANNEL}-${VERSION}.${ARCH}
RPM="$TMP/${FULLNAME}.rpm"
REPACK="$OUTPUT/${FULLNAME}.tar"
PKGURL=https://dl.google.com/linux/chrome/rpm/stable/${ARCH}/${FULLNAME}.rpm
if [ -d "/opt/google/$FULLNAME" ] ; then
echo "Google Chrome ($CHROMECHANNEL) is already installed as /opt/google/$FULLNAME/google-chrome; exiting"
exit 0
fi
if [ -e "$REPACK" ]; then
echo "$REPACK already exists; exiting"
exit 0
fi
set -eu
if [ -d "$REPACKDIR" ]; then
rm -fr "$REPACKDIR"
fi
mkdir -p "$REPACKDIR"
if [ -e "$RPM" ]; then
echo "$RPM will not be downloaded as it is already present"
elif [ -e "${FULLNAME}.rpm" ]; then
echo "./${FULLNAME}.rpm will not be downloaded as it is already present"
ln -s "$(pwd)/${FULLNAME}.rpm" "$RPM"
else
echo "Downloading $PKGURL to $TMP"
(cd "$TMP"; $DOWNLOAD $PKGURL)
fi
cd "$REPACKDIR"
echo "Extracting ${FULLNAME}.rpm for repacking"
if command -v bsdtar >/dev/null 2>&1; then
bsdtar xf "$RPM" ./opt
if [ ! -e /opt/google/chrome/google-chrome.desktop ]; then
bsdtar xf "$RPM" ./usr/share/applications/google-chrome.desktop
mv usr/share/applications/google-chrome.desktop opt/google/chrome
rm -fr usr
fi
elif command -v rpm2cpio >/dev/null 2>&1; then
rpm2cpio "$RPM" | cpio --quiet -id "./opt/*"
if [ ! -e /opt/google/chrome/google-chrome.desktop ]; then
rpm2cpio "$RPM" | cpio --quiet -id ./usr/share/applications/google-chrome.desktop
mv usr/share/applications/google-chrome.desktop opt/google/chrome
rm -fr usr
fi
else
RPMHDRLGTH=$(LANG=C grep -abom1 '.7zXZ\|BZh9' "$RPM")
case "$RPMHDRLGTH" in
*7zXZ) COMPRESSOR=xz ;;
*BZh9) COMPRESSOR=bzip2 ;;
*) echo "Unknown compression type in $RPM!" >&2; exit 1 ;;
esac
tail -c+$[${RPMHDRLGTH%:*}+1] "$RPM" | $COMPRESSOR -d | cpio --quiet -id "./opt/*"
if [ ! -e /opt/google/chrome/google-chrome.desktop ]; then
tail -c+$[${RPMHDRLGTH%:*}+1] "$RPM" | $COMPRESSOR -d | cpio --quiet -id ./usr/share/applications/google-chrome.desktop
mv usr/share/applications/google-chrome.desktop opt/google/chrome
rm -fr usr
fi
fi
chmod 4711 opt/google/chrome/chrome-sandbox
echo "Updating Chrome $CHROMECHANNEL install location"
mv opt/google/chrome opt/google/$FULLNAME
(cd opt/google ; ln -s $FULLNAME $CHANNELNAME)
echo "Repackaging as a tar archive"
find opt ! -type d | tar --owner 0 --group 0 -T- -cf "$REPACK"
echo "Created $REPACK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment