#!/bin/bash set -Eeuo pipefail # source environment because Linux is beautiful and not really confusing like Windows # also you are apparently not supposed to source that file because it's not conforming to standard shell envvar # format but we already fix that in base image # yes, this is sarcasm # shellcheck disable=SC1091 . /etc/environment printf "\n\tšŸ‹ Installed NPM šŸ‹\t\n" npm -v versions=("10" "12") JSON=$(wget -qO- https://nodejs.org/download/release/index.json | jq --compact-output) for V in "${versions[@]}"; do printf "\n\tšŸ‹ Installing NODE=%s šŸ‹\t\n" "${V}" VER=$(echo "${JSON}" | jq "[.[] | select(.version|test(\"^v${V}\"))][0].version" -r) NODEPATH="$AGENT_TOOLSDIRECTORY/node/${VER:1}/x64" # disable warning about 'mkdir -m -p' # shellcheck disable=SC2174 mkdir -v -m 0777 -p "$NODEPATH" wget -qO- "https://nodejs.org/download/release/latest-v${V}.x/node-$VER-linux-x64.tar.xz" | tar -Jxf - --strip-components=1 -C "$NODEPATH" ENVVAR="${V//\./_}" echo "${ENVVAR}=${NODEPATH}" >>/etc/environment printf "\n\tšŸ‹ Installed NODE šŸ‹\t\n" "$NODEPATH/bin/node" -v done printf "\n\tšŸ‹ Installing JS tools šŸ‹\t\n" npm install -g npm npm install -g pnpm npm install -g yarn npm install -g grunt gulp n parcel-bundler typescript newman vercel webpack webpack-cli lerna npm install -g --unsafe-perm netlify-cli printf "\n\tšŸ‹ Installed NPM šŸ‹\t\n" npm -v printf "\n\tšŸ‹ Installed PNPM šŸ‹\t\n" pnpm -v printf "\n\tšŸ‹ Installed YARN šŸ‹\t\n" yarn -v printf "\n\tšŸ‹ Installing NVM tools šŸ‹\t\n" VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r '.tag_name') curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION/install.sh" | bash export NVM_DIR=$HOME/.nvm echo "NVM_DIR=$HOME/.nvm" | tee -a /etc/environment # Expressions don't expand in single quotes, use double quotes for that.shellcheck(SC2016) # shellcheck disable=SC2016 echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' | tee -a /etc/skel/.bash_profile # Not following: ./nvm.sh was not specified as input (see shellcheck -x).shellcheck(SC1091) # shellcheck disable=SC1091 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" printf "\n\tšŸ‹ Installed NVM šŸ‹\t\n" nvm --version printf "\n\tšŸ‹ Cleaning image šŸ‹\t\n" apt-get clean rm -rf /var/cache/* /var/log/* /var/lib/apt/lists/* /tmp/* || echo 'Failed to delete directories' printf "\n\tšŸ‹ Cleaned up image šŸ‹\t\n"