Skip to content

Instantly share code, notes, and snippets.

@adamrights
Created April 5, 2014 01:49
Show Gist options
  • Save adamrights/9986445 to your computer and use it in GitHub Desktop.
Save adamrights/9986445 to your computer and use it in GitHub Desktop.
#!/bin/bash
#source env variables including node version
. /opt/elasticbeanstalk/env.vars
function error_exit
{
eventHelper.py --msg "$1" --severity ERROR
exit $2
}
#UNCOMMENT to update npm, otherwise will be updated on instance init or rebuild
#rm -f /opt/elasticbeanstalk/node-install/npm_updated
#download and extract desired node.js version
OUT=$( [ ! -d "/opt/elasticbeanstalk/node-install" ] &&
mkdir /opt/elasticbeanstalk/node-install ;
cd /opt/elasticbeanstalk/node-install/ &&
wget -nc http://nodejs.org/dist/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz &&
tar --skip-old-files -xzpf node-v$NODE_VER-linux-$ARCH.tar.gz) ||
error_exit "Failed to UPDATE node version. $OUT" $?.
echo $OUT
#if there's no global node link elasticbeanstalk node to global
if [ ! -L /usr/bin/node ]; then
ln -s /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/node /usr/bin/node
fi
# Do that same for npm
if [ ! -L /usr/bin/npm ]; then
ln -s /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm /usr/bin/npm
fi
# Default is to not update.
if [ ! -f "/opt/elasticbeanstalk/node-install/npm_updated" ]; then
/opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/ && /opt/elasticbeanstalk/node-install/node-v$NODE_VER-linux-$ARCH/bin/npm update npm -g
touch /opt/elasticbeanstalk/node-install/npm_updated
echo "Updated global NPM version to `npm -v`"
else
echo "UNCOMMENT ABOVE TO UPDATE NPM; you're done you bro, you h@xored EB."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment