2015-09-11 19:35:08 +00:00
|
|
|
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:47:52 +00:00
|
|
|
if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ]
|
2015-09-11 19:35:08 +00:00
|
|
|
then
|
2015-12-23 02:47:52 +00:00
|
|
|
echo "Selecting io.js instead of node.js for this version (>= 1.0.0 < 4.0.0)"
|
2015-09-11 19:35:08 +00:00
|
|
|
NODEJS_BASE_URL="https://iojs.org"
|
|
|
|
NODEJS_NAME="iojs"
|
|
|
|
fi
|
2015-01-15 22:41:04 +00:00
|
|
|
|
|
|
|
if [ -n "$(arch | grep 64)" ]; then
|
|
|
|
ARCH="x64"
|
2015-03-20 04:01:17 +00:00
|
|
|
elif [ -n "$(arch | grep armv7l)" ]; then
|
|
|
|
ARCH="armv7l"
|
|
|
|
elif [ -n "$(arch | grep armv6l)" ]; then
|
|
|
|
ARCH="armv6l"
|
2015-01-15 22:41:04 +00:00
|
|
|
else
|
|
|
|
ARCH="x86"
|
|
|
|
fi
|
|
|
|
|
2015-09-11 19:35:08 +00:00
|
|
|
NODEJS_REMOTE="${NODEJS_BASE_URL}/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
|
|
|
|
NODEJS_LOCAL="/tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
|
|
|
|
NODEJS_UNTAR="/tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}"
|
2015-01-21 06:18:12 +00:00
|
|
|
|
2015-09-11 19:35:08 +00:00
|
|
|
if [ -n "${NODEJS_VER}" ]; then
|
|
|
|
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
|
2015-01-15 22:43:34 +00:00
|
|
|
|
2015-01-21 06:18:12 +00:00
|
|
|
if [ -n "$(which curl 2>/dev/null)" ]; then
|
2015-09-11 19:35:08 +00:00
|
|
|
curl -fsSL ${NODEJS_REMOTE} -o ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
2015-01-21 06:18:12 +00:00
|
|
|
elif [ -n "$(which wget 2>/dev/null)" ]; then
|
2015-09-11 19:35:08 +00:00
|
|
|
wget --quiet ${NODEJS_REMOTE} -O ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
2015-01-21 06:18:12 +00:00
|
|
|
else
|
|
|
|
echo "'wget' and 'curl' are missing. Please run the following command and try again"
|
|
|
|
echo "\tsudo apt-get install --yes curl wget"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-03-28 21:13:38 +00:00
|
|
|
mkdir -p ${NODEJS_UNTAR}/
|
2016-03-28 21:12:06 +00:00
|
|
|
tar xf ${NODEJS_LOCAL} -C ${NODEJS_UNTAR}/ --strip-components=1
|
2015-09-11 19:35:08 +00:00
|
|
|
rm ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
|
|
|
|
sudo rsync -a "${NODEJS_UNTAR}/" /usr/local/
|
2015-01-15 22:41:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
sudo chown -R $(whoami) /usr/local
|
|
|
|
fi
|