Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Automatically installs and configures node.js.
#!/usr/bin/env bash
##
# Description:
#
# Automatically installs and configures node.js.
#
if ! [[ "$(id -u)" = '0' ]] ; then
echo "\"$0\" must be run as root" 1>&2
exit 1
fi
set -x
set -o errexit
set -o pipefail
set -o nounset
INSTALLATION_PREFIX="${INSTALLATION_PREFIX:-/usr}"
DOWNLOAD_URL='https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.gz'
SHA256_HASH='0e49da19cdf4c89b52656e858346775af21f1953c308efbc803b665d6069c15c'
FILENAME="$(echo "${DOWNLOAD_URL}" | sed 's/.*\///')"
DIRNAME="$(echo "${FILENAME}" | sed 's/\.tar\.gz$//')"
cd "$(dirname "$0")"
test -f "${FILENAME}" || curl --silent --show-error --location --output "${FILENAME}" "${DOWNLOAD_URL}"
echo "${SHA256_HASH} ${FILENAME}" | sha256sum --check -
tar -C "${INSTALLATION_PREFIX}" -xzf "${FILENAME}"
test ! -l ${INSTALLATION_PREFIX}/node || unlink ${INSTALLATION_PREFIX}/node
ln -s "${INSTALLATION_PREFIX}/${DIRNAME}" ${INSTALLATION_PREFIX}/node
for bin in "${INSTALLATION_PREFIX}/node/bin/"*; do
name="$(echo "${bin}" | sed 's/^.*\///')"
test ! -h "${INSTALLATION_PREFIX}/bin/${name}" || unlink "${INSTALLATION_PREFIX}/bin/${name}"
ln -s "${bin}" "${INSTALLATION_PREFIX}/bin/${name}"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment