Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active August 29, 2015 14:18
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 ruario/57d31713b96dfc92b725 to your computer and use it in GitHub Desktop.
Save ruario/57d31713b96dfc92b725 to your computer and use it in GitHub Desktop.
Unpacks a Google Chrome rpm package into a version named directory and creates a startup script that will cause it to save its profile within this directory (Useful for testing).

This script converts a Google Chrome rpm package into standalone (portable) format. Usage example:

sh standalone-google-chrome.sh google-chrome-stable_current_x86_64.rpm

When the script is done you will have a suitably version named directory. You can run the copy of Google Chrome stored within it as follows:

google-chrome-stable-41.0.2272.118-1/run &

Copy or move the directory wherever you like.

#!/bin/sh
if [ -z "$1" ]; then
echo 'You must specify the path to a locally stored Google Chrome .rpm package.' >&2
echo "Example usage: `basename $0` google-chrome-stable_current_x86_64.rpm" >&2
exit 1
fi
if ! echo "$1" | grep -q 'google-chrome-.*\.rpm$'; then
echo "$1 is not named like a Google Chrome .rpm package" >&2
exit 1
fi
if [ ! -r "$1" ]; then
echo "$1 is either not present or cannot be read" >&2
exit 1
fi
outputdir="`head -c96 $1 | strings`"
mkdir -p "$outputdir" || exit 1
tail -c+`expr \`LANG=C grep -abom1 '.7zXZ' "$1" | cut -d: -f1\` + 1` "$1" | xz -d | (cd "$outputdir"; cpio --quiet -id)
cd "$outputdir"
# The SANDBOX section can be removed if you run Google Chrome 42+ and have a Linux kernel of 3.17 or newer (Ubuntu 14.10's 3.16 kernel will also work).
## SANDBOX BEGIN
_sandbox="`find opt -name chrome-sandbox -executable -type f -print`"
if [ -n "$CHROME_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 chrome-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 chrome-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 opt -name chrome -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 Google Chrome:\n"
printf "\n\t$outputdir/run &\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment