2017-05-16 03:38:48 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-09-04 18:20:00 +00:00
|
|
|
# Not every platform has or needs sudo, gotta save them O(1)s...
|
|
|
|
sudo_cmd=""
|
2018-06-26 05:54:06 +00:00
|
|
|
((EUID)) && [[ -z "${ANDROID_ROOT:-}" ]] && sudo_cmd="sudo"
|
2017-09-04 18:20:00 +00:00
|
|
|
|
2017-05-16 03:54:35 +00:00
|
|
|
set -e
|
|
|
|
set -u
|
2017-09-04 02:46:44 +00:00
|
|
|
set -o pipefail
|
2017-05-16 03:54:35 +00:00
|
|
|
|
2018-06-23 22:29:13 +00:00
|
|
|
if [ -z "${my_tmp-}" ]; then
|
|
|
|
my_tmp=$(mkdir -p)
|
|
|
|
fi
|
2017-05-16 03:54:35 +00:00
|
|
|
if [ -z "${PREFIX-}" ]; then
|
|
|
|
PREFIX=""
|
|
|
|
fi
|
|
|
|
|
2017-09-04 02:46:44 +00:00
|
|
|
if [ -z "${NODE_PATH-}" ]; then
|
|
|
|
node_install_path=$PREFIX/usr/local
|
2017-09-02 02:09:55 +00:00
|
|
|
else
|
2017-09-04 02:46:44 +00:00
|
|
|
node_install_path=$(dirname $(dirname $NODE_PATH))
|
2017-05-16 03:38:48 +00:00
|
|
|
fi
|
|
|
|
|
2017-09-04 02:46:44 +00:00
|
|
|
NODEJS_VER=${1}
|
|
|
|
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
|
2015-09-11 19:35:08 +00:00
|
|
|
|
2017-09-04 02:46:44 +00:00
|
|
|
NODEJS_NAME="node"
|
|
|
|
NODEJS_BASE_URL="https://nodejs.org"
|
2015-09-11 19:35:08 +00:00
|
|
|
|
2017-09-04 02:46:44 +00:00
|
|
|
if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ]
|
2015-09-11 19:35:08 +00:00
|
|
|
then
|
2017-09-04 02:46:44 +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"
|
2015-01-15 22:41:04 +00:00
|
|
|
fi
|
|
|
|
|
2017-09-04 02:47:40 +00:00
|
|
|
if [ -n "$(uname -a | grep aarch64)" ]; then
|
2017-09-04 02:46:44 +00:00
|
|
|
ARCH="arm64"
|
2017-09-04 02:47:40 +00:00
|
|
|
elif [ -n "$(uname -a | grep 64)" ]; then
|
2017-09-04 02:46:44 +00:00
|
|
|
ARCH="x64"
|
2017-09-04 02:47:40 +00:00
|
|
|
elif [ -n "$(uname -a | grep armv8l)" ]; then
|
2017-09-04 02:46:44 +00:00
|
|
|
ARCH="arm64"
|
2017-09-04 02:47:40 +00:00
|
|
|
elif [ -n "$(uname -a | grep armv7l)" ]; then
|
2017-09-04 02:46:44 +00:00
|
|
|
ARCH="armv7l"
|
2017-09-04 02:47:40 +00:00
|
|
|
elif [ -n "$(uname -a | grep armv6l)" ]; then
|
2017-09-04 02:46:44 +00:00
|
|
|
ARCH="armv6l"
|
|
|
|
else
|
|
|
|
ARCH="x86"
|
2017-09-02 02:09:55 +00:00
|
|
|
fi
|
|
|
|
|
2017-09-04 02:46:44 +00:00
|
|
|
NODEJS_REMOTE="${NODEJS_BASE_URL}/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
|
2018-06-23 22:29:13 +00:00
|
|
|
NODEJS_LOCAL="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
|
|
|
|
NODEJS_UNTAR="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}"
|
2017-09-02 02:09:55 +00:00
|
|
|
|
2017-09-04 02:46:44 +00:00
|
|
|
if [ -n "${NODEJS_VER}" ]; then
|
|
|
|
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
|
2015-01-15 22:43:34 +00:00
|
|
|
|
2018-07-26 20:48:00 +00:00
|
|
|
if [ -n "$(command -v curl 2>/dev/null | grep curl)" ]; then
|
2017-09-04 02:46:44 +00:00
|
|
|
curl -fsSL ${NODEJS_REMOTE} -o ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
2018-07-26 20:48:00 +00:00
|
|
|
elif [ -n "$(command -v wget 2>/dev/null | grep wget)" ]; then
|
2017-09-04 02:46:44 +00:00
|
|
|
wget --quiet ${NODEJS_REMOTE} -O ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
2015-01-21 06:18:12 +00:00
|
|
|
else
|
2017-09-04 02:46:44 +00:00
|
|
|
echo "'wget' and 'curl' are missing. Please run the following command and try again"
|
2018-06-23 22:29:13 +00:00
|
|
|
echo " sudo apt-get install --yes curl wget"
|
2015-01-21 06:18:12 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-09-04 02:46:44 +00:00
|
|
|
mkdir -p ${NODEJS_UNTAR}/
|
2017-09-04 03:13:47 +00:00
|
|
|
# --strip-components isn't portable, switch to portable version by performing move step after untar
|
|
|
|
tar xf ${NODEJS_LOCAL} -C ${NODEJS_UNTAR}/ #--strip-components=1
|
|
|
|
mv ${NODEJS_UNTAR}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}/* ${NODEJS_UNTAR}/
|
|
|
|
rm -rf ${NODEJS_UNTAR}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH} # clean up the temporary unzip folder
|
2017-11-07 11:45:52 +00:00
|
|
|
rm ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
|
2018-07-26 20:48:00 +00:00
|
|
|
if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
|
2018-07-26 21:19:49 +00:00
|
|
|
echo $sudo_cmd rsync -r "${NODEJS_UNTAR}"/* "$node_install_path/"
|
|
|
|
rsync -r "${NODEJS_UNTAR}"/* "$node_install_path/" || $sudo_cmd rsync -r "${NODEJS_UNTAR}"/* "$node_install_path/"
|
2018-07-26 20:48:00 +00:00
|
|
|
else
|
2018-07-26 21:17:49 +00:00
|
|
|
echo $sudo_cmd cp -PR "${NODEJS_UNTAR}/*" "$node_install_path/"
|
|
|
|
cp -PR "${NODEJS_UNTAR}"/* "$node_install_path/" || $sudo_cmd cp -PR "${NODEJS_UNTAR}"/* "$node_install_path/"
|
2018-07-26 20:48:00 +00:00
|
|
|
fi
|
2017-09-04 20:35:23 +00:00
|
|
|
rm -rf "${NODEJS_UNTAR}"
|
2015-01-15 22:41:04 +00:00
|
|
|
|
2018-06-23 22:29:13 +00:00
|
|
|
chown -R $(whoami) "$node_install_path/lib/node_modules/" || $sudo_cmd chown -R $(whoami) "$node_install_path/lib/node_modules/"
|
|
|
|
chown $(whoami) ""$node_install_path"/bin/" || $sudo_cmd chown $(whoami) ""$node_install_path"/bin/"
|
2018-07-26 21:17:49 +00:00
|
|
|
fi
|