node-installer.sh/setup-node-mavericks.bash

55 lines
1.4 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
set -u
set -o pipefail
if [ -z "${PREFIX-}" ]; then
PREFIX=""
fi
if [ -z "$NODE_PATH" ]; then
node_install_path=$(dirname $(dirname $NODE_PATH))
else
node_install_path=$PREFIX/usr/local
fi
NODEJS_VER=${1}
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
NODEJS_NAME="node"
NODEJS_BASE_URL="https://nodejs.org"
2015-12-23 02:50:41 +00:00
if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ]
then
2015-12-23 02:50:41 +00:00
echo "Selecting io.js instead of node.js for this version (>= 1.0.0 < 4.0.0)"
NODEJS_BASE_URL="https://iojs.org"
NODEJS_NAME="iojs"
fi
# When using .pkg
#NODEJS_REMOTE="$NODEJS_BASE_URL/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}.pkg"
#NODEJS_PKG="/tmp/${NODEJS_NAME}-${NODEJS_VER}.pkg"
NODEJS_REMOTE="$NODEJS_BASE_URL/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}.tar.gz"
NODEJS_PKG="/tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
NODEJS_UNTAR="/tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64"
if [ -n "${NODEJS_VER}" ]; then
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
curl -fsSL "${NODEJS_REMOTE}" -o "${NODEJS_PKG}"
# When using .pkg
#sudo /usr/sbin/installer -pkg "${NODEJS_PKG}" -target /
# When using .tar.gz
sudo tar xf "${NODEJS_PKG}" -C "{NODEJS_UNTAR}/"
rm -f ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
sudo rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
sudo chown -R $(whoami) "$node_install_path/lib/node_modules/"
sudo chown $(whoami) "$node_install_path/bin/"
2015-01-15 22:41:04 +00:00
fi