Files
vpndock/vpn-node/sudo-wrapper.sh
Malin 91674ea056 fix: env -u PKG_EXECPATH in sudo wrapper + pre-install components at build
PKG_EXECPATH inherited from parent caused pkg bootstrap to treat argv[1] as
a module path. Fix: env -u unsets only PKG_EXECPATH so bootstrap starts fresh
while all auth/session vars are preserved. Depth guard prevents loops.

Also pre-run component installation during Docker build so the sudo code path
is never hit at runtime.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 18:02:18 +01:00

21 lines
702 B
Bash

#!/bin/bash
# Strip PKG_EXECPATH so the child's pkg bootstrap starts fresh.
# When PKG_EXECPATH is inherited, bootstrap treats argv[1] as a module path
# causing "Cannot find module '/--connect'" or '/--install-missing-components'.
# env -u unsets only PKG_EXECPATH; all auth/config/session vars are kept.
# Depth guard prevents infinite recursion.
DEPTH="${PUREVPN_SUDO_DEPTH:-0}"
if [[ "$DEPTH" -ge 2 ]]; then
echo "[sudo-wrapper] depth $DEPTH — exiting 0" >&2
exit 0
fi
args=()
for a in "$@"; do
case "$a" in -E|-n|-H) ;; *) args+=("$a") ;; esac
done
echo "[sudo-wrapper] depth=$(( DEPTH+1 )): ${args[*]}" >&2
exec env -u PKG_EXECPATH PUREVPN_SUDO_DEPTH=$(( DEPTH+1 )) "${args[@]}"