Last active
December 21, 2015 07:38
-
-
Save jsatt/6272226 to your computer and use it in GitHub Desktop.
A script for managing and installing nodejs within a Python virtualenv.
This file contains 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 | |
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