deploy-container.sh: fix sudo

The 'echo sudo' approach used previously failed when PATH or
NIX_PATH contains spaces. Exec the script with sudo instead.
This commit is contained in:
Erik Arvstedt 2020-10-18 13:41:56 +02:00
parent c19f7ebb01
commit e6340426c1
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
1 changed files with 6 additions and 2 deletions

View File

@ -20,6 +20,11 @@ if [[ ! -v IN_NIX_SHELL ]]; then
exec nix-shell --run "./${BASH_SOURCE[0]##*/} $*"
fi
if [[ $EUID != 0 ]]; then
# NixOS containers require root permissions
exec sudo "PATH=$PATH" "NIX_PATH=$NIX_PATH" "IN_NIX_SHELL=$IN_NIX_SHELL" "${BASH_SOURCE[0]}" "$@"
fi
# These commands can also be executed interactively in a shell session
demoCmds='
echo
@ -65,7 +70,6 @@ read -d '' src <<'EOF' || true
};
}
EOF
$([[ $EUID = 0 ]] || echo sudo "PATH=$PATH" "NIX_PATH=$NIX_PATH") \
$(type -P extra-container) shell -E "$src" "${runCmd[@]}"
extra-container shell -E "$src" "${runCmd[@]}"
# The container is automatically deleted at exit