2014-12-22 00:16:06 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-05-25 21:08:33 +00:00
|
|
|
# Installs node.js only (no development dependencies) for both Ubuntu and OS X
|
2015-01-14 09:57:45 +00:00
|
|
|
|
2017-04-07 02:07:07 +00:00
|
|
|
#
|
2017-11-03 20:31:34 +00:00
|
|
|
# See https://git.coolaj86.com/coolaj86/node-installer.sh
|
2017-04-07 02:07:07 +00:00
|
|
|
#
|
2015-01-14 09:57:45 +00:00
|
|
|
|
2017-05-25 21:08:33 +00:00
|
|
|
# curl -fsSL bit.ly/nodejs-min | bash
|
|
|
|
# wget -nv bit.ly/nodejs-min -O - | bash
|
|
|
|
|
|
|
|
# curl -fsSL https://example.com/setup-min.bash | bash
|
|
|
|
# wget -nv https://example.com/setup-min.bash -O - | bash
|
|
|
|
|
2017-11-06 20:20:05 +00:00
|
|
|
# Not every platform has or needs sudo, gotta save them O(1)s...
|
|
|
|
sudo_cmd=""
|
|
|
|
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
|
|
|
|
2017-11-03 20:51:47 +00:00
|
|
|
deps_flag="$1"
|
2017-05-25 21:08:33 +00:00
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
#set -o pipefail
|
|
|
|
|
|
|
|
if [ -z "${PREFIX-}" ]; then
|
|
|
|
PREFIX=""
|
|
|
|
fi
|
2014-12-22 00:16:06 +00:00
|
|
|
|
2017-04-07 02:07:07 +00:00
|
|
|
NODEJS_NAME="node"
|
|
|
|
NODEJS_BASE_URL="https://nodejs.org"
|
2017-11-03 20:31:34 +00:00
|
|
|
BASE_URL="https://git.coolaj86.com/coolaj86/node-installer.sh/raw/master"
|
2017-05-25 17:17:40 +00:00
|
|
|
#NO_FAIL2BAN=""
|
|
|
|
NO_FAIL2BAN="nope"
|
2017-04-07 02:07:07 +00:00
|
|
|
OS="unsupported"
|
|
|
|
ARCH=""
|
|
|
|
SETUP_FILE=""
|
2018-06-23 22:29:13 +00:00
|
|
|
my_tmp=$(mktemp -d)
|
|
|
|
export my_tmp
|
2015-01-15 22:41:04 +00:00
|
|
|
|
2017-04-07 02:07:07 +00:00
|
|
|
clear
|
2015-01-15 22:41:04 +00:00
|
|
|
|
2017-04-07 02:07:07 +00:00
|
|
|
#########################
|
|
|
|
# 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
|
|
|
|
|
2017-11-06 20:20:05 +00:00
|
|
|
if [ -n "$(uname -a | grep 64)" ]; then
|
2017-04-07 02:07:07 +00:00
|
|
|
ARCH="64"
|
|
|
|
else
|
|
|
|
ARCH="32"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$(cat /etc/issue | grep -i 'Ubuntu')" ]; then
|
|
|
|
OS='ubuntu'
|
|
|
|
elif [ "$(cat /etc/issue | grep -i 'Linux Mint')" ]; then
|
|
|
|
OS='ubuntu'
|
|
|
|
elif [ "$(cat /etc/issue | grep -i 'elementary OS')" ]; then
|
|
|
|
OS='ubuntu'
|
|
|
|
elif [ "$(cat /etc/issue | grep -i 'Debian')" ]; then
|
|
|
|
OS='ubuntu'
|
|
|
|
elif [ "$(cat /etc/issue | grep -i 'Trisquel')" ]; then
|
|
|
|
OS='ubuntu'
|
|
|
|
elif [ "$(cat /etc/issue | grep -i 'Zorin')" ]; then
|
|
|
|
OS='ubuntu'
|
|
|
|
elif [ "$(cat /etc/issue | grep -i 'Raspbian')" ]; then
|
|
|
|
OS='raspbian'
|
|
|
|
elif [ "$(cat /etc/issue | grep -i 'Fedora')" ]; then
|
|
|
|
OS='fedora'
|
2017-11-06 20:20:05 +00:00
|
|
|
elif [ "$(cat /etc/issue | grep -i 'Marvell')" ]; then
|
|
|
|
OS='marvell'
|
2017-04-07 02:07:07 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "unsupported unknown os (non-mac, non-linux)"
|
|
|
|
exit 1
|
2014-12-22 00:16:06 +00:00
|
|
|
fi
|
|
|
|
|
2017-04-07 02:07:07 +00:00
|
|
|
case "${OS}" in
|
|
|
|
fedora)
|
|
|
|
echo "FEDORA not yet supported (feel free to pull request)"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
ubuntu)
|
|
|
|
SETUP_FILE="ubuntu"
|
|
|
|
;;
|
|
|
|
raspbian)
|
|
|
|
SETUP_FILE="ubuntu"
|
|
|
|
;;
|
2017-11-06 20:20:05 +00:00
|
|
|
marvell)
|
|
|
|
SETUP_FILE="ubuntu"
|
|
|
|
;;
|
2017-04-07 02:07:07 +00: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 #
|
|
|
|
#######################
|
|
|
|
|
2017-11-03 20:51:47 +00:00
|
|
|
if [ "--dev-deps" == "$deps_flag" ]; then
|
2017-05-25 21:08:33 +00:00
|
|
|
echo "Preparing to install node.js (and common development dependencies) for ${OS}" "${ARCH}"
|
|
|
|
else
|
|
|
|
echo "Preparing to install node.js (minimal) for ${OS}" "${ARCH}"
|
|
|
|
fi
|
2017-04-07 02:07:07 +00:00
|
|
|
|
2017-05-25 21:22:04 +00:00
|
|
|
INSTALL_DEPS_FILE="setup-deps-${SETUP_FILE}.bash"
|
2017-04-07 02:07:07 +00:00
|
|
|
INSTALL_FILE="setup-node-${SETUP_FILE}.bash"
|
2018-06-23 22:29:13 +00:00
|
|
|
if [ ! -e "$my_tmp/${INSTALL_FILE}" ]; then
|
2017-05-25 21:08:33 +00:00
|
|
|
if [ -n "$(type -p curl)" ]; then
|
2017-11-02 04:20:56 +00:00
|
|
|
curl --silent -L "${BASE_URL}/${INSTALL_FILE}" \
|
2018-06-23 22:29:13 +00:00
|
|
|
-o "$my_tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
|
2017-05-25 21:08:33 +00:00
|
|
|
elif [ -n "$(type -p wget)" ]; then
|
2017-04-07 02:07:07 +00:00
|
|
|
wget --quiet "${BASE_URL}/${INSTALL_FILE}" \
|
2018-06-23 22:29:13 +00:00
|
|
|
-O "$my_tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
|
2017-04-07 02:07:07 +00:00
|
|
|
else
|
|
|
|
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-11-03 20:51:47 +00:00
|
|
|
if [ "--dev-deps" == "$deps_flag" ]; then
|
2018-06-23 22:29:13 +00:00
|
|
|
if [ ! -e "$my_tmp/${INSTALL_DEPS_FILE}" ]; then
|
2017-05-30 00:03:29 +00:00
|
|
|
if [ -n "$(type -p curl)" ]; then
|
2017-11-02 04:20:56 +00:00
|
|
|
curl --silent -L "${BASE_URL}/${INSTALL_DEPS_FILE}" \
|
2018-06-23 22:29:13 +00:00
|
|
|
-o "$my_tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
|
2017-05-30 00:03:29 +00:00
|
|
|
elif [ -n "$(type -p wget)" ]; then
|
|
|
|
wget --quiet "${BASE_URL}/${INSTALL_DEPS_FILE}" \
|
2018-06-23 22:29:13 +00:00
|
|
|
-O "$my_tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
|
2017-05-30 00:03:29 +00:00
|
|
|
else
|
|
|
|
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-06-23 22:29:13 +00:00
|
|
|
if [ ! -e "$my_tmp/${INSTALL_FILE}" ]
|
2017-04-07 02:07:07 +00:00
|
|
|
then
|
|
|
|
echo "Error Downloading Install File"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-03 20:51:47 +00:00
|
|
|
if [ "--dev-deps" == "$deps_flag" ]; then
|
2018-06-23 22:29:13 +00:00
|
|
|
if [ ! -e "$my_tmp/${INSTALL_DEPS_FILE}" ]
|
2017-05-29 23:58:16 +00:00
|
|
|
then
|
|
|
|
echo "Error Downloading Deps File"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-04-07 02:07:07 +00:00
|
|
|
#########################
|
|
|
|
# Which node.js VERSION ? #
|
|
|
|
#########################
|
|
|
|
|
2018-05-12 19:45:15 +00:00
|
|
|
if [ -z "${NODEJS_VER:-}" ]; then
|
|
|
|
# For backwards compat
|
2018-06-23 22:29:13 +00:00
|
|
|
if [ -f "$my_tmp/NODEJS_VER" ]; then
|
|
|
|
NODEJS_VER=$(cat $my_tmp/NODEJS_VER | grep v)
|
2018-05-12 19:45:15 +00:00
|
|
|
elif [ -f "/tmp/IOJS_VER" ]; then
|
2018-06-23 22:29:13 +00:00
|
|
|
NODEJS_VER=$(cat $my_tmp/IOJS_VER | grep v)
|
2018-05-12 19:45:15 +00:00
|
|
|
fi
|
2017-04-07 02:07:07 +00:00
|
|
|
fi
|
|
|
|
|
2018-05-12 20:37:54 +00:00
|
|
|
if [ -n "${NODEJS_VER:-}" ]; then
|
2017-04-07 02:07:07 +00:00
|
|
|
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
|
|
|
|
|
|
|
|
if [ $NODEJS_VERT -ge 1 ] && [ $NODEJS_VERT -lt 4 ]
|
|
|
|
then
|
|
|
|
echo "Selecting io.js instead of node.js for this version (>= 1.0.0 < 4.0.0)"
|
|
|
|
NODEJS_BASE_URL="https://iojs.org"
|
|
|
|
NODEJS_NAME="iojs"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-05-12 20:37:54 +00:00
|
|
|
if [ -z "${NODEJS_VER:-}" ]; then
|
2017-05-30 00:03:29 +00:00
|
|
|
if [ -n "$(type -p curl)" ]; then
|
2017-11-06 20:20:05 +00:00
|
|
|
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -n 2 | tail -1 | cut -f 1) \
|
2017-05-25 21:08:33 +00:00
|
|
|
|| echo 'error automatically determining current node.js version'
|
2017-05-30 00:03:29 +00:00
|
|
|
elif [ -n "$(type -p wget)" ]; then
|
2017-11-06 20:20:05 +00:00
|
|
|
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -n 2 | tail -1 | cut -f 1) \
|
2017-05-25 21:08:33 +00:00
|
|
|
|| echo 'error automatically determining current node.js version'
|
2017-04-07 02:07:07 +00:00
|
|
|
else
|
|
|
|
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# node
|
|
|
|
#
|
2017-05-25 21:08:33 +00:00
|
|
|
if [ -z "${NODE_PATH-}" ]; then
|
|
|
|
if [ -n "$(type -p node | grep node 2>/dev/null)" ]; then
|
|
|
|
# /usr/local/bin/node => /usr/local
|
|
|
|
node_install_path="$(dirname $(dirname $(type -p node)))"
|
2017-11-03 21:21:25 +00:00
|
|
|
echo "NODE_PATH is not set. Using existing node install path: '$node_install_path'"
|
2017-05-25 21:08:33 +00:00
|
|
|
else
|
|
|
|
node_install_path=$PREFIX/usr/local
|
2017-11-03 21:21:25 +00:00
|
|
|
echo "NODE_PATH is not set. Using default install path '$node_install_path'"
|
2017-05-25 21:08:33 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
node_install_path=$(dirname $(dirname $NODE_PATH))
|
2017-11-03 21:21:25 +00:00
|
|
|
echo "NODE_PATH is '$NODE_PATH', so install path is '$node_install_path'"
|
2017-05-25 21:08:33 +00:00
|
|
|
fi
|
|
|
|
if [ -e "$node_install_path/bin/node" ]; then
|
2017-04-07 02:07:07 +00:00
|
|
|
# node of some version is already installed
|
2017-07-21 21:47:05 +00:00
|
|
|
if [ "${NODEJS_VER}" == "$($node_install_path/bin/node -v 2>/dev/null)" ]; then
|
2017-04-07 02:07:07 +00:00
|
|
|
echo node ${NODEJS_VER} is already installed
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "HEY, LISTEN:"
|
|
|
|
echo ""
|
2017-07-21 21:47:05 +00:00
|
|
|
echo "node.js is already installed as node $($node_install_path/bin/node -v | grep v)"
|
2017-04-07 02:07:07 +00:00
|
|
|
echo ""
|
2017-07-21 21:47:05 +00:00
|
|
|
echo "to reinstall please first run: rm $node_install_path/bin/node"
|
2017-04-07 02:07:07 +00:00
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
|
|
|
|
NODEJS_VER=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${NODEJS_VER}" ]; then
|
2018-06-23 22:29:13 +00:00
|
|
|
bash "$my_tmp/${INSTALL_FILE}" "${NODEJS_VER}"
|
2017-04-07 02:07:07 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-23 22:29:13 +00:00
|
|
|
chown -R $(whoami) $node_install_path/lib/node_modules || $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
|
2014-12-22 00:16:06 +00:00
|
|
|
|
2017-04-07 02:07:07 +00:00
|
|
|
echo ""
|
2017-05-25 21:08:33 +00:00
|
|
|
|
2017-11-03 20:51:47 +00:00
|
|
|
if [ "--dev-deps" == "$deps_flag" ]; then
|
2017-05-25 21:08:33 +00:00
|
|
|
|
|
|
|
################
|
|
|
|
# DEPENDENCIES #
|
|
|
|
################
|
|
|
|
|
|
|
|
#if [ -z "$(which fail2ban-server | grep fail2ban)" ]; then
|
|
|
|
# echo ""
|
|
|
|
# echo "Your server didn't come with fail2ban preinstalled!!!"
|
|
|
|
# echo "Among other things, fail2ban secures ssh so that your server isn't reaped by botnets."
|
|
|
|
# echo ""
|
|
|
|
# echo "Since you're obviously connecting this computer to a network, you should install fail2ban before continuing"
|
|
|
|
# echo ""
|
|
|
|
# echo "Install fail2ban? [Y/n]"
|
|
|
|
# echo "(if unsure, just hit [enter])"
|
|
|
|
# read INSTALL_FAIL2BAN
|
|
|
|
#
|
|
|
|
# if [ "n" == "${INSTALL_FAIL2BAN}" ] || [ "no" == "${INSTALL_FAIL2BAN}" ] || [ "N" == "${INSTALL_FAIL2BAN}" ] || [ "NO" == "${INSTALL_FAIL2BAN}" ]; then
|
|
|
|
# echo ""
|
|
|
|
# echo "I don't think you understand: This is important."
|
|
|
|
# echo ""
|
|
|
|
# echo "Your server will be under constant attack by botnets via ssh."
|
|
|
|
# echo "It only takes a few extra seconds to install and the defaults are adequate for protecting you."
|
|
|
|
# echo ""
|
|
|
|
# echo "Change your mind?"
|
|
|
|
# echo "Ready to install fail2ban? [Y/n]"
|
|
|
|
# read INSTALL_FAIL2BAN
|
|
|
|
# if [ "n" == "${INSTALL_FAIL2BAN}" ] || [ "no" == "${INSTALL_FAIL2BAN}" ] || [ "N" == "${INSTALL_FAIL2BAN}" ] || [ "NO" == "${INSTALL_FAIL2BAN}" ]; then
|
|
|
|
# clear
|
|
|
|
# echo "you make me sad :-("
|
|
|
|
# sleep 0.5
|
|
|
|
# echo "but whatever, it's your funeral..."
|
|
|
|
# sleep 1
|
|
|
|
# NO_FAIL2BAN="nope"
|
|
|
|
# else
|
|
|
|
# echo "Phew, dodged the bullet on that one... Will install fail2ban.. :-)"
|
|
|
|
# fi
|
|
|
|
# fi
|
|
|
|
#fi
|
|
|
|
|
2018-06-23 22:29:13 +00:00
|
|
|
bash "$my_tmp/${INSTALL_DEPS_FILE}" "${NO_FAIL2BAN}"
|
2017-05-25 21:08:33 +00:00
|
|
|
|
|
|
|
# yarn
|
2017-06-16 01:39:46 +00:00
|
|
|
#if [ -z "$(type -p yarn)" ]; then
|
|
|
|
# echo "installing yarn..."
|
|
|
|
# npm install --silent yarn -g > /dev/null
|
|
|
|
#fi
|
2017-05-25 21:08:33 +00:00
|
|
|
|
|
|
|
# jshint
|
|
|
|
if [ -z "$(type -p jshint)" ]; then
|
|
|
|
echo "installing jshint..."
|
2017-06-16 02:44:21 +00:00
|
|
|
#yarn global add jshint > /dev/null
|
2017-07-21 21:47:05 +00:00
|
|
|
$node_install_path/bin/npm install -g jshint > /dev/null
|
2017-05-25 21:08:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
fi
|