2016-09-21 08:44:01 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
ZULIP_PATH=$(dirname "$0")
|
2017-06-12 18:05:02 +02:00
|
|
|
node_version=6.6.0
|
|
|
|
npm_version=3.10.3
|
|
|
|
|
2017-07-11 21:36:33 +02:00
|
|
|
current_npm_version="none"
|
|
|
|
if hash npm 2>/dev/null; then
|
|
|
|
current_npm_version="$(npm --version)"
|
|
|
|
fi
|
|
|
|
current_node_version="none"
|
|
|
|
if hash node 2>/dev/null; then
|
|
|
|
current_node_version="$(node --version)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$current_npm_version" = "$npm_version" ] && [ "$current_node_version" = "v$node_version" ]; then
|
2017-06-12 18:05:02 +02:00
|
|
|
echo "Node version $node_version and npm version $npm_version are already installed."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2016-09-21 08:44:01 +02:00
|
|
|
export NVM_DIR=/usr/local/nvm
|
|
|
|
if ! [ -e "$NVM_DIR/nvm.sh" ]; then
|
|
|
|
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
|
|
|
|
fi
|
|
|
|
|
|
|
|
source "$NVM_DIR/nvm.sh"
|
|
|
|
nvm install "$node_version" && nvm alias default "$node_version"
|
2017-05-09 16:25:31 +02:00
|
|
|
export NODE_BIN="$(nvm which default)"
|
2017-06-10 08:16:47 +02:00
|
|
|
export NPM_BIN=$(echo "$NODE_BIN" | sed 's/node$/npm/')
|
2016-09-21 08:44:01 +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"
|
|
|
|
|
|
|
|
# Install node and npm wrappers to /usr/local/bin
|
|
|
|
cp "$ZULIP_PATH/../../scripts/setup/node-wrapper" /usr/local/bin/node
|
2017-05-09 16:25:31 +02:00
|
|
|
sed -i "s|NODE_PATH|$NODE_BIN|" /usr/local/bin/node
|
2016-09-21 08:44:01 +02:00
|
|
|
cp "$ZULIP_PATH/../../scripts/setup/npm-wrapper" /usr/local/bin/npm
|
2017-06-10 08:16:47 +02:00
|
|
|
sed -i "s|NPM_PATH|$NPM_BIN|" /usr/local/bin/npm
|