Created
April 12, 2012 17:44
-
-
Save chorrell/2369564 to your computer and use it in GitHub Desktop.
add new version of nodejs to a SmartMachine
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
#!/usr/bin/env bash | |
# | |
# Add new version of nodejs to a SmartMachine | |
# | |
# Check to see if script is being run as the root user | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root. Aborting..." 1>&2 | |
exit 1 | |
fi | |
VERSION=$1 | |
if [ -z "$VERSION" ]; then | |
echo "Usage: $0 <version> (e.g. 0.6.0)" | |
exit 127 | |
fi | |
# Is the gcc compiler installed? If not, install | |
pkgin list | grep -q gcc-compiler | |
if [ $? -eq 1 ]; then | |
pkgin -f update # make sure the local repo is up to date | |
pkgin -y install gcc-compiler | |
fi | |
cd /var/tmp/ | |
# Check if the version of node is installed, if so exit | |
if [ -e /opt/nodejs/v${VERSION}/ ]; then | |
echo "/opt/nodejs/v${VERSION}/ exists. ${VERSION} Already installed?" | |
exit 1 | |
fi | |
# Download, make and compile node | |
curl -O http://nodejs.org/dist/v${VERSION}/node-v${VERSION}.tar.gz | |
gtar -xpf node-v${VERSION}.tar.gz | |
cd node-v${VERSION}/ | |
./configure --with-dtrace --prefix=/opt/nodejs/v${VERSION}/ | |
gmake install | |
# Clean up | |
cd /var/tmp/ | |
rm -rf /var/tmp/node-v${VERSION}* | |
# Setup the symlink | |
if [ -e /opt/local/bin/node ]; then | |
if [ -L /opt/local/bin/node ]; then | |
rm /opt/local/bin/node | |
fi | |
fi | |
ln -s /opt/nodejs/v${VERSION}/bin/node /opt/local/bin/node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment