zulip/scripts/lib/install-node

43 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
ZULIP_PATH=$(dirname "$0")
node_version=6.6.0
npm_version=3.10.3
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
echo "Node version $node_version and npm version $npm_version are already installed."
exit 0
fi
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"
export NODE_BIN="$(nvm which default)"
export NPM_BIN=$(echo "$NODE_BIN" | sed 's/node$/npm/')
# 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
sed -i "s|NODE_PATH|$NODE_BIN|" /usr/local/bin/node
cp "$ZULIP_PATH/../../scripts/setup/npm-wrapper" /usr/local/bin/npm
sed -i "s|NPM_PATH|$NPM_BIN|" /usr/local/bin/npm