diff --git a/deploy/update-test-server.sh b/deploy/update-test-server.sh index 85f0c46..0f5df51 100755 --- a/deploy/update-test-server.sh +++ b/deploy/update-test-server.sh @@ -33,6 +33,30 @@ require_command() fi } +# Cron runs with a bare PATH, so nvm-installed npm (added to PATH only by +# .bashrc sourcing nvm.sh in an interactive shell) is invisible here even +# though it works fine when this script is run by hand. Resolve nvm's +# current npm via bash (nvm.sh is not POSIX sh compatible) and prepend it, +# so a later `nvm use`/`nvm install` doesn't require updating this script +# or the crontab. +ensure_npm_on_path() +{ + command -v npm >/dev/null 2>&1 && return 0 + + nvm_dir=${NVM_DIR:-${HOME:-/root}/.nvm} + [ -s "$nvm_dir/nvm.sh" ] || return 0 + command -v bash >/dev/null 2>&1 || return 0 + + npm_path=$(bash -c ". \"\$1/nvm.sh\" >/dev/null 2>&1 && command -v npm" _ "$nvm_dir" 2>/dev/null) || return 0 + [ -n "$npm_path" ] || return 0 + + PATH=$(dirname -- "$npm_path"):$PATH + export PATH + log "Resolved npm via nvm: $npm_path" +} + +ensure_npm_on_path + git_in() { repository=$1