Last active
August 29, 2015 13:57
-
-
Save ruario/9728785 to your computer and use it in GitHub Desktop.
This scripts allows you to run Chrome on Linux, with a self contained profile and without a system wide install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# standalonechrome Version 0.2.1 | |
# This script will extract the contents of a Google Chrome rpm package | |
# into a folder, from which it be can run in a self contained fashion, | |
# i.e. the profile (settings) will also be saved in the same location. | |
# I don't use Chrome for regular browsing but it is handy for | |
# comparative tests against Opera. :P | |
# Copyright 2014 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. | |
# Run some checks to see that we are ready to proceed: | |
if [ -z "$1" ]; then | |
echo "You must specify the path to a locally stored Google Chrome rpm package." >&2 | |
echo "Example usage: $0 google-chrome-unstable_current_x86_64.rpm" >&2 | |
exit 1 | |
fi | |
if ! echo "$1" | grep -q "google-chrome.*.rpm"; then | |
echo "$1 is not name like a Google Chrome package" >&2 | |
exit 1 | |
fi | |
if [ ! -r "$1" ]; then | |
echo "$1 is either not present or cannot be read" >&2 | |
exit 1 | |
fi | |
CHROMEVERSION=$(head -c96 "$1" | strings | sed -nr "s/^google-chrome-[a-z]+-([0-9\.]+)-[0-9]+$/\1/p") | |
if [ -z "$CHROMEVERSION" ]; then | |
echo "Could not work out the Chrome version; exiting" >&2 | |
exit 1 | |
fi | |
# Extract the contents of the rpm | |
mkdir -p chrome-$CHROMEVERSION || exit 1 | |
RPMHDRINFO=$(LANG=C grep -abom1 '.7zXZ\|]'$'\000\000''....'$'\377\377\377\377\377\377''\|BZh9\|'$'\037\213\b' "$1") | |
case "$RPMHDRINFO" in | |
*7zXZ) COMPRESSOR=xz ;; | |
*]*) COMPRESSOR=lzma ;; | |
*BZh9) COMPRESSOR=bzip2 ;; | |
*) COMPRESSOR=gzip ;; | |
esac | |
echo "Extracting Chrome..." | |
tail -c+$[${RPMHDRINFO%:*}+1] "$1" | $COMPRESSOR -d | ( cd chrome-$CHROMEVERSION ; cpio --quiet -imd ./opt/* ) | |
# Configure Chrome to run with no (system wide) install and a self contained profile | |
cd chrome-$CHROMEVERSION | |
if [ -r /etc/os-release ] && grep -qx 'ID=\(ubuntu\|linuxmint\)' /etc/os-release; then | |
echo "Calling sudo ... If prompted, please enter your password to give chrome-sandbox sufficient permissions to function as it should." | |
sudo chown root:root opt/google/chrome/chrome-sandbox | |
sudo chmod 4755 opt/google/chrome/chrome-sandbox | |
else | |
echo "Please enter your root password to give chrome-sandbox sufficient permissions to function as it should." | |
su -c "sh -c \"chown root:root opt/google/chrome/chrome-sandbox && chmod 4755 opt/google/chrome/chrome-sandbox \"" | |
fi | |
if ls -l opt/google/chrome/chrome-sandbox | grep -q "rws.*root root"; then | |
sed -i '$ s,"\$@",--user-data-dir="\${0%/*}"/profile "\$@",' opt/google/chrome/google-chrome | |
ln -s opt/google/chrome/google-chrome run | |
else | |
echo "Failed to setup chrome-sandbox with correct ownership and permissions" >&2 | |
cd .. | |
rm -fr chrome-$CHROMEVERSION | |
exit 1 | |
fi | |
# Inform the user that we are done | |
printf "\nThe directory chrome-$CHROMEVERSION has been created, issue the following to start Chrome:\n" | |
printf "\n chrome-$CHROMEVERSION/run &\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment