2016-09-21 08:44:01 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2017-07-27 23:22:52 +02:00
|
|
|
ZULIP_PATH="$(dirname "$0")/../.."
|
|
|
|
ZULIP_SRV="/srv"
|
|
|
|
if [ "$TRAVIS" ] ; then
|
|
|
|
ZULIP_SRV="/home/travis"
|
|
|
|
fi
|
|
|
|
YARN_BIN="$ZULIP_SRV/zulip-yarn/bin/yarn"
|
2018-04-04 20:06:41 +02:00
|
|
|
node_version=8.11.1
|
2018-06-05 10:03:43 +02:00
|
|
|
yarn_version=1.7.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-07-29 01:50:53 +02:00
|
|
|
if node_wrapper_path="$(type -p node)"; then
|
2017-07-11 21:36:33 +02:00
|
|
|
current_node_version="$(node --version)"
|
|
|
|
fi
|
|
|
|
|
2018-07-29 01:50:53 +02:00
|
|
|
if [ "$($YARN_BIN --version 2>/dev/null)" = "$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
|
|
|
|
if ! [ -e "$NVM_DIR/nvm.sh" ]; then
|
2018-04-04 20:06:41 +02:00
|
|
|
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
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
|
|
|
source "$NVM_DIR/nvm.sh"
|
|
|
|
nvm install "$node_version" && nvm alias default "$node_version"
|
|
|
|
export 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
|
|
|
|
n=$(which node)
|
|
|
|
n=${n%/bin/node}
|
|
|
|
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
|
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"
|