forked from coolaj86/node-installer.sh
install io.js if 1 <= x < 4, otherwise install node.js
This commit is contained in:
parent
701513faa9
commit
d8c75b08f4
|
@ -1,11 +1,25 @@
|
||||||
IOJS_VER=${1}
|
NODEJS_VER=${1}
|
||||||
IOJS_REMOTE="http://iojs.org/dist/${IOJS_VER}/iojs-${IOJS_VER}.pkg"
|
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
|
||||||
IOJS_PKG="/tmp/iojs-${IOJS_VER}.pkg"
|
|
||||||
|
|
||||||
if [ -n "${IOJS_VER}" ]; then
|
NODEJS_NAME="node"
|
||||||
echo "installing io.js as iojs ${IOJS_VER}..."
|
NODEJS_BASE_URL="https://nodejs.org"
|
||||||
curl -fsSL "${IOJS_REMOTE}" -o "${IOJS_PKG}"
|
|
||||||
sudo /usr/sbin/installer -pkg "${IOJS_PKG}" -target /
|
GE1=$(echo "$NODEJS_VERT>=1" | bc)
|
||||||
|
LT4=$(echo "$NODEJS_VERT<4" | bc)
|
||||||
|
|
||||||
|
if [ "1" -eq $GE1 ] && [ "1" -eq $LT4 ]
|
||||||
|
then
|
||||||
|
NODEJS_BASE_URL="https://iojs.org"
|
||||||
|
NODEJS_NAME="iojs"
|
||||||
|
fi
|
||||||
|
|
||||||
|
NODEJS_REMOTE="$NODEJS_BASE_URL/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}.pkg"
|
||||||
|
NODEJS_PKG="/tmp/${NODEJS_NAME}-${NODEJS_VER}.pkg"
|
||||||
|
|
||||||
|
if [ -n "${NODEJS_VER}" ]; then
|
||||||
|
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
|
||||||
|
curl -fsSL "${NODEJS_REMOTE}" -o "${NODEJS_PKG}"
|
||||||
|
sudo /usr/sbin/installer -pkg "${NODEJS_PKG}" -target /
|
||||||
|
|
||||||
sudo chown -R $(whoami) /usr/local 2>/dev/null
|
sudo chown -R $(whoami) /usr/local 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,4 +1,17 @@
|
||||||
IOJS_VER=${1}
|
NODEJS_VER=${1}
|
||||||
|
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
|
||||||
|
|
||||||
|
NODEJS_NAME="node"
|
||||||
|
NODEJS_BASE_URL="https://nodejs.org"
|
||||||
|
|
||||||
|
GE1=$(echo "$NODEJS_VERT>=1" | bc)
|
||||||
|
LT4=$(echo "$NODEJS_VERT<4" | bc)
|
||||||
|
|
||||||
|
if [ "1" -eq $GE1 ] && [ "1" -eq $LT4 ]
|
||||||
|
then
|
||||||
|
NODEJS_BASE_URL="https://iojs.org"
|
||||||
|
NODEJS_NAME="iojs"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$(arch | grep 64)" ]; then
|
if [ -n "$(arch | grep 64)" ]; then
|
||||||
ARCH="x64"
|
ARCH="x64"
|
||||||
|
@ -10,26 +23,26 @@ else
|
||||||
ARCH="x86"
|
ARCH="x86"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IOJS_REMOTE="http://iojs.org/dist/${IOJS_VER}/iojs-${IOJS_VER}-linux-${ARCH}.tar.gz"
|
NODEJS_REMOTE="${NODEJS_BASE_URL}/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
|
||||||
IOJS_LOCAL="/tmp/iojs-${IOJS_VER}-linux-${ARCH}.tar.gz"
|
NODEJS_LOCAL="/tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
|
||||||
IOJS_UNTAR="/tmp/iojs-${IOJS_VER}-linux-${ARCH}"
|
NODEJS_UNTAR="/tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}"
|
||||||
|
|
||||||
if [ -n "${IOJS_VER}" ]; then
|
if [ -n "${NODEJS_VER}" ]; then
|
||||||
echo "installing io.js as iojs ${IOJS_VER}..."
|
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
|
||||||
|
|
||||||
if [ -n "$(which curl 2>/dev/null)" ]; then
|
if [ -n "$(which curl 2>/dev/null)" ]; then
|
||||||
curl -fsSL ${IOJS_REMOTE} -o ${IOJS_LOCAL} || echo 'error downloading io.js'
|
curl -fsSL ${NODEJS_REMOTE} -o ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
||||||
elif [ -n "$(which wget 2>/dev/null)" ]; then
|
elif [ -n "$(which wget 2>/dev/null)" ]; then
|
||||||
wget --quiet ${IOJS_REMOTE} -O ${IOJS_LOCAL} || echo 'error downloading io.js'
|
wget --quiet ${NODEJS_REMOTE} -O ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
|
||||||
else
|
else
|
||||||
echo "'wget' and 'curl' are missing. Please run the following command and try again"
|
echo "'wget' and 'curl' are missing. Please run the following command and try again"
|
||||||
echo "\tsudo apt-get install --yes curl wget"
|
echo "\tsudo apt-get install --yes curl wget"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tar xf ${IOJS_LOCAL} -C /tmp/
|
tar xf ${NODEJS_LOCAL} -C /tmp/
|
||||||
rm ${IOJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
|
rm ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
|
||||||
sudo rsync -a "${IOJS_UNTAR}/" /usr/local/
|
sudo rsync -a "${NODEJS_UNTAR}/" /usr/local/
|
||||||
|
|
||||||
|
|
||||||
sudo chown -R $(whoami) /usr/local
|
sudo chown -R $(whoami) /usr/local
|
||||||
|
|
39
setup-min.sh
39
setup-min.sh
|
@ -12,10 +12,12 @@
|
||||||
# curl -fsSL https://example.com/setup-min.bash | bash
|
# curl -fsSL https://example.com/setup-min.bash | bash
|
||||||
# wget -nv https://example.com/setup-min.bash -O - | bash
|
# wget -nv https://example.com/setup-min.bash -O - | bash
|
||||||
|
|
||||||
|
NODEJS_NAME="node"
|
||||||
|
NODEJS_BASE_URL="https://nodejs.org"
|
||||||
BASE_URL="https://raw.githubusercontent.com/coolaj86/iojs-install-script/master"
|
BASE_URL="https://raw.githubusercontent.com/coolaj86/iojs-install-script/master"
|
||||||
OS="unsupported"
|
OS="unsupported"
|
||||||
ARCH=""
|
ARCH=""
|
||||||
IOJS_VER=""
|
NODEJS_VER=""
|
||||||
SETUP_FILE=""
|
SETUP_FILE=""
|
||||||
|
|
||||||
clear
|
clear
|
||||||
|
@ -157,16 +159,31 @@ fi
|
||||||
# Which io.js VERSION ? #
|
# Which io.js VERSION ? #
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
if [ -f "/tmp/IOJS_VER" ]; then
|
if [ -f "/tmp/NODEJS_VER" ]; then
|
||||||
IOJS_VER=$(cat /tmp/IOJS_VER | grep v)
|
NODEJS_VER=$(cat /tmp/NODEJS_VER | grep v)
|
||||||
|
elif [ -f "/tmp/IOJS_VER" ]; then
|
||||||
|
NODEJS_VER=$(cat /tmp/IOJS_VER | grep v)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$IOJS_VER" ]; then
|
if [ -n "$NODEJS_VER" ]; then
|
||||||
|
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
|
||||||
|
|
||||||
|
GE1=$(echo "$NODEJS_VERT>=1" | bc)
|
||||||
|
LT4=$(echo "$NODEJS_VERT<4" | bc)
|
||||||
|
|
||||||
|
if [ "1" -eq $GE1 ] && [ "1" -eq $LT4 ]
|
||||||
|
then
|
||||||
|
NODEJS_BASE_URL="https://iojs.org"
|
||||||
|
NODEJS_NAME="iojs"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$NODEJS_VER" ]; then
|
||||||
if [ -n "$(which curl)" ]; then
|
if [ -n "$(which curl)" ]; then
|
||||||
IOJS_VER="$(curl -fsSL https://iojs.org/dist/index.tab | head -2 | tail -1 | cut -f 1)" \
|
NODEJS_VER="$(curl -fsSL "$NODEJS_BASE_URL/dist/index.tab" | head -2 | tail -1 | cut -f 1)" \
|
||||||
|| echo 'error automatically determining current io.js version'
|
|| echo 'error automatically determining current io.js version'
|
||||||
elif [ -n "$(which wget)" ]; then
|
elif [ -n "$(which wget)" ]; then
|
||||||
IOJS_VER="wget --quiet https://iojs.org/dist/index.tab -O - | head -2 | tail -1 | cut -f 1)" \
|
NODEJS_VER="wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -2 | tail -1 | cut -f 1)" \
|
||||||
|| echo 'error automatically determining current io.js version'
|
|| echo 'error automatically determining current io.js version'
|
||||||
else
|
else
|
||||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||||
|
@ -179,8 +196,8 @@ fi
|
||||||
#
|
#
|
||||||
if [ -n "$(which iojs | grep iojs 2>/dev/null)" ]; then
|
if [ -n "$(which iojs | grep iojs 2>/dev/null)" ]; then
|
||||||
# iojs of some version is already installed
|
# iojs of some version is already installed
|
||||||
if [ "${IOJS_VER}" == "$(iojs -v 2>/dev/null)" ]; then
|
if [ "${NODEJS_VER}" == "$(iojs -v 2>/dev/null)" ]; then
|
||||||
echo iojs ${IOJS_VER} is already installed
|
echo iojs ${NODEJS_VER} is already installed
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
echo "HEY, LISTEN:"
|
echo "HEY, LISTEN:"
|
||||||
|
@ -190,7 +207,7 @@ if [ -n "$(which iojs | grep iojs 2>/dev/null)" ]; then
|
||||||
echo "to reinstall please first run: rm $(which iojs)"
|
echo "to reinstall please first run: rm $(which iojs)"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
IOJS_VER=""
|
NODEJS_VER=""
|
||||||
elif [ "$(node -v 2>/dev/null)" != "$(iojs -v 2>/dev/null)" ]; then
|
elif [ "$(node -v 2>/dev/null)" != "$(iojs -v 2>/dev/null)" ]; then
|
||||||
# node of some version is already installed
|
# node of some version is already installed
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -211,8 +228,8 @@ elif [ "$(node -v 2>/dev/null)" != "$(iojs -v 2>/dev/null)" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${IOJS_VER}" ]; then
|
if [ -n "${NODEJS_VER}" ]; then
|
||||||
bash /tmp/install-iojs.bash "${IOJS_VER}"
|
bash /tmp/install-iojs.bash "${NODEJS_VER}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
63
setup.bash
63
setup.bash
|
@ -9,13 +9,13 @@
|
||||||
# curl -fsSL https://example.com/setup.bash | bash
|
# curl -fsSL https://example.com/setup.bash | bash
|
||||||
# wget -nv https://example.com/setup.bash -O - | bash
|
# wget -nv https://example.com/setup.bash -O - | bash
|
||||||
|
|
||||||
NODEJS_BASE_URL="https://iojs.org"
|
NODEJS_NAME="node"
|
||||||
#NODEJS_BASE_URL="https://nodejs.org"
|
NODEJS_BASE_URL="https://nodejs.org"
|
||||||
BASE_URL="https://raw.githubusercontent.com/coolaj86/iojs-install-script/master"
|
BASE_URL="https://raw.githubusercontent.com/coolaj86/iojs-install-script/master"
|
||||||
NO_FAIL2BAN=""
|
NO_FAIL2BAN=""
|
||||||
OS="unsupported"
|
OS="unsupported"
|
||||||
ARCH=""
|
ARCH=""
|
||||||
IOJS_VER=""
|
NODEJS_VER=""
|
||||||
SETUP_FILE=""
|
SETUP_FILE=""
|
||||||
|
|
||||||
clear
|
clear
|
||||||
|
@ -145,18 +145,18 @@ esac
|
||||||
# Download installers #
|
# Download installers #
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
echo "Preparing to install io.js (and common development dependencies) for ${OS}" "${ARCH}"
|
echo "Preparing to install ${NODEJS_NAME} (and common development dependencies) for ${OS}" "${ARCH}"
|
||||||
|
|
||||||
if [ -n "$(which curl)" ]; then
|
if [ -n "$(which curl)" ]; then
|
||||||
curl --silent "${BASE_URL}/setup-deps-${SETUP_FILE}.bash" \
|
curl --silent "${BASE_URL}/setup-deps-${SETUP_FILE}.bash" \
|
||||||
-o /tmp/install-iojs-deps.bash || echo 'error downloading os setup script'
|
-o /tmp/install-${NODEJS_NAME}-deps.bash || echo 'error downloading os setup script'
|
||||||
curl --silent "${BASE_URL}/setup-iojs-${SETUP_FILE}.bash" \
|
curl --silent "${BASE_URL}/setup-iojs-${SETUP_FILE}.bash" \
|
||||||
-o /tmp/install-iojs.bash || echo 'error downloading os setup script'
|
-o /tmp/install-${NODEJS_NAME}.bash || echo 'error downloading os setup script'
|
||||||
elif [ -n "$(which wget)" ]; then
|
elif [ -n "$(which wget)" ]; then
|
||||||
wget --quiet "${BASE_URL}/setup-deps-${SETUP_FILE}.bash" \
|
wget --quiet "${BASE_URL}/setup-deps-${SETUP_FILE}.bash" \
|
||||||
-O /tmp/install-iojs-deps.bash || echo 'error downloading os setup script'
|
-O /tmp/install-${NODEJS_NAME}-deps.bash || echo 'error downloading os setup script'
|
||||||
wget --quiet "${BASE_URL}/setup-iojs-${SETUP_FILE}.bash" \
|
wget --quiet "${BASE_URL}/setup-iojs-${SETUP_FILE}.bash" \
|
||||||
-O /tmp/install-iojs.bash || echo 'error downloading os setup script'
|
-O /tmp/install-${NODEJS_NAME}.bash || echo 'error downloading os setup script'
|
||||||
else
|
else
|
||||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -203,23 +203,39 @@ if [ -z "$(which fail2ban-server | grep fail2ban)" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bash /tmp/install-iojs-deps.bash "${NO_FAIL2BAN}"
|
bash /tmp/install-${NODEJS_NAME}-deps.bash "${NO_FAIL2BAN}"
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# Which io.js VERSION ? #
|
# Which node.js VERSION ? #
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
if [ -f "/tmp/IOJS_VER" ]; then
|
if [ -f "/tmp/NODEJS_VER" ]; then
|
||||||
IOJS_VER=$(cat /tmp/IOJS_VER | grep v)
|
NODEJS_VER=$(cat /tmp/NODEJS_VER | grep v)
|
||||||
|
elif [ -f "/tmp/IOJS_VER" ]; then
|
||||||
|
NODEJS_VER=$(cat /tmp/IOJS_VER | grep v)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$IOJS_VER" ]; then
|
if [ -n "$NODEJS_VER" ]; then
|
||||||
|
NODEJS_VERT=$(echo ${NODEJS_VER} | cut -c 2- | cut -d '.' -f1)
|
||||||
|
|
||||||
|
GE1=$(echo "$NODEJS_VERT>=1" | bc)
|
||||||
|
LT4=$(echo "$NODEJS_VERT<4" | bc)
|
||||||
|
|
||||||
|
if [ "1" -eq $GE1 ] && [ "1" -eq $LT4 ]
|
||||||
|
then
|
||||||
|
echo "Selecting io.js instead of node.js for this version"
|
||||||
|
NODEJS_BASE_URL="https://iojs.org"
|
||||||
|
NODEJS_NAME="iojs"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$NODEJS_VER" ]; then
|
||||||
if [ -n "$(which curl)" ]; then
|
if [ -n "$(which curl)" ]; then
|
||||||
IOJS_VER="$(curl -fsSL "$NODEJS_BASE_URL/dist/index.tab" | head -2 | tail -1 | cut -f 1)" \
|
NODEJS_VER="$(curl -fsSL "$NODEJS_BASE_URL/dist/index.tab" | head -2 | tail -1 | cut -f 1)" \
|
||||||
|| echo 'error automatically determining current io.js version'
|
|| echo 'error automatically determining current ${NODEJS_NAME} version'
|
||||||
elif [ -n "$(which wget)" ]; then
|
elif [ -n "$(which wget)" ]; then
|
||||||
IOJS_VER="wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -2 | tail -1 | cut -f 1)" \
|
NODEJS_VER="wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -2 | tail -1 | cut -f 1)" \
|
||||||
|| echo 'error automatically determining current io.js version'
|
|| echo 'error automatically determining current ${NODEJS_NAME} version'
|
||||||
else
|
else
|
||||||
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
echo "Found neither 'curl' nor 'wget'. Can't Continue."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -231,18 +247,18 @@ fi
|
||||||
#
|
#
|
||||||
if [ -n "$(which iojs | grep iojs 2>/dev/null)" ]; then
|
if [ -n "$(which iojs | grep iojs 2>/dev/null)" ]; then
|
||||||
# iojs of some version is already installed
|
# iojs of some version is already installed
|
||||||
if [ "${IOJS_VER}" == "$(iojs -v 2>/dev/null)" ]; then
|
if [ "${NODEJS_VER}" == "$(iojs -v 2>/dev/null)" ]; then
|
||||||
echo iojs ${IOJS_VER} is already installed
|
echo iojs ${NODEJS_VER} is already installed
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
echo "HEY, LISTEN:"
|
echo "HEY, LISTEN:"
|
||||||
echo ""
|
echo ""
|
||||||
echo "io.js is already installed as iojs $(iojs -v | grep v)"
|
echo "${NODEJS_NAME} is already installed as iojs $(iojs -v | grep v)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "to reinstall please first run: rm $(which iojs)"
|
echo "to reinstall please first run: rm $(which iojs)"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
IOJS_VER=""
|
NODEJS_VER=""
|
||||||
elif [ "$(node -v 2>/dev/null)" != "$(iojs -v 2>/dev/null)" ]; then
|
elif [ "$(node -v 2>/dev/null)" != "$(iojs -v 2>/dev/null)" ]; then
|
||||||
# node of some version is already installed
|
# node of some version is already installed
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -250,7 +266,6 @@ elif [ "$(node -v 2>/dev/null)" != "$(iojs -v 2>/dev/null)" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "You have node.js installed."
|
echo "You have node.js installed."
|
||||||
echo "Backing up $(which node) as $(which node).$(node -v)"
|
echo "Backing up $(which node) as $(which node).$(node -v)"
|
||||||
echo "(copy it back after the install to maintain node.js and io.js separately)"
|
|
||||||
echo ""
|
echo ""
|
||||||
sleep 3
|
sleep 3
|
||||||
NODE_PATH=$(which node)
|
NODE_PATH=$(which node)
|
||||||
|
@ -263,8 +278,8 @@ elif [ "$(node -v 2>/dev/null)" != "$(iojs -v 2>/dev/null)" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${IOJS_VER}" ]; then
|
if [ -n "${NODEJS_VER}" ]; then
|
||||||
bash /tmp/install-iojs.bash "${IOJS_VER}"
|
bash /tmp/install-${NODEJS_NAME}.bash "${NODEJS_VER}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# jshint
|
# jshint
|
||||||
|
|
Loading…
Reference in New Issue