allow use of partial version number i.e. v10 or v10.2

This commit is contained in:
AJ ONeal 2018-05-24 21:07:04 +00:00
parent a443dd04d3
commit e436cdb64d
1 changed files with 11 additions and 3 deletions

View File

@ -245,12 +245,20 @@ if [ -n "${NODEJS_VER:-}" ]; then
fi fi
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 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' || echo 'error automatically determining current node.js version'
elif [ -n "$(type -p wget)" ]; then 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' || echo 'error automatically determining current node.js version'
else else
echo "Found neither 'curl' nor 'wget'. Can't Continue." echo "Found neither 'curl' nor 'wget'. Can't Continue."