deiga
3/27/2017 - 3:30 PM

Node installation script with bash

Node installation script with bash

function install_node() {
  local REQUIRED_MAJOR_NODE_VERSION=${REQUIRED_NODEJS_VERSION:0:1}
  echo "${BLUE}Which version manager do you want to install node.js with? If you don't know, choose 'brew'${NORMAL}:"
  select NODE_VERSION_MANAGER in 'brew' 'nvm' 'nodenv' 'other';
  do
    case $NODE_VERSION_MANAGER in
      'nvm'|'nodenv')
        verify_command $NODE_VERSION_MANAGER
        set +x
        $NODE_VERSION_MANAGER install $REQUIRED_MAJOR_NODE_VERSION
        set -x
        break
        ;;
      'other')
        read -p "${BLUE}Please write the command of your node version manager: ${NORMAL}" -r
        local OTHER=$REPLY
        if ! command -v "$OTHER"; then
          echo "${RED}$OTHER does not exist.$NORMAL" >&2
          install_node_homebrew
        else
          ${OTHER} install $REQUIRED_MAJOR_NODE_VERSION
        fi
        break
        ;;
      'brew'|*)
        install_node_homebrew
        break
        ;;
    esac
  done
}