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.
55 lines
1.5 KiB
Plaintext
55 lines
1.5 KiB
Plaintext
5 years ago
|
#!/usr/bin/env bash
|
||
|
|
||
4 years ago
|
NODE_VERSION=${NODE_VERSION:-v14.15.3}
|
||
|
PREFIX_DIR=${PREFIX_DIR:-/usr/local}
|
||
5 years ago
|
|
||
|
BIN_DIR=${PREFIX_DIR}/bin
|
||
4 years ago
|
NODE_PREFIX_DIR=${PREFIX_DIR}/apps/node
|
||
5 years ago
|
NODE_DEST_DIR=${NODE_PREFIX_DIR}/${NODE_VERSION}
|
||
|
NODE_DEST_BIN_DIR=${NODE_DEST_DIR}/bin
|
||
|
NODE_CURRENT=${NODE_PREFIX_DIR}/current
|
||
|
|
||
|
OS=
|
||
|
ARCH=
|
||
4 years ago
|
case $(uname -s) in
|
||
|
Linux*) OS=linux;;
|
||
|
Darwin*) OS=darwin;;
|
||
|
*) >&2 echo "unsupported os"; return;
|
||
|
esac
|
||
|
|
||
|
case $(uname -m) in
|
||
|
x86_64*) ARCH=x64;;
|
||
|
*) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;;
|
||
|
esac
|
||
5 years ago
|
|
||
4 years ago
|
[[ -d "${NODE_DEST_DIR}" ]] || sudo mkdir -p "${NODE_DEST_DIR}"
|
||
5 years ago
|
|
||
4 years ago
|
URL=https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-${OS}-${ARCH}.tar.xz
|
||
|
|
||
5 years ago
|
TMP_DIR=
|
||
|
if [[ ! -d ${NODE_DEST_BIN_DIR} ]]; then
|
||
|
TMP_DIR=$(mktemp --directory)
|
||
|
DEST_FILE=$TMP_DIR/node.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
|
||
|
|
||
4 years ago
|
cd "${NODE_PREFIX_DIR}" || exit 1
|
||
5 years ago
|
[[ -s current ]] && sudo unlink current
|
||
4 years ago
|
sudo ln --symbolic "${NODE_VERSION}" current
|
||
|
echo current version set to "${NODE_VERSION}"
|
||
4 years ago
|
cd "${BIN_DIR}" || exit 1
|
||
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
|