diff --git a/deploy/README.md b/deploy/README.md index b498dfa..bbc4f3f 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -59,7 +59,7 @@ Node 22 security releases; unattended upgrades cover Debian packages only. Build tools support node-pty compilation. Claude uses its native installer. Local deployment regressions: `bash deploy/test/template-picker.test.sh` and -`bash deploy/test/ct-config.test.sh`. Existing CTs with a manual TUN mount entry +`bash deploy/test/ct-config.test.sh`, `bash deploy/test/install-script.test.sh`. Existing CTs with a manual TUN mount entry (earlier Tailscale setups) keep it; no `dev0` is added on top. The scripts require bash, use LF endings, and avoid early-consuming pipelines under pipefail. Proxmox, systemd, Tailscale and SSH require deployment validation. diff --git a/deploy/install.sh b/deploy/install.sh index 226f49c..25751f9 100755 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -euo pipefail [[ $EUID == 0 ]] || { echo 'Run as root inside Debian 13' >&2; exit 1; } +# `pct exec` starts with PATH=/sbin:/bin:/usr/sbin:/usr/bin; Node and pnpm live in /usr/local/bin. +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # shellcheck source=/dev/null source /etc/os-release [[ $ID == debian && $VERSION_ID == 13 ]] || { echo 'Debian 13 required' >&2; exit 1; } @@ -22,7 +24,8 @@ curl -fsSL "https://nodejs.org/dist/latest-v22.x/$node_file" -o "$node_temp/$nod awk -v file="$node_file" '$2 == file' "$node_temp/SHASUMS256.txt" > "$node_temp/checksum" (cd "$node_temp"; sha256sum -c checksum) mkdir "$node_temp/unpacked" -tar -xJf "$node_temp/$node_file" -C "$node_temp/unpacked" --strip-components=1 +# Root-owned: tar as root would keep the archive's uid, and cp -a would carry it into /usr/local. +tar --no-same-owner -xJf "$node_temp/$node_file" -C "$node_temp/unpacked" --strip-components=1 # Replace the executable rather than truncating one a running service uses. install -m 0755 "$node_temp/unpacked/bin/node" /usr/local/bin/node rm "$node_temp/unpacked/bin/node" diff --git a/deploy/test/install-script.test.sh b/deploy/test/install-script.test.sh new file mode 100755 index 0000000..d6e28df --- /dev/null +++ b/deploy/test/install-script.test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail +# Static guards for regressions seen on a real Proxmox deploy (full run needs Debian 13 as root). +dir="$(dirname "${BASH_SOURCE[0]}")/.." +path_line='export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' +for script in install.sh update.sh; do + # pct exec omits /usr/local/bin: PATH must be set before the first command that needs node/pnpm. + first_path=$(grep -nxF "$path_line" "$dir/$script" | head -n1 | cut -d: -f1) + first_use=$(grep -nE '\b(node|pnpm|npm|corepack)\b' "$dir/$script" | grep -v '^[0-9]*:#' | head -n1 | cut -d: -f1) + [[ -n $first_path && $first_path -lt $first_use ]] || { echo "$script: PATH not set before node/pnpm use" >&2; exit 1; } +done +# Node tarball must not hand /usr/local to the archive's uid. +grep -qE '^tar --no-same-owner .*node_file' "$dir/install.sh" || { echo 'install.sh: tar keeps archive owners' >&2; exit 1; } +printf '3 install script checks passed\n' diff --git a/deploy/update.sh b/deploy/update.sh index 49f8101..55fa927 100755 --- a/deploy/update.sh +++ b/deploy/update.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -euo pipefail [[ $EUID == 0 ]] || { echo 'Run as root' >&2; exit 1; } +# `pct exec` omits /usr/local/bin, where Node and pnpm live. +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin runuser -u shellbook -- bash -c 'cd /opt/shellbook; git pull --ff-only; pnpm install --frozen-lockfile; pnpm build' systemctl restart shellbook systemctl --no-pager status shellbook