Skip to content

Instantly share code, notes, and snippets.

@scy
Created May 21, 2014 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scy/fadb756209f9d1932527 to your computer and use it in GitHub Desktop.
Save scy/fadb756209f9d1932527 to your computer and use it in GitHub Desktop.
Simple PhantomJS installer for Linux
#!/bin/sh
set -e
if [ "$(id -u)" -ne 0 ]; then
printf 'WARNING: You will most likely need to be root, but continuing anyway ...\n' >&2
fi
url="$1"
if [ -z "$url" ]; then
printf 'Please go to <http://phantomjs.org/download.html> and find the\n'
printf 'Linux (32/64 bit) .tar.bz2 download URL, paste it and hit return:\n'
printf '\nURL: '
read -r url
fi
version="$(echo "$url" | sed -e 's#^.*/phantomjs-\([0-9.]*\)-linux-[^/]*\.tar\.bz2$#\1#')"
if [ -z "$version" ]; then
printf 'Sorry, I could not extract the version number from that URL.\n' >&2
exit 1
fi
basepath='/usr/local/bin'
lnkfile='phantomjs'
lnkpath="$basepath/$lnkfile"
outfile="$lnkfile-$version"
outpath="$basepath/$outfile"
PS4="$(basename "$0")> "
set -x
curl -L "$url" | tar xj --anchored --wildcards --strip-components=2 --to-stdout 'phantomjs-*-linux-*/bin/phantomjs' >"$outpath"
chmod 0755 "$outpath"
ln -sf "$outfile" "$lnkpath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment