From 4294dcb88bb60cefae347cc76f010d8588e4591a Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 29 Apr 2026 14:13:28 +0200 Subject: [PATCH] Enhance deploy script: Add functions to ensure required commands (node, npm, git) are available in the PATH, improving reliability in non-interactive SSH sessions. This includes bootstrapping Node.js environment using nvm if necessary. --- deploy.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/deploy.sh b/deploy.sh index 83ddfd7..958ab1c 100755 --- a/deploy.sh +++ b/deploy.sh @@ -9,6 +9,28 @@ NC="\033[0m" log() { echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $*${NC}"; } err() { echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] $*${NC}" 1>&2; } +ensure_command() { + local cmd="$1" + command -v "$cmd" >/dev/null 2>&1 +} + +bootstrap_node() { + # In non-interactive SSH sessions, node/npm might not be on PATH (e.g. nvm in .bashrc). + if ensure_command npm && ensure_command node; then + return 0 + fi + if [ -s "$HOME/.nvm/nvm.sh" ]; then + # shellcheck disable=SC1090 + . "$HOME/.nvm/nvm.sh" + # Prefer default alias if configured, otherwise keep current. + nvm use --silent default >/dev/null 2>&1 || true + fi +} + +bootstrap_node +if ! ensure_command git; then err "git not found in PATH"; exit 127; fi +if ! ensure_command npm; then err "npm not found in PATH"; exit 127; fi + log "Fetching latest changes..." git fetch --all --prune || { err "git fetch failed"; exit 1; }