Skip to content

Instantly share code, notes, and snippets.

@rococodogs
Last active March 7, 2016 18:45
Show Gist options
  • Select an option

  • Save rococodogs/168093f228ce1348c788 to your computer and use it in GitHub Desktop.

Select an option

Save rococodogs/168093f228ce1348c788 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ -z $1 ]; then
echo "please pass me a version number!"
exit 1
fi
VERSION="$1"
DIR="node-v$VERSION-linux-x64"
URL="https://nodejs.org/dist/v$VERSION/$DIR.tar.gz"
TMP_DIR="/tmp"
TMP_FILE="node.tar.gz"
TMP_OUT="$TMP_DIR/$TMP_FILE"
# download the latest
echo "Downloading $URL"
curl -s -o $TMP_OUT $URL
# extract the files
cd $TMP_DIR
echo "moved to $PWD"
echo "extracting..."
tar -xzf $TMP_FILE &> /dev/null
if [ ! -d $DIR ]; then
echo "directory $DIR doesn't exist. maybe an extraction error?"
echo "bye :("
exit 1
fi
echo "syncing node files"
rsync -a --exclude=README.md --exclude=LICENSE --exclude=CHANGELOG.md $DIR/ /usr/local
rm -r $TMP_FILE $DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment