consolidate installer
This commit is contained in:
parent
0e84c903e9
commit
b33f1136f2
236
setup-min.sh
236
setup-min.sh
|
@ -1,176 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Installs node.js only (no development dependencies) for both Ubuntu and OS X
|
||||
# Installs node.js + dependencies for both Ubuntu and OS X
|
||||
|
||||
#
|
||||
# See https://git.daplie.com/coolaj86/node-install-script
|
||||
#
|
||||
|
||||
# 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
|
||||
# curl -fsSL https://example.com/setup.bash | bash
|
||||
# wget -nv https://example.com/setup.bash -O - | bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
#set -o pipefail
|
||||
|
||||
if [ -z "${PREFIX-}" ]; then
|
||||
PREFIX=""
|
||||
fi
|
||||
|
||||
NODEJS_NAME="node"
|
||||
NODEJS_BASE_URL="https://nodejs.org"
|
||||
BASE_URL="https://git.daplie.com/coolaj86/node-install-script/raw/master"
|
||||
OS="unsupported"
|
||||
ARCH=""
|
||||
NODEJS_VER=""
|
||||
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'
|
||||
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'
|
||||
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"
|
||||
;;
|
||||
raspbian)
|
||||
SETUP_FILE="ubuntu"
|
||||
;;
|
||||
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 node.js (and common development dependencies) for ${OS}" "${ARCH}"
|
||||
|
||||
INSTALL_FILE="setup-node-${SETUP_FILE}.bash"
|
||||
INSTALL_FILE_REMOTE="setup.bash"
|
||||
INSTALL_FILE="node.setup.bash"
|
||||
if [ ! -e "/tmp/${INSTALL_FILE}" ]
|
||||
then
|
||||
if [ -n "$(type -p curl)" ]; then
|
||||
curl --silent "${BASE_URL}/${INSTALL_FILE}" \
|
||||
-o "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
|
||||
elif [ -n "$(type -p wget)" ]; then
|
||||
wget --quiet "${BASE_URL}/${INSTALL_FILE}" \
|
||||
-O "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
|
||||
if [ -n "$(which curl)" ]; then
|
||||
curl --silent "${BASE_URL}/${INSTALL_FILE_REMOTE}" \
|
||||
-o "/tmp/${INSTALL_FILE}" || echo 'error setup script: '"${BASE_URL}/${INSTALL_FILE_REMOTE}"
|
||||
elif [ -n "$(which wget)" ]; then
|
||||
wget --quiet "${BASE_URL}/${INSTALL_FILE_REMOTE}" \
|
||||
-O "/tmp/${INSTALL_FILE}" || echo 'error setup script: '"${BASE_URL}/${INSTALL_FILE_REMOTE}"
|
||||
else
|
||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||
exit 1
|
||||
|
@ -183,74 +40,5 @@ then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
#########################
|
||||
# Which node.js VERSION ? #
|
||||
#########################
|
||||
|
||||
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)
|
||||
fi
|
||||
|
||||
if [ -n "$NODEJS_VER" ]; then
|
||||
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
|
||||
|
||||
if [ -z "$NODEJS_VER" ]; then
|
||||
if [ -n "$(which curl)" ]; then
|
||||
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -2 | tail -1 | cut -f 1) \
|
||||
|| echo 'error automatically determining current node.js version'
|
||||
elif [ -n "$(which wget)" ]; then
|
||||
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -2 | tail -1 | cut -f 1) \
|
||||
|| echo 'error automatically determining current node.js version'
|
||||
else
|
||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# node
|
||||
#
|
||||
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)))"
|
||||
else
|
||||
node_install_path=$PREFIX/usr/local
|
||||
fi
|
||||
else
|
||||
node_install_path=$(dirname $(dirname $NODE_PATH))
|
||||
fi
|
||||
if [ -e "$node_install_path/bin/node" ]; then
|
||||
# node of some version is already installed
|
||||
if [ "${NODEJS_VER}" == "$(node -v 2>/dev/null)" ]; then
|
||||
echo node ${NODEJS_VER} is already installed
|
||||
else
|
||||
echo ""
|
||||
echo "HEY, LISTEN:"
|
||||
echo ""
|
||||
echo "node.js is already installed as node $(node -v | grep v)"
|
||||
echo ""
|
||||
echo "to reinstall please first run: rm $(which node)"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
NODEJS_VER=""
|
||||
fi
|
||||
|
||||
if [ -n "${NODEJS_VER}" ]; then
|
||||
bash "/tmp/${INSTALL_FILE}" "${NODEJS_VER}"
|
||||
fi
|
||||
|
||||
sudo chown -R $(whoami) $node_install_path/lib/node_modules
|
||||
|
||||
echo ""
|
||||
bash "/tmp/${INSTALL_FILE}" --no-dev-deps
|
||||
|
|
178
setup.bash
178
setup.bash
|
@ -1,13 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Installs node.js + dependencies for both Ubuntu and OS X
|
||||
# Installs node.js only (no development dependencies) for both Ubuntu and OS X
|
||||
|
||||
#
|
||||
# See https://git.daplie.com/coolaj86/node-install-script
|
||||
#
|
||||
|
||||
# curl -fsSL https://example.com/setup.bash | bash
|
||||
# wget -nv https://example.com/setup.bash -O - | bash
|
||||
# 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
|
||||
|
||||
dont_install_deps="$1"
|
||||
set -e
|
||||
set -u
|
||||
#set -o pipefail
|
||||
|
||||
if [ -z "${PREFIX-}" ]; then
|
||||
PREFIX=""
|
||||
fi
|
||||
|
||||
NODEJS_NAME="node"
|
||||
NODEJS_BASE_URL="https://nodejs.org"
|
||||
|
@ -21,8 +33,6 @@ SETUP_FILE=""
|
|||
|
||||
clear
|
||||
|
||||
|
||||
|
||||
#########################
|
||||
# Which OS and version? #
|
||||
#########################
|
||||
|
@ -149,41 +159,118 @@ case "${OS}" in
|
|||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
|
||||
#######################
|
||||
# Download installers #
|
||||
#######################
|
||||
|
||||
echo "Preparing to install ${NODEJS_NAME} (and common development dependencies) for ${OS}" "${ARCH}"
|
||||
if [ -z "$dont_install_deps" ]; then
|
||||
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
|
||||
|
||||
INSTALL_DEPS_FILE="setup-deps-${SETUP_FILE}.bash"
|
||||
INSTALL_FILE="setup-node-${SETUP_FILE}.bash"
|
||||
if [ ! -e "/tmp/${INSTALL_DEPS_FILE}" ]
|
||||
if [ ! -e "/tmp/${INSTALL_FILE}" ]
|
||||
then
|
||||
if [ -n "$(which curl)" ]; then
|
||||
if [ -n "$(type -p curl)" ]; then
|
||||
if [ -z "$(dont_install_deps)" ]; then
|
||||
curl --silent "${BASE_URL}/${INSTALL_DEPS_FILE}" \
|
||||
-o "/tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
|
||||
fi
|
||||
curl --silent "${BASE_URL}/${INSTALL_FILE}" \
|
||||
-o "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script: '"${BASE_URL}/${INSTALL_FILE}"
|
||||
elif [ -n "$(which wget)" ]; then
|
||||
-o "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
|
||||
elif [ -n "$(type -p wget)" ]; then
|
||||
if [ -z "$(dont_install_deps)" ]; then
|
||||
wget --quiet "${BASE_URL}/${INSTALL_DEPS_FILE}" \
|
||||
-O "/tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
|
||||
fi
|
||||
wget --quiet "${BASE_URL}/${INSTALL_FILE}" \
|
||||
-O "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script: '"${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_DEPS_FILE}" ]
|
||||
if [ ! -e "/tmp/${INSTALL_FILE}" ]
|
||||
then
|
||||
echo "Error Downloading Install File"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#########################
|
||||
# Which node.js VERSION ? #
|
||||
#########################
|
||||
|
||||
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)
|
||||
fi
|
||||
|
||||
if [ -n "$NODEJS_VER" ]; then
|
||||
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
|
||||
|
||||
if [ -z "$NODEJS_VER" ]; then
|
||||
if [ -n "$(which curl)" ]; then
|
||||
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -2 | tail -1 | cut -f 1) \
|
||||
|| echo 'error automatically determining current node.js version'
|
||||
elif [ -n "$(which wget)" ]; then
|
||||
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -2 | tail -1 | cut -f 1) \
|
||||
|| echo 'error automatically determining current node.js version'
|
||||
else
|
||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# node
|
||||
#
|
||||
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)))"
|
||||
else
|
||||
node_install_path=$PREFIX/usr/local
|
||||
fi
|
||||
else
|
||||
node_install_path=$(dirname $(dirname $NODE_PATH))
|
||||
fi
|
||||
if [ -e "$node_install_path/bin/node" ]; then
|
||||
# node of some version is already installed
|
||||
if [ "${NODEJS_VER}" == "$(node -v 2>/dev/null)" ]; then
|
||||
echo node ${NODEJS_VER} is already installed
|
||||
else
|
||||
echo ""
|
||||
echo "HEY, LISTEN:"
|
||||
echo ""
|
||||
echo "node.js is already installed as node $(node -v | grep v)"
|
||||
echo ""
|
||||
echo "to reinstall please first run: rm $(which node)"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
NODEJS_VER=""
|
||||
fi
|
||||
|
||||
if [ -n "${NODEJS_VER}" ]; then
|
||||
bash "/tmp/${INSTALL_FILE}" "${NODEJS_VER}"
|
||||
fi
|
||||
|
||||
sudo chown -R $(whoami) $node_install_path/lib/node_modules
|
||||
|
||||
echo ""
|
||||
|
||||
if [ -z "$dont_install_deps" ]; then
|
||||
|
||||
################
|
||||
# DEPENDENCIES #
|
||||
|
@ -225,64 +312,6 @@ fi
|
|||
|
||||
bash "/tmp/${INSTALL_DEPS_FILE}" "${NO_FAIL2BAN}"
|
||||
|
||||
#########################
|
||||
# Which node.js VERSION ? #
|
||||
#########################
|
||||
|
||||
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)
|
||||
fi
|
||||
|
||||
if [ -n "$NODEJS_VER" ]; then
|
||||
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
|
||||
|
||||
if [ -z "$NODEJS_VER" ]; then
|
||||
if [ -n "$(which curl)" ]; then
|
||||
NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -2 | tail -1 | cut -f 1) \
|
||||
|| echo "error automatically determining current ${NODEJS_NAME} version"
|
||||
elif [ -n "$(which wget)" ]; then
|
||||
NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -2 | tail -1 | cut -f 1) \
|
||||
|| echo "error automatically determining current ${NODEJS_NAME} version"
|
||||
else
|
||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# node
|
||||
#
|
||||
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
|
||||
else
|
||||
echo ""
|
||||
echo "HEY, LISTEN:"
|
||||
echo ""
|
||||
echo "node.js is already installed as node $(node -v | grep v)"
|
||||
echo ""
|
||||
echo "to reinstall please first run: rm $(which node)"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
NODEJS_VER=""
|
||||
fi
|
||||
|
||||
if [ -n "${NODEJS_VER}" ]; then
|
||||
bash "/tmp/${INSTALL_FILE}" "${NODEJS_VER}"
|
||||
fi
|
||||
|
||||
# yarn
|
||||
if [ -z "$(type -p yarn)" ]; then
|
||||
echo "installing yarn..."
|
||||
|
@ -296,3 +325,4 @@ if [ -z "$(type -p jshint)" ]; then
|
|||
fi
|
||||
|
||||
echo ""
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue