Created
November 30, 2011 18:52
-
-
Save danbeam/1410275 to your computer and use it in GitHub Desktop.
Keep up to date with the latest version of node.js
This file contains hidden or 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 | |
sudo apt-get -qq install build-essential g++ apache2-utils libssl-dev curl | |
latest_dir="http://nodejs.org/dist/latest/"; | |
latest_version=$(curl -s "$latest_dir" | grep "tar\.gz" | sed -re 's/.*?href="node-(v[0-9\.]+)\.tar\.gz".*/\1/'); | |
cleanup() { | |
rm -rf "$temp"; | |
} | |
earlydeath() { | |
cleanup; | |
exit 1; | |
} | |
error() { | |
echo >&2 "ERROR: There was a problem $1."; | |
earlydeath; | |
} | |
local_version() { | |
echo $(node --version); | |
} | |
if [ ! -z "`which node`" ]; then | |
version=$(local_version); | |
newest=$(echo -e "$latest_version\n$version" | sort -V | tail -1); | |
if [ "$version" == "$newest" ]; then | |
echo "Already up to date."; | |
exit 0; | |
fi | |
fi | |
trapped() { | |
echo >&2 "Caught signal, cleaning up..."; | |
earlydeath; | |
} | |
trap trapped INT TRAP HUP; | |
temp=$(mktemp -d '/tmp/nodejs-XXX'); | |
curl -s "$latest_dir/node-$latest_version.tar.gz" | tar xz -C "$temp" || error "downloading or decompressing"; | |
cd "$temp"/node-* || "with the decompressed file"; | |
./configure --prefix=/usr || error "configuring"; | |
JOBS=`grep processor /proc/cpuinfo | wc -l` make || error "compiling"; | |
sudo make install || error "installing"; | |
cleanup; | |
echo "node.js version now at `local_version`"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run easily with something like this