From e436cdb64d7d7b338c8f20293d3258c20740705b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 24 May 2018 21:07:04 +0000 Subject: [PATCH 01/14] allow use of partial version number i.e. v10 or v10.2 --- install.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 6a47387..ccc6801 100644 --- a/install.sh +++ b/install.sh @@ -245,12 +245,20 @@ if [ -n "${NODEJS_VER:-}" ]; then fi fi -if [ -z "${NODEJS_VER:-}" ]; then +NODEJS_VER="${NODEJS_VER:v}" # Search for 'v' at the least +# sort -rV # will sort by version number, but it appears these are already sorted +# tail +2 # starts at line two (1-indexed) and all after (omits the csv header with 'version' and such) +# cut -f 1 # gets only the first column +# head -n 1 # gets only the most recent version +my_char="." +my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}") +# get the latest version if partial +if [ $my_count -ne 2 ]; then if [ -n "$(type -p curl)" ]; then - NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | head -n 2 | tail -1 | cut -f 1) \ + NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ || echo 'error automatically determining current node.js version' elif [ -n "$(type -p wget)" ]; then - NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | head -n 2 | tail -1 | cut -f 1) \ + NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ || echo 'error automatically determining current node.js version' else echo "Found neither 'curl' nor 'wget'. Can't Continue." From 17c0b01ee06c0551d85a21bbb30bcee9638dd905 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 24 May 2018 21:08:12 +0000 Subject: [PATCH 02/14] unset far typo fix --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index ccc6801..12c1759 100644 --- a/install.sh +++ b/install.sh @@ -245,7 +245,7 @@ if [ -n "${NODEJS_VER:-}" ]; then fi fi -NODEJS_VER="${NODEJS_VER:v}" # Search for 'v' at the least +NODEJS_VER="${NODEJS_VER:-v}" # Search for 'v' at the least # sort -rV # will sort by version number, but it appears these are already sorted # tail +2 # starts at line two (1-indexed) and all after (omits the csv header with 'version' and such) # cut -f 1 # gets only the first column From 2d628014d05b4e57d1e2c221e9aa7dff7c94f527 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 24 May 2018 21:09:02 +0000 Subject: [PATCH 03/14] tail typo fix --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 12c1759..fb05d92 100644 --- a/install.sh +++ b/install.sh @@ -247,7 +247,7 @@ fi NODEJS_VER="${NODEJS_VER:-v}" # Search for 'v' at the least # sort -rV # will sort by version number, but it appears these are already sorted -# tail +2 # starts at line two (1-indexed) and all after (omits the csv header with 'version' and such) +# tail -n +2 # starts at line two (1-indexed) and all after (omits the csv header with 'version' and such) # cut -f 1 # gets only the first column # head -n 1 # gets only the most recent version my_char="." @@ -255,10 +255,10 @@ my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}") # get the latest version if partial if [ $my_count -ne 2 ]; then if [ -n "$(type -p curl)" ]; then - NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ + NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ || echo 'error automatically determining current node.js version' elif [ -n "$(type -p wget)" ]; then - NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ + NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ || echo 'error automatically determining current node.js version' else echo "Found neither 'curl' nor 'wget'. Can't Continue." From be9344dbea55ad9e954ac25edafb83a4d5918809 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 24 May 2018 21:12:37 +0000 Subject: [PATCH 04/14] match literal '.' for version, not wildcard --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index fb05d92..65a9aaa 100644 --- a/install.sh +++ b/install.sh @@ -255,10 +255,10 @@ my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}") # get the latest version if partial if [ $my_count -ne 2 ]; then if [ -n "$(type -p curl)" ]; then - NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ + NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER\." | head -n 1) \ || echo 'error automatically determining current node.js version' elif [ -n "$(type -p wget)" ]; then - NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER." | head -n 1) \ + NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER\." | head -n 1) \ || echo 'error automatically determining current node.js version' else echo "Found neither 'curl' nor 'wget'. Can't Continue." From 0c7d0a7da62790ca297572674577dadf4bb8890c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 24 May 2018 21:13:55 +0000 Subject: [PATCH 05/14] note desired version number when already installed --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 65a9aaa..f235228 100644 --- a/install.sh +++ b/install.sh @@ -292,7 +292,7 @@ if [ -e "$node_install_path/bin/node" ]; then echo "" echo "node.js is already installed as node $($node_install_path/bin/node -v | grep v)" echo "" - echo "to reinstall please first run: rm $node_install_path/bin/node" + echo "to reinstall as ${NODEJS_VER} please first run: rm $node_install_path/bin/node" echo "" fi From 748c51a687a1ec4b9462b2aa6e481509c0813231 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 24 May 2018 21:31:04 +0000 Subject: [PATCH 06/14] show selecting version in docs --- README.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 35325bb..fd3e175 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,33 @@ wget -nv https://bit.ly/node-installer -O - ./node-installer.sh; bash ./node-ins ### Choosing a specific version ```bash -echo "Current node.js version is $(curl -fsSL https://nodejs.org/dist/index.tab | head -2 | tail -1 | cut -f 1)" +NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | head -1 ) +echo "The current node.js version is $NODEJS_VER" ``` ```bash -# To install a specific version rather than defaulting to latest -# latest version at time of writing are v8.11.1 and v10.1.0 -export NODEJS_VER="v10.1.0" +BASE_VER="v10\\." +NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | grep $BASE_VER | head -1 ) +echo "Latest node.js $BASE_VER is $NODEJS_VER" +``` + +To install the latest of a specific version rather than defaulting to latest + +```bash +### latest version +export NODEJS_VER="" + +# exact version +export NODEJS_VER="v10.2.1" + +# latest of v8.1.x +export NODEJS_VER="v8.1" + +# latest of v8.11.x +export NODEJS_VER="v8.11" + +# latest of v10.x +export NODEJS_VER="v10" ``` ### Choosing an install location @@ -101,7 +121,7 @@ wget -nv https://bit.ly/node-installer -O /tmp/node-installer.sh; bash /tmp/node ### Other things you should know -This is what gets installed: +This is what gets installed with the dev dependencies: * rsync * curl From 82e6ace060808968c5793b708bc05c90003503b8 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 24 May 2018 21:34:44 +0000 Subject: [PATCH 07/14] make docs more readable --- README.md | 59 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fd3e175..b2b7671 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,39 @@ wget -nv https://bit.ly/node-installer -O - ./node-installer.sh; bash ./node-ins ### Choosing a specific version +**Latest** + +```bash +export NODEJS_VER="" +``` + +**Exact** + +```bash +export NODEJS_VER="v10.2.1" +``` + +**Latest of vX.Y.Z** + +```bash +export NODEJS_VER="v8.1" +``` + +**Latest of vX.YY.Z** + +```bash +# latest of v8.11.x +export NODEJS_VER="v8.11" +``` + +**Latest of vX.Y** + +```bash +export NODEJS_VER="v10" +``` + +Fun FYI, here's how the latest version is determined: + ```bash NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f 1 | head -1 ) echo "The current node.js version is $NODEJS_VER" @@ -46,25 +79,6 @@ NODEJS_VER=$(curl -fsSL https://nodejs.org/dist/index.tab | tail -n +2 | cut -f echo "Latest node.js $BASE_VER is $NODEJS_VER" ``` -To install the latest of a specific version rather than defaulting to latest - -```bash -### latest version -export NODEJS_VER="" - -# exact version -export NODEJS_VER="v10.2.1" - -# latest of v8.1.x -export NODEJS_VER="v8.1" - -# latest of v8.11.x -export NODEJS_VER="v8.11" - -# latest of v10.x -export NODEJS_VER="v10" -``` - ### Choosing an install location Just set BOTH `NODE_PATH` and `NPM_CONFIG_PREFIX`. @@ -74,10 +88,15 @@ The install path will be the preceding `lib/node_modules` ```bash export NPM_CONFIG_PREFIX=/tmp/user/local export NODE_PATH=/tmp/user/local/lib/node_modules +``` +```bash curl -fsSL https://bit.ly/node-installer -o ./node-installer.sh; bash ./node-installer.sh --dev-deps +``` -# If you want to add the install location to your PATH +If you want to add the install location to your `PATH`: + +```bash PATH=$PATH:/tmp/user/local/bin ``` From 62bc523d03cebf285c45d3adbf232e13f85f2d45 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 5 Jun 2018 07:36:21 +0000 Subject: [PATCH 08/14] fix #1 typo / misspelling of PREFIX PREFIX not PREFIIX as per #1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2b7671..083b478 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ echo "Latest node.js $BASE_VER is $NODEJS_VER" Just set BOTH `NODE_PATH` and `NPM_CONFIG_PREFIX`. The install path will be the preceding `lib/node_modules` -(which you usually want to be the same as `NPM_CONFIG_PREFIIX` anyway). +(which you usually want to be the same as `NPM_CONFIG_PREFIX` anyway). ```bash export NPM_CONFIG_PREFIX=/tmp/user/local From c747edb99aaef7505dbf9704303bcdb9360eacd1 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 14 Jun 2018 21:10:05 +0000 Subject: [PATCH 09/14] update installer examples --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 083b478..e14c0fa 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,17 @@ The install path will be the preceding `lib/node_modules` (which you usually want to be the same as `NPM_CONFIG_PREFIX` anyway). ```bash -export NPM_CONFIG_PREFIX=/tmp/user/local -export NODE_PATH=/tmp/user/local/lib/node_modules +export NPM_CONFIG_PREFIX=/tmp/usr/local +export NODE_PATH=/tmp/usr/local/lib/node_modules ``` +A more realistic example for a self-contained node app: +```bash +export NPM_CONFIG_PREFIX=/opt/my-app +export NODE_PATH=/opt/my-app/lib/node_modules +``` + + ```bash curl -fsSL https://bit.ly/node-installer -o ./node-installer.sh; bash ./node-installer.sh --dev-deps ``` From 97c7ef97930a9917732dfbd454bc378c77546760 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 18 Jun 2018 21:40:42 +0000 Subject: [PATCH 10/14] make sure directory exists before chowning it --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index f235228..55c087d 100644 --- a/install.sh +++ b/install.sh @@ -303,6 +303,7 @@ if [ -n "${NODEJS_VER}" ]; then bash "/tmp/${INSTALL_FILE}" "${NODEJS_VER}" fi +$sudo_cmd mkdir -p $node_install_path/lib/node_modules $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules echo "" From 00c986e483784c984f8ba0cd0f500551f31bdb29 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 20 Jun 2018 02:06:38 +0000 Subject: [PATCH 11/14] regression fix: allow empty NODEJS_VER --- install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 55c087d..ffdcfe5 100644 --- a/install.sh +++ b/install.sh @@ -254,11 +254,14 @@ my_char="." my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}") # get the latest version if partial if [ $my_count -ne 2 ]; then + if [ "$my_count" -ne "v" ]; then + NODEJS_VER="$NODEJS_VER\\." + fi if [ -n "$(type -p curl)" ]; then - NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER\." | head -n 1) \ + NODEJS_VER=$(curl -fsL "$NODEJS_BASE_URL/dist/index.tab" | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER" | head -n 1) \ || echo 'error automatically determining current node.js version' elif [ -n "$(type -p wget)" ]; then - NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER\." | head -n 1) \ + NODEJS_VER=$(wget --quiet "$NODEJS_BASE_URL/dist/index.tab" -O - | tail -n +2 | cut -f 1 | grep "^$NODEJS_VER" | head -n 1) \ || echo 'error automatically determining current node.js version' else echo "Found neither 'curl' nor 'wget'. Can't Continue." From 3ced314799a2c5e69f5dd7140334d061accccfb7 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 20 Jun 2018 02:07:43 +0000 Subject: [PATCH 12/14] fix comparison --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index ffdcfe5..bf1c187 100644 --- a/install.sh +++ b/install.sh @@ -254,7 +254,7 @@ my_char="." my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}") # get the latest version if partial if [ $my_count -ne 2 ]; then - if [ "$my_count" -ne "v" ]; then + if [ "$my_count" != "v" ]; then NODEJS_VER="$NODEJS_VER\\." fi if [ -n "$(type -p curl)" ]; then From 0171162f203b67038e10453b4eff885d83d2b65e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 20 Jun 2018 02:11:24 +0000 Subject: [PATCH 13/14] typo fix --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index bf1c187..87da1ac 100644 --- a/install.sh +++ b/install.sh @@ -254,7 +254,7 @@ my_char="." my_count=$(awk -F"${my_char}" '{print NF-1}' <<< "${NODEJS_VER}") # get the latest version if partial if [ $my_count -ne 2 ]; then - if [ "$my_count" != "v" ]; then + if [ "$NODEJS_VER" != "v" ]; then NODEJS_VER="$NODEJS_VER\\." fi if [ -n "$(type -p curl)" ]; then From 5f231f9d22067f7bac1d603c8425ffafb4deaa42 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 23 Jun 2018 05:16:13 +0000 Subject: [PATCH 14/14] set ANDROID_ROOT empty --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 87da1ac..a6638c2 100644 --- a/install.sh +++ b/install.sh @@ -14,7 +14,7 @@ # Not every platform has or needs sudo, gotta save them O(1)s... sudo_cmd="" -((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo" +((EUID)) && [[ -z "${ANDROID_ROOT:-}" ]] && sudo_cmd="sudo" deps_flag="$1" set -e