Skip to content

Instantly share code, notes, and snippets.

@fnando
Created June 29, 2012 03:42
Show Gist options
  • Save fnando/3015541 to your computer and use it in GitHub Desktop.
Save fnando/3015541 to your computer and use it in GitHub Desktop.
Install Node.js
#!/usr/bin/env bash
INSTALL_DIR="${INSTALL_DIR:-/opt/local}"
VERSION=$2
APP_NAME="node"
URL="http://nodejs.org/dist/v$VERSION/node-v$VERSION.tar.gz"
PREFIX="$INSTALL_DIR/$APP_NAME/$VERSION"
CURRENT="$INSTALL_DIR/$APP_NAME/current"
TGZ="$INSTALL_DIR/src/$(basename $URL)"
COMMAND=$1
if [[ -z "$COMMAND" ]]; then
${0} help
exit 1
elif [[ -z "$VERSION" && "$COMMAND" != "help" && "$COMMAND" != "deactivate" ]]; then
${0} help
fi
case "$COMMAND" in
bootstrap)
mkdir /var/log/node
chown www-data. /var/log/node
;;
install)
if [[ "$(uname)" != "Darwin" ]]; then
sudo apt-get install -y libssl-dev
fi
mkdir -p $INSTALL_DIR/src
cd $INSTALL_DIR/src
[ ! -f "$TGZ" ] && wget $URL
tar xvf $TGZ
cd node-v$VERSION
./configure --prefix=$PREFIX
make
make install
;;
activate)
if [[ ! -d $PREFIX ]]; then
${0} install $VERSION
fi
${0} deactivate
ln -s "$PREFIX" "$CURRENT"
for dir in bin sbin
do
[ ! -d "$CURRENT/$dir" ] && continue
mkdir -p "$INSTALL_DIR/$dir"
for file in `ls $CURRENT/$dir`
do
bin=$(basename $file)
ln -s "$CURRENT/$dir/$bin" "$INSTALL_DIR/$dir/$bin"
done
done
;;
deactivate)
if [[ ! -L "$CURRENT" ]]; then
exit
fi
for dir in bin sbin
do
[ ! -d "$CURRENT/$dir" ] && continue
for file in `ls $CURRENT/$dir`
do
bin=$(basename $file)
[ -L "$INSTALL_DIR/$dir/$bin" ] && rm "$INSTALL_DIR/$dir/$bin"
done
done
rm "$CURRENT"
;;
*)
echo "Usage: ${0} {bootstrap|install|uninstall|activate|deactivate|help} {version}" >&2
exit 3
;;
esac
:
@PotHix
Copy link

PotHix commented Jun 29, 2012

Gerenciador de pacotes está no canto chorando. LOL

@fnando
Copy link
Author

fnando commented Jun 30, 2012

@PotHix script para levantar o Vagrant. Pacote para dev? Coisa de quem trabalha na Locaweb. :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment