#!/usr/bin/env bash set -e [ -n "$NODENV_DEBUG" ] && { export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '; set -x; } homebrew= type -p brew >/dev/null && homebrew=1 try_bash_extension() { if [ -x src/configure ]; then { src/configure && make -C src; } || { echo "Optional bash extension failed to build, but things will still work normally." } fi } if ! type -p git >/dev/null; then git() { echo "Error: git is required to proceed. Please install git and try again." >&2 exit 1 } fi http() { local url="$1" if type -p curl >/dev/null; then curl -fsSL "$url" elif type -p wget >/dev/null; then wget -q "$url" -O- else echo "Error: couldn't download file. No \`curl' or \`wget' found." >&2 return 1 fi } nodenv="$(command -v nodenv ~/.nodenv/bin/nodenv | head -1)" if [ -n "$nodenv" ]; then echo "nodenv already seems installed in \`$nodenv'." cd "${nodenv%/*}" if [ -x ./brew ]; then echo "Trying to update with Homebrew..." brew update >/dev/null if [ "$(./nodenv --version)" \< "1.0.0" ] && brew list nodenv | grep -q nodenv/HEAD; then brew uninstall nodenv brew install nodenv else brew upgrade nodenv fi elif git remote -v 2>/dev/null | grep -q nodenv; then echo "Trying to update with git..." git pull --tags origin master cd .. try_bash_extension fi else if [ -n "$homebrew" ]; then echo "Installing nodenv with Homebrew..." brew update brew install nodenv nodenv="$(brew --prefix)/bin/nodenv" else echo "Installing nodenv with git..." mkdir -p ~/.nodenv cd ~/.nodenv git init git remote add -f -t master origin https://github.com/nodenv/nodenv.git git checkout -b master origin/master try_bash_extension nodenv=~/.nodenv/bin/nodenv if [ ! -e versions ] && [ -w /opt/rubies ]; then ln -s /opt/rubies versions fi fi fi nodenv_root="$("$nodenv" root)" node_build="$(command -v "$nodenv_root"/plugins/*/bin/nodenv-install nodenv-install | head -1)" echo if [ -n "$node_build" ]; then echo "\`nodenv install' command already available in \`$node_build'." cd "${node_build%/*}" if [ -x ./brew ]; then echo "Trying to update with Homebrew..." brew update >/dev/null brew upgrade node-build elif git remote -v 2>/dev/null | grep -q node-build; then echo "Trying to update with git..." git pull origin master fi else if [ -n "$homebrew" ]; then echo "Installing node-build with Homebrew..." brew update brew install node-build else echo "Installing node-build with git..." mkdir -p "${nodenv_root}/plugins" git clone https://github.com/nodenv/node-build.git "${nodenv_root}/plugins/node-build" fi fi # Enable caching of nodenv-install downloads mkdir -p "${nodenv_root}/cache" echo echo "Running doctor script to verify installation..." http https://raw.githubusercontent.com/nodenv/nodenv-installer/recent-install/bin/nodenv-doctor | "$BASH" echo echo "All done!" echo "Note that this installer doesn't yet configure your shell startup files:" i=0 if [ -x ~/.nodenv/bin ]; then echo "$((++i)). You'll want to ensure that \`~/.nodenv/bin' is added to PATH." fi echo "$((++i)). Run \`nodenv init' to see instructions how to configure nodenv for your shell." echo "$((++i)). Launch a new terminal window to verify that the configuration is correct." echo