aboutsummaryrefslogtreecommitdiff
path: root/src/node/install.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/node/install.sh')
-rwxr-xr-xsrc/node/install.sh42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/node/install.sh b/src/node/install.sh
index 1ce8fee..8091094 100755
--- a/src/node/install.sh
+++ b/src/node/install.sh
@@ -8,7 +8,7 @@
# Maintainer: The Dev Container spec maintainers
export NODE_VERSION="${VERSION:-"lts"}"
-export NVM_VERSION="${NVMVERSION:-"0.39.2"}"
+export NVM_VERSION="${NVMVERSION:-"latest"}"
export NVM_DIR="${NVMINSTALLPATH:-"/usr/local/share/nvm"}"
INSTALL_TOOLS_FOR_NODE_GYP="${NODEGYPDEPENDENCIES:-true}"
@@ -78,6 +78,40 @@ check_packages() {
fi
}
+# Figure out correct version of a three part version number is not passed
+find_version_from_git_tags() {
+ local variable_name=$1
+ local requested_version=${!variable_name}
+ if [ "${requested_version}" = "none" ]; then return; fi
+ local repository=$2
+ local prefix=${3:-"tags/v"}
+ local separator=${4:-"."}
+ local last_part_optional=${5:-"false"}
+ if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
+ local escaped_separator=${separator//./\\.}
+ local last_part
+ if [ "${last_part_optional}" = "true" ]; then
+ last_part="(${escaped_separator}[0-9]+)?"
+ else
+ last_part="${escaped_separator}[0-9]+"
+ fi
+ local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
+ local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
+ if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
+ declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
+ else
+ set +e
+ declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
+ set -e
+ fi
+ fi
+ if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
+ echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
+ exit 1
+ fi
+ echo "${variable_name}=${!variable_name}"
+}
+
# Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive
@@ -92,6 +126,10 @@ fi
# Install dependencies
check_packages apt-transport-https curl ca-certificates tar gnupg2 dirmngr
+if ! type git > /dev/null 2>&1; then
+ check_packages git
+fi
+
# Install yarn
if type yarn > /dev/null 2>&1; then
echo "Yarn already installed."
@@ -112,6 +150,8 @@ elif [ "${NODE_VERSION}" = "latest" ]; then
export NODE_VERSION="node"
fi
+find_version_from_git_tags NVM_VERSION "https://github.com/nvm-sh/nvm"
+
# Install snipppet that we will run as the user
nvm_install_snippet="$(cat << EOF
set -e