nixos-rebuild: fix the maybeSudo usage
* properly expand the command using arrays instead of strings * also handle sudo on the localhost
This commit is contained in:
parent
93204f1d8a
commit
ab10bac1b1
@ -22,7 +22,7 @@ repair=
|
|||||||
profile=/nix/var/nix/profiles/system
|
profile=/nix/var/nix/profiles/system
|
||||||
buildHost=
|
buildHost=
|
||||||
targetHost=
|
targetHost=
|
||||||
maybeSudo=
|
maybeSudo=()
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
i="$1"; shift 1
|
i="$1"; shift 1
|
||||||
@ -92,7 +92,7 @@ while [ "$#" -gt 0 ]; do
|
|||||||
;;
|
;;
|
||||||
--use-remote-sudo)
|
--use-remote-sudo)
|
||||||
# note the trailing space
|
# note the trailing space
|
||||||
maybeSudo="sudo "
|
maybeSudo=(sudo --)
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -102,6 +102,10 @@ while [ "$#" -gt 0 ]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ -n "$SUDO_USER" ]; then
|
||||||
|
maybeSudo=(sudo --)
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$buildHost" -a -n "$targetHost" ]; then
|
if [ -z "$buildHost" -a -n "$targetHost" ]; then
|
||||||
buildHost="$targetHost"
|
buildHost="$targetHost"
|
||||||
fi
|
fi
|
||||||
@ -116,17 +120,17 @@ buildHostCmd() {
|
|||||||
if [ -z "$buildHost" ]; then
|
if [ -z "$buildHost" ]; then
|
||||||
"$@"
|
"$@"
|
||||||
elif [ -n "$remoteNix" ]; then
|
elif [ -n "$remoteNix" ]; then
|
||||||
ssh $SSHOPTS "$buildHost" env PATH="$remoteNix:$PATH" "$maybeSudo$@"
|
ssh $SSHOPTS "$buildHost" env PATH="$remoteNix:$PATH" "${maybeSudo[@]}" "$@"
|
||||||
else
|
else
|
||||||
ssh $SSHOPTS "$buildHost" "$maybeSudo$@"
|
ssh $SSHOPTS "$buildHost" "${maybeSudo[@]}" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
targetHostCmd() {
|
targetHostCmd() {
|
||||||
if [ -z "$targetHost" ]; then
|
if [ -z "$targetHost" ]; then
|
||||||
"$@"
|
"${maybeSudo[@]}" "$@"
|
||||||
else
|
else
|
||||||
ssh $SSHOPTS "$targetHost" "$maybeSudo$@"
|
ssh $SSHOPTS "$targetHost" "${maybeSudo[@]}" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user