Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
proc
/
212
/
root
/
srv
/
admin
/
scripts
/
builder
/
nodejs
/
//proc/212/root/srv/admin/scripts/builder/nodejs/install.sh
#!/bin/bash -e export LINK=g++ DISTRIB_RELEASE="$(cat /etc/debian_version)" export DISTRIB_RELEASE=${DISTRIB_RELEASE%.*} custom_jq () { # usage: custom_jq -r .engine.node package.json # Can be dropped as soon as jq is installed everywhere. shift filter="$1" file="$2" if [ -x /usr/bin/jq ]; then jq -r "$filter" "$file" else # Leading dot must be removed from filter node /srv/admin/scripts/nodejs/jq.js "${filter#.}" "$file" fi } install_nodejs () { range=$1 _PREFIX="$PREFIX" # export -n is seemingly not enough unset PREFIX # nvm doesn't like PREFIX (see documentation) set +e # nvm does not like bash -e (see documentation) . /srv/admin/scripts/nodejs/nvm.sh set -e version_to_install="$(nvm ls-remote | xargs semver -r "${range}" | tail -n1)" nvm install "$version_to_install" echo "Using Node.js version ${version_to_install}." export PREFIX="$_PREFIX" } install_npm () { range="$1" node_env="$2" if [ "$range" ]; then npm install --silent npm@"${range}" fi export PATH="$(npm bin):${PATH}" echo "Using npm version $(npm --version)." if [ "$node_env" = "development" ]; then npm install --also=dev else npm install fi } # Legacy build (stretch image and older) if [ "$DISTRIB_RELEASE" -lt 12 ]; then # This script installs NodeJS if needed and does the npm install. # For NodeJS: # - If a version is specified in a .nvmrc, we install it. # - Otherwise, if packages.json specifies a version in engines.node, we install it. # - Otherwise, we use NodeJS version from /opt. export NVM_DIR=/srv/data/home/.nvm export PATH="/opt/nodejs-${WWW_VERSION}/usr/bin:/opt/nodejs-${WWW_VERSION}/usr/lib/node_modules/npm/node_modules/semver/bin:$PATH" if [ -s .nvmrc ]; then install_nodejs "$(tr -dc '0-9.x' <.nvmrc)" else range="" if [ -s package.json ]; then range="$(custom_jq -r ".engines.node" "package.json")" [ "$range" = "null" ] && range="" fi if [ -n "$range" ]; then install_nodejs "$range" else echo "Using Node.js version $(node --version)." fi fi # npm install range="$(custom_jq -r ".engines.npm" "package.json")" [ "$range" = "null" ] && range="" node_env="$(custom_jq -r ".config.NODE_ENV" "package.json")" [ "$node_env" = "null" ] && node_env="" install_npm "$range" "$node_env" else # Remove old cache location rm -rf /srv/data/home/.npm/npm-cache export NPM_CONFIG_CACHE=/srv/data/tmp/npm-cache export NPM_CONFIG_YES=true echo "Using Node.js version $(node --version)." echo "Using npm version $(npm --version)." # Use provided NODE_ENV else read it from package.json # If nothing found defaults to production if [ -z "$NODE_ENV" ] && [ -f package.json ]; then NODE_ENV=$(jq -r '.config.NODE_ENV // "production"' package.json) fi echo "Node Env is $NODE_ENV" if [ "$NODE_ENV" = "development" ]; then npm install --also=dev else npm install --omit=dev fi fi