diff --git a/README.md b/README.md index b19e8d4..48aa15e 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,31 @@ # Node.js Linux Installer This is a universal Node.js installer for Linux. The [original project by taaem](https://github.com/taaem/nodejs-linux-installer) required some fixes to maintain functionality, which are contained in this fork, together with a few enhancements. -[![CodeFactor](https://www.codefactor.io/repository/github/michaing/nodejs-linux-installer/badge)](https://www.codefactor.io/repository/github/michaing/nodejs-linux-installer) - The following architectures are currently supported: - ARMv6 (armv6l) - ARMv7 (armv7l) - ARMv8 (aarch64) - x86 64-bit (x86_64) - x86 32-bit (i386, i486, i586, i686) +- further architectures from [nodejs.org's unofficial builds](unofficial-builds.nodejs.org). **I don't take any responsibilities if you blow your system up!** -### Installing -``` -curl -sSf https://raw.githubusercontent.com/MichaIng/nodejs-linux-installer/master/node-install.sh | bash -``` +### Usage +Please be aware, that installation of node requires root privileges. The script will ask for sudo credentials before installation. + +Get the help text: + + curl -sSf https://raw.githubusercontent.com/ollliegits/nodejs-linux-installer/master/node-install.sh | bash -s -- --help + +Show a list of all unofficial releases for your CPU architecture available from nodejs.org : + + curl -sSf https://raw.githubusercontent.com/ollliegits/nodejs-linux-installer/master/node-install.sh | bash -s -- --list-unofficial-releases + +Install unofficial release of node.js with ``: + + curl -sSf https://raw.githubusercontent.com/ollliegits/nodejs-linux-installer/master/node-install.sh | bash -s -- --unofficial-version + ### Contributing Just create a fork and please contribute all your improvements back here! diff --git a/node-install.sh b/node-install.sh index 2898a8d..d5c9c79 100755 --- a/node-install.sh +++ b/node-install.sh @@ -1,6 +1,47 @@ #!/bin/bash -echo 'Node.js Linux Installer by github.com/taaem, updated by github.com/MichaIng' +show_help() { + cat <] + +Parameters: + -lu + --list-unofficial-releases List all available versions in nodejs.org's unofficial builds. + + -u + --unofficial-version Install from nodejs.org's unofficial builds at + unofficial-builds.nodejs.org/download/release/. E.g. 'v15.5.1'. + +END +} + +list_available() { + curl -l "https://unofficial-builds.nodejs.org/download/release/index.json" 2>>/dev/null | jq -r '.[].version' | sort -Vr +} + + +# getting options +while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in + -h | --help ) + show_help + exit + ;; + -lu | --list-unofficial-releases ) + list_available + exit + ;; + -u | --unofficial-version ) + shift; unofficial_build_version=$1 + [[ -z "$unofficial_build_version" ]] && echo "Specify the version to install when using the --unofficial-build-version flag." && exit 1 + ;; +esac; shift; done +if [[ "$1" == '--' ]]; then shift; fi + if [[ $EUID != 0 ]] then echo 'root permissions required for installing Node.js' @@ -16,9 +57,17 @@ if [[ $EUID != 0 ]] fi ARCH=$(uname -m) -echo "Searching latest stable version for $ARCH ..." -URL='https://nodejs.org/dist/' -if [[ $ARCH == 'aarch64' ]] + +if [[ ! -z "$unofficial_build_version" ]]; then + echo "Searching version $unofficial_build_version for $ARCH ..." + URL="https://unofficial-builds.nodejs.org/download/release/${unofficial_build_version}/" + NAME="node-${unofficial_build_version}-linux-${ARCH}.tar.gz" + curl --output /dev/null --silent --head --fail "${URL}${NAME}" || NAME='' # check if file exists + NAME="\"$NAME" # add double quote sign to mimic logic from original script block below. +else + echo "Searching latest stable version for $ARCH ..." + URL='https://nodejs.org/dist/' + if [[ $ARCH == 'aarch64' ]] then URL+='latest/' NAME=$(curl -sSf "$URL" | grep -o '"node-v[0-9.]*-linux-arm64.tar.gz') @@ -42,6 +91,7 @@ if [[ $ARCH == 'aarch64' ]] then URL+='latest-v9.x/' NAME=$(curl -sSf "$URL" | grep -o '"node-v[0-9.]*-linux-x86.tar.gz') + fi fi VER=${NAME:1} if [[ ! $VER ]]