| 
									
										
										
										
											2015-01-19 17:06:29 -07:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 15:50:12 -04:00
										 |  |  | # Installs node.js only (no development dependencies) for both Ubuntu and OS X | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2016-03-28 15:50:12 -04:00
										 |  |  | # See https://github.com/coolaj86/node-install-script | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 15:50:12 -04:00
										 |  |  | # curl -fsSL bit.ly/nodejs-min | bash | 
					
						
							|  |  |  | # wget -nv bit.ly/nodejs-min -O - | bash | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # curl -fsSL https://example.com/setup-min.bash | bash | 
					
						
							|  |  |  | # wget -nv https://example.com/setup-min.bash -O - | bash | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  | NODEJS_NAME="node" | 
					
						
							|  |  |  | NODEJS_BASE_URL="https://nodejs.org" | 
					
						
							| 
									
										
										
										
											2016-03-28 16:24:37 -04:00
										 |  |  | BASE_URL="https://raw.githubusercontent.com/coolaj86/node-install-script/master" | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | OS="unsupported" | 
					
						
							|  |  |  | ARCH="" | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  | NODEJS_VER="" | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | SETUP_FILE="" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | clear | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ######################### | 
					
						
							|  |  |  | # Which OS and version? # | 
					
						
							|  |  |  | ######################### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ "$(uname | grep -i 'Darwin')" ]; then | 
					
						
							|  |  |  |   OSX_VER="$(sw_vers | grep ProductVersion | cut -d':' -f2 | cut -f2)" | 
					
						
							|  |  |  |   OSX_MAJOR="$(echo ${OSX_VER} | cut -d'.' -f1)" | 
					
						
							|  |  |  |   OSX_MINOR="$(echo ${OSX_VER} | cut -d'.' -f2)" | 
					
						
							|  |  |  |   OSX_PATCH="$(echo ${OSX_VER} | cut -d'.' -f3)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # Major | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   if [ "$OSX_MAJOR" -lt 10 ]; then | 
					
						
							|  |  |  |     echo "unsupported OS X version (os 9-)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ "$OSX_MAJOR" -gt 10 ]; then | 
					
						
							|  |  |  |     echo "unsupported OS X version (os 11+)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   # Minor | 
					
						
							|  |  |  |   # | 
					
						
							|  |  |  |   if [ "$OSX_MINOR" -le 5 ]; then | 
					
						
							|  |  |  |     echo "unsupported OS X version (os 10.5-)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Snow | 
					
						
							|  |  |  |   if [ "$OSX_MINOR" -eq 6 ]; then | 
					
						
							|  |  |  |     OS='snow' | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Lion | 
					
						
							|  |  |  |   if [ $OSX_MINOR -eq 7 ]; then | 
					
						
							|  |  |  |     OS='lion' | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Mountain Lion | 
					
						
							|  |  |  |   if [ "$OSX_MINOR" -eq 8 ]; then | 
					
						
							|  |  |  |     OS='mountain' | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Mavericks, Yosemite | 
					
						
							|  |  |  |   if [ "$OSX_MINOR" -ge 9 ]; then | 
					
						
							|  |  |  |     OS='mavericks' | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -n "$(sysctl hw | grep 64bit | grep ': 1')" ]; then | 
					
						
							|  |  |  |     ARCH="64" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     ARCH="32" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | elif [ "$(uname | grep -i 'Linux')" ]; then | 
					
						
							|  |  |  |   if [ ! -f "/etc/issue" ]; then | 
					
						
							|  |  |  |     echo "unsupported linux os" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -n "$(arch | grep 64)" ]; then | 
					
						
							|  |  |  |     ARCH="64" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     ARCH="32" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ "$(cat /etc/issue | grep -i 'Ubuntu')" ]; then | 
					
						
							|  |  |  |     OS='ubuntu' | 
					
						
							| 
									
										
										
										
											2015-03-19 21:31:19 -06:00
										 |  |  |   elif [ "$(cat /etc/issue | grep -i 'Raspbian')" ]; then | 
					
						
							|  |  |  |     OS='raspbian' | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  |   elif [ "$(cat /etc/issue | grep -i 'Fedora')" ]; then | 
					
						
							|  |  |  |     OS='fedora' | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   echo "unsupported unknown os (non-mac, non-linux)" | 
					
						
							|  |  |  |   exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | case "${OS}" in | 
					
						
							|  |  |  |   fedora) | 
					
						
							|  |  |  |     echo "FEDORA not yet supported (feel free to pull request)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   ubuntu) | 
					
						
							|  |  |  |     SETUP_FILE="ubuntu" | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2015-03-19 21:31:19 -06:00
										 |  |  |   raspbian) | 
					
						
							| 
									
										
										
										
											2015-03-19 21:32:37 -06:00
										 |  |  |     SETUP_FILE="ubuntu" | 
					
						
							| 
									
										
										
										
											2015-03-19 21:31:19 -06:00
										 |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  |   yosemite) | 
					
						
							|  |  |  |     # mavericks | 
					
						
							|  |  |  |     SETUP_FILE="mavericks" | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   mavericks) | 
					
						
							|  |  |  |     SETUP_FILE="mavericks" | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   mountain) | 
					
						
							|  |  |  |     echo "Mountain Lion not yet supported (feel free to pull request)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   lion) | 
					
						
							|  |  |  |     echo "Lion not yet supported (feel free to pull request)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   snow) | 
					
						
							|  |  |  |     echo "Snow Leopard not yet supported (feel free to pull request)" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |   *) | 
					
						
							|  |  |  |     echo "unsupported unknown os ${OS}" | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  | esac | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ####################### | 
					
						
							|  |  |  | # Download installers # | 
					
						
							|  |  |  | ####################### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "Preparing to install io.js (and common development dependencies) for ${OS}" "${ARCH}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 15:50:12 -04:00
										 |  |  | INSTALL_FILE="setup-node-${SETUP_FILE}.bash" | 
					
						
							|  |  |  | if [ ! -e "/tmp/${INSTALL_FILE}" ] | 
					
						
							|  |  |  | then | 
					
						
							|  |  |  |   if [ -n "$(which curl)" ]; then | 
					
						
							|  |  |  |     curl --silent "${BASE_URL}/${INSTALL_FILE}" \
 | 
					
						
							|  |  |  |       -o "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script' | 
					
						
							|  |  |  |   elif [ -n "$(which wget)" ]; then | 
					
						
							|  |  |  |     wget --quiet "${BASE_URL}/${INSTALL_FILE}" \
 | 
					
						
							|  |  |  |       -O "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script' | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     echo "Found neither 'curl' nor 'wget'. Can't Continue." | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ ! -e "/tmp/${INSTALL_FILE}" ] | 
					
						
							|  |  |  | then | 
					
						
							|  |  |  |   echo "Error Downloading Install File" | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  |   exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ######################### | 
					
						
							|  |  |  | # Which io.js VERSION ? # | 
					
						
							|  |  |  | ######################### | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  | if [ -f "/tmp/NODEJS_VER" ]; then | 
					
						
							|  |  |  |   NODEJS_VER=$(cat /tmp/NODEJS_VER | grep v) | 
					
						
							|  |  |  | elif [ -f "/tmp/IOJS_VER" ]; then | 
					
						
							|  |  |  |   NODEJS_VER=$(cat /tmp/IOJS_VER | grep v) | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  | if [ -n "$NODEJS_VER" ]; then | 
					
						
							|  |  |  |   NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-22 21:50:41 -05:00
										 |  |  |   if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ] | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  |   then | 
					
						
							| 
									
										
										
										
											2015-12-22 21:50:41 -05:00
										 |  |  |     echo "Selecting io.js instead of node.js for this version (>= 1.0.0 < 4.0.0)" | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  |     NODEJS_BASE_URL="https://iojs.org" | 
					
						
							|  |  |  |     NODEJS_NAME="iojs" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ -z "$NODEJS_VER" ]; then | 
					
						
							| 
									
										
										
										
											2015-04-22 09:48:01 -06:00
										 |  |  |   if [ -n "$(which curl)" ]; then | 
					
						
							| 
									
										
										
										
											2016-03-28 17:19:18 -04:00
										 |  |  |     NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -2 | tail -1 | cut -f 1) \
 | 
					
						
							| 
									
										
										
										
											2015-04-22 09:48:01 -06:00
										 |  |  |       || echo 'error automatically determining current io.js version' | 
					
						
							|  |  |  |   elif [ -n "$(which wget)" ]; then | 
					
						
							| 
									
										
										
										
											2016-03-28 15:50:12 -04:00
										 |  |  |     NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -2 | tail -1 | cut -f 1) \
 | 
					
						
							| 
									
										
										
										
											2015-04-22 09:48:01 -06:00
										 |  |  |       || echo 'error automatically determining current io.js version' | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     echo "Found neither 'curl' nor 'wget'. Can't Continue." | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2016-03-28 16:11:01 -04:00
										 |  |  | # node | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2016-03-28 16:11:01 -04:00
										 |  |  | if [ -n "$(which node | grep node 2>/dev/null)" ]; then | 
					
						
							|  |  |  | # node of some version is already installed | 
					
						
							|  |  |  |   if [ "${NODEJS_VER}" == "$(node -v 2>/dev/null)" ]; then | 
					
						
							|  |  |  |     echo node ${NODEJS_VER} is already installed | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  |   else | 
					
						
							|  |  |  |     echo "" | 
					
						
							|  |  |  |     echo "HEY, LISTEN:" | 
					
						
							|  |  |  |     echo "" | 
					
						
							| 
									
										
										
										
											2016-03-28 16:11:01 -04:00
										 |  |  |     echo "node.js is already installed as node $(node -v | grep v)" | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  |     echo "" | 
					
						
							| 
									
										
										
										
											2016-03-28 16:11:01 -04:00
										 |  |  |     echo "to reinstall please first run: rm $(which node)" | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  |     echo "" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2016-03-28 16:11:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  |   NODEJS_VER="" | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 13:35:08 -06:00
										 |  |  | if [ -n "${NODEJS_VER}" ]; then | 
					
						
							| 
									
										
										
										
											2016-03-28 15:50:12 -04:00
										 |  |  |   bash "/tmp/${INSTALL_FILE}" "${NODEJS_VER}" | 
					
						
							| 
									
										
										
										
											2015-01-20 23:17:31 -07:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "" |