2016-09-21 08:44:01 +02:00
|
|
|
#!/usr/bin/env bash
|
2018-08-03 10:50:41 +02:00
|
|
|
set -eo pipefail
|
2016-09-21 08:44:01 +02:00
|
|
|
|
2021-06-09 01:02:05 +02:00
|
|
|
node_version=14.17.0
|
2021-04-08 04:12:36 +02:00
|
|
|
nvm_version=0.38.0
|
2017-06-12 18:05:02 +02:00
|
|
|
|
2018-04-12 23:25:30 +02:00
|
|
|
# This is a fix for the fact that nvm uses $HOME to determine which
|
|
|
|
# user account's home directory to ~/.config to. Ideally, we'd have a
|
|
|
|
# more systematic fix, like using `sudo -H` everywhere.
|
|
|
|
export HOME=/root
|
|
|
|
|
2017-07-11 21:36:33 +02:00
|
|
|
current_node_version="none"
|
2018-08-03 02:14:47 +02:00
|
|
|
if node_wrapper_path="$(command -v node)"; then
|
2017-07-11 21:36:33 +02:00
|
|
|
current_node_version="$(node --version)"
|
|
|
|
fi
|
|
|
|
|
2021-06-26 02:26:27 +02:00
|
|
|
if [ "$current_node_version" = "v$node_version" ] && [ -L "$node_wrapper_path" ]; then
|
|
|
|
echo "Node version $node_version is already installed."
|
2017-06-12 18:05:02 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-07-29 01:50:53 +02:00
|
|
|
if [ "$current_node_version" != "v$node_version" ] || ! [ -L "$node_wrapper_path" ]; then
|
2017-07-27 23:17:52 +02:00
|
|
|
export NVM_DIR=/usr/local/nvm
|
2020-03-27 02:22:14 +01:00
|
|
|
# shellcheck source=/dev/null
|
2020-10-15 04:55:57 +02:00
|
|
|
if ! [ -e "$NVM_DIR/nvm.sh" ] || {
|
|
|
|
. "$NVM_DIR/nvm.sh"
|
|
|
|
[ "$(nvm --version)" != "$nvm_version" ]
|
|
|
|
}; then
|
2020-03-27 02:22:14 +01:00
|
|
|
mkdir -p "$NVM_DIR"
|
2021-06-25 01:28:27 +02:00
|
|
|
curl_opts=(-L)
|
2018-08-02 16:29:47 +02:00
|
|
|
if [ -n "${CUSTOM_CA_CERTIFICATES:-}" ]; then
|
2021-06-25 01:28:27 +02:00
|
|
|
curl_opts+=(--cacert "${CUSTOM_CA_CERTIFICATES}")
|
2018-08-02 16:29:47 +02:00
|
|
|
fi
|
2021-06-25 01:28:27 +02:00
|
|
|
curl "${curl_opts[@]}" "https://raw.githubusercontent.com/nvm-sh/nvm/v$nvm_version/install.sh" | bash
|
2020-03-27 02:22:14 +01:00
|
|
|
# shellcheck source=/dev/null
|
|
|
|
. "$NVM_DIR/nvm.sh"
|
2017-07-27 23:17:52 +02:00
|
|
|
fi
|
2016-09-21 08:44:01 +02:00
|
|
|
|
2021-05-11 22:52:56 +02:00
|
|
|
# Tell NVM that we don't want it messing around with $PATH; we'll
|
|
|
|
# adjust which npm to use by symlinks below.
|
|
|
|
nvm alias default system
|
|
|
|
|
2021-05-01 03:04:43 +02:00
|
|
|
nvm install "$node_version"
|
|
|
|
NODE_BIN="$(nvm which $node_version)"
|
2016-09-21 08:44:01 +02:00
|
|
|
|
2017-07-27 23:17:52 +02:00
|
|
|
# Fix messed-up uid=500 and group write bits produced by nvm
|
2018-08-03 02:14:47 +02:00
|
|
|
n=${NODE_BIN%/bin/node}
|
2017-07-27 23:17:52 +02:00
|
|
|
chown -R root:root "$n"
|
|
|
|
chmod -R go-w "$n"
|
2016-09-21 08:44:01 +02:00
|
|
|
|
2018-07-29 01:50:53 +02:00
|
|
|
# Install node symlink to /usr/local/bin
|
|
|
|
ln -nsf "$NODE_BIN" /usr/local/bin/node
|
2020-10-28 04:48:54 +01:00
|
|
|
ln -nsf "$(dirname "$NODE_BIN")/npm" /usr/local/bin/npm
|
|
|
|
ln -nsf "$(dirname "$NODE_BIN")/npx" /usr/local/bin/npx
|
2017-07-27 23:17:52 +02:00
|
|
|
fi
|