#!/bin/bash # sudo-wrapper.sh # # purevpn-cli (pkg/Node.js binary) calls: # sudo purevpn-cli --connect --install-missing-components # # The pkg bootstrap uses argv[1] as the main module path when # --install-missing-components is present. With the original call order, # argv[1] = '--connect', so pkg tries require('/--connect') → crash. # # Fix: move --install-missing-components to argv[1] position so pkg sees it # as its own bootstrap flag instead of a module path. # Also strip -E / -n (sudo flags we don't need) and run with a clean env. binary="" has_install_flag=false other_args=() for a in "$@"; do case "$a" in -E|-n|--preserve-env|--non-interactive) continue ;; # sudo flags, ignore --install-missing-components) has_install_flag=true ;; *) if [[ -z "$binary" ]]; then binary="$a" else other_args+=("$a") fi ;; esac done if [[ -z "$binary" ]]; then echo "[sudo-wrapper] no binary supplied" >&2 exit 1 fi if [[ "$has_install_flag" == "true" ]]; then echo "[sudo-wrapper] reorder: $binary --install-missing-components ${other_args[*]}" >&2 exec env -i \ PATH="/opt/purevpn-cli/bin:/opt/purevpn-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ HOME=/root USER=root LOGNAME=root \ "$binary" "--install-missing-components" "${other_args[@]}" else echo "[sudo-wrapper] passthrough: $binary ${other_args[*]}" >&2 exec env -i \ PATH="/opt/purevpn-cli/bin:/opt/purevpn-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ HOME=/root USER=root LOGNAME=root \ "$binary" "${other_args[@]}" fi