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
|
|
|
|
2017-07-27 23:22:52 +02:00
|
|
|
ZULIP_PATH="$(dirname "$0")/../.."
|
|
|
|
ZULIP_SRV="/srv"
|
2018-12-07 23:28:04 +01:00
|
|
|
YARN_PACKAGE_JSON="$ZULIP_SRV/zulip-yarn/package.json"
|
2020-09-16 00:11:40 +02:00
|
|
|
node_version=12.18.4
|
|
|
|
yarn_version=1.22.5
|
2020-03-27 02:22:14 +01:00
|
|
|
nvm_version=0.35.3
|
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
|
|
|
|
|
2018-12-07 23:28:04 +01:00
|
|
|
current_yarn_version="none"
|
|
|
|
if [ -e "$YARN_PACKAGE_JSON" ]; then
|
|
|
|
current_yarn_version=$(jq -r '.version' "$YARN_PACKAGE_JSON")
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$current_yarn_version" = "$yarn_version" ] && [ "$current_node_version" = "v$node_version" ] && [ -L "$node_wrapper_path" ]; then
|
2017-07-27 23:22:52 +02:00
|
|
|
echo "Node version $node_version and yarn version $yarn_version are 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"
|
2018-08-02 16:29:47 +02:00
|
|
|
wget_opts=(-nv)
|
|
|
|
if [ -n "${CUSTOM_CA_CERTIFICATES:-}" ]; then
|
|
|
|
wget_opts+=(--ca-certificate "${CUSTOM_CA_CERTIFICATES}")
|
|
|
|
fi
|
2020-03-27 02:22:14 +01:00
|
|
|
wget "${wget_opts[@]}" -O- "https://raw.githubusercontent.com/nvm-sh/nvm/v$nvm_version/install.sh" | bash
|
|
|
|
# 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
|
|
|
|
2017-07-27 23:17:52 +02:00
|
|
|
nvm install "$node_version" && nvm alias default "$node_version"
|
2018-08-03 02:14:47 +02:00
|
|
|
NODE_BIN="$(nvm which default)"
|
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
|
2017-07-27 23:22:52 +02:00
|
|
|
|
2018-04-12 20:34:34 +02:00
|
|
|
# Work around the fact that apparently sudo doesn't clear the HOME
|
|
|
|
# environment variable in some cases; we don't want root
|
|
|
|
# accessing/storing yarn configuration in the non-root user's home
|
|
|
|
# directory.
|
|
|
|
export HOME=/root
|
|
|
|
|
2017-07-27 23:22:52 +02:00
|
|
|
# Install yarn if not installed
|
|
|
|
bash "$ZULIP_PATH/scripts/lib/third/install-yarn.sh" "$ZULIP_SRV" --version "$yarn_version"
|