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

61 lines
1.8 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
set -u
set -o pipefail
2018-06-23 22:29:13 +00:00
if [ -z "${my_tmp-}" ]; then
my_tmp=$(mkdir -p)
fi
if [ -z "${PREFIX-}" ]; then
PREFIX=""
fi
2017-05-16 03:56:56 +00:00
if [ -z "${NODE_PATH-}" ]; then
node_install_path=$PREFIX/usr/local
2017-05-16 03:56:56 +00:00
else
node_install_path=$(dirname $(dirname $NODE_PATH))
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"
2017-05-16 04:20:57 +00:00
NODEJS_REMOTE="$NODEJS_BASE_URL/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
2018-06-23 22:29:13 +00:00
NODEJS_PKG="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
NODEJS_UNTAR="$my_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}"
2018-06-23 22:29:13 +00:00
# When using .pkg
#sudo /usr/sbin/installer -pkg "${NODEJS_PKG}" -target /
2018-06-23 22:29:13 +00:00
# When using .tar.gz
2017-05-16 04:10:02 +00:00
mkdir -p ${NODEJS_UNTAR}/
2017-05-16 04:23:36 +00:00
tar xf "${NODEJS_PKG}" -C "${NODEJS_UNTAR}/" --strip-components=1
rm -f ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
2018-06-23 22:29:13 +00:00
mkdir -p "$node_install_path/" || sudo mkdir -p "$node_install_path/"
rsync -a "${NODEJS_UNTAR}/" "$node_install_path/" || sudo rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
chown -R $(whoami) "$node_install_path/lib/node_modules/" || sudo chown -R $(whoami) "$node_install_path/lib/node_modules/"
chown $(whoami) "$node_install_path/bin/" || sudo chown $(whoami) "$node_install_path/bin/"
2015-01-15 22:41:04 +00:00
fi