Skip to content

Instantly share code, notes, and snippets.

@jsatt
Last active December 21, 2015 07:38
Show Gist options
  • Save jsatt/6272226 to your computer and use it in GitHub Desktop.
Save jsatt/6272226 to your computer and use it in GitHub Desktop.
A script for managing and installing nodejs within a Python virtualenv.
#!/bin/bash
TASK=$1
node_checksum() {
if [ "$1" = "$2" ]; then
return
elif [ -z $2 ]; then
echo 'Checksums empty' #missing in raspberry pi binary
return
else
echo 'Checksums do not match.'
return 1
fi
}
main(){
case $TASK in
"install" )
VERSION=$2
if [ "$3" ]; then
DIR=$3
elif [ "$VIRTUAL_ENV" ]; then
DIR=$VIRTUAL_ENV
else
echo "You must be in an active virtualenv or provide a path."
return 1;
fi
url="http://nodejs.org/dist/$VERSION/node-${VERSION}.tar.gz"
tmpdir="/tmp/node-${VERSION}"
tmptarball="$tmpdir/node-${VERSION}.tar.gz"
sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
mkdir -p "$tmpdir"
if [ "$sum" = "" ]; then
echo "Checksum not available, verify version number."
return 1
else
curl --progress-bar $url -o "$tmptarball"
node_checksum `shasum "$tmptarball" | awk '{print $1}'` $sum
fi
tar -xzf "$tmptarball" -C "$tmpdir"
cd "$tmpdir/node-$VERSION"
./configure --prefix=$DIR
make
make install
;;
* )
echo "Usage: venv_node <command>"
echo ""
echo "Commands:"
echo " install <version> [<path>] Installs the specified <version> (i.e. "
echo " \"v0.8.11\") of node to the specified <path>."
echo " If no <path> is provided, it attempts to install"
echo " to the active python virtualenv."
esac
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment