#!/bin/bash

OS_UPPERCAPS=`uname -s | tr '[:lower:]' '[:upper:]'`
OS_LOWERCAPS=`uname -s | tr '[:upper:]' '[:lower:]'`

#version=16.13.2
#version=18.18.0
version=24.18.0
installed_dir=node-${OS_LOWERCAPS}-64bit

if [ ! -f node-v${version}-linux-x64.tar.gz ] ; then
    curl --output node-v${version}-linux-x64.tar.gz https://nodejs.org/dist/v${version}/node-v${version}-linux-x64.tar.gz
fi
   
tar xvzf node-v${version}-linux-x64.tar.gz \
    && mv node-v${version}-linux-x64 $installed_dir

if [ $? = 0 ] ; then
    echo ""
    echo "Untarred NodeJS $version and renamed the directory to:"
    echo "    $installed_dir"
fi


os_full_lc=`uname -s | tr '[:upper:]' '[:lower:]'`
os_root=${os_full_lc%%_*}

#if [ "x$os_root" = "xcygwin" ] ; then
#    if [ ! -x $installed_dir/node.exe ] ; then
#	echo "" >&2
#	echo "**** Note ****" >&2
#	echo "Under Cygwin, the programs in the 'bin' directory often lack" >&2
#	echo "execute permissions.  This can be addressed with:" >&2
#	echo "    chmod a+x $installed_dir/*.{exe,bat,cmd} $installed_dir/{npm,npx}" >&2
#    fi
#fi
