You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
Plaintext
62 lines
1.5 KiB
Plaintext
5 years ago
|
#!/usr/bin/env bash
|
||
|
|
||
|
set -e
|
||
|
|
||
5 years ago
|
NODE_VERSION=${NODE_VERSION:-v12.16.2}
|
||
5 years ago
|
|
||
|
PREFIX_DIR=/usr/local
|
||
|
BIN_DIR=${PREFIX_DIR}/bin
|
||
|
|
||
|
NODE_PREFIX_DIR=${PREFIX_DIR}/node
|
||
|
NODE_DEST_DIR=${NODE_PREFIX_DIR}/${NODE_VERSION}
|
||
|
NODE_DEST_BIN_DIR=${NODE_DEST_DIR}/bin
|
||
|
NODE_CURRENT=${NODE_PREFIX_DIR}/current
|
||
|
|
||
|
OS=
|
||
|
if [[ $OSTYPE =~ linux ]]; then
|
||
|
OS=linux
|
||
|
elif [[ $OSTYPE =~ darwin ]]; then
|
||
|
OS=darwin
|
||
|
else
|
||
4 years ago
|
echo unknown os: "$OSTYPE"
|
||
5 years ago
|
exit 1
|
||
|
fi
|
||
|
|
||
|
ARCH=
|
||
|
if [[ $(uname -m) == x86_64 ]]; then
|
||
|
ARCH=x64
|
||
|
else
|
||
4 years ago
|
echo arch not yet supported: "$(uname -m)"
|
||
5 years ago
|
exit 1
|
||
|
fi
|
||
|
|
||
4 years ago
|
[[ -d "${NODE_DEST_DIR}" ]] || sudo mkdir -p "${NODE_DEST_DIR}"
|
||
5 years ago
|
|
||
|
TMP_DIR=
|
||
|
if [[ ! -d ${NODE_DEST_BIN_DIR} ]]; then
|
||
|
TMP_DIR=$(mktemp --directory)
|
||
|
DEST_FILE=$TMP_DIR/node.tar.xz
|
||
|
URL=https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-${OS}-${ARCH}.tar.xz
|
||
4 years ago
|
echo downloading node "$NODE_VERSION" to temp directory "${TMP_DIR}"
|
||
|
curl --silent --output "${DEST_FILE}" "${URL}"
|
||
5 years ago
|
|
||
4 years ago
|
sudo tar xf "${DEST_FILE}" --directory "${NODE_DEST_DIR}" --strip-components 1
|
||
|
sudo chown --recursive root:root "${NODE_DEST_DIR}"
|
||
5 years ago
|
else
|
||
4 years ago
|
echo node "$NODE_VERSION" already installed
|
||
5 years ago
|
fi
|
||
|
|
||
|
cd ${NODE_PREFIX_DIR}
|
||
5 years ago
|
[[ -s current ]] && sudo unlink current
|
||
4 years ago
|
sudo ln --symbolic "${NODE_VERSION}" current
|
||
|
echo current version set to "${NODE_VERSION}"
|
||
5 years ago
|
cd ${BIN_DIR}
|
||
4 years ago
|
for bin in "${NODE_CURRENT}/bin/"*; do
|
||
|
[[ -s $bin ]] || sudo ln --symbolic "${NODE_CURRENT}/bin/$bin"
|
||
5 years ago
|
done
|
||
|
|
||
|
if [[ $TMP_DIR != "" ]]; then
|
||
4 years ago
|
rm -rf "${TMP_DIR}"
|
||
|
echo removed up temp directory "${TMP_DIR}"
|
||
5 years ago
|
fi
|