added user option to rebuild.sh

This commit is contained in:
Leyla Becker 2024-09-17 18:24:09 -05:00
parent 84877be6f4
commit e2625d0c0a

View file

@ -14,11 +14,16 @@ while [ $# -gt 0 ]; do
if [[ "$1" != *=* ]]; then shift; fi if [[ "$1" != *=* ]]; then shift; fi
mode="${1#*=}" mode="${1#*=}"
;; ;;
--user*|-u*)
if [[ "$1" != *=* ]]; then shift; fi
user="${1#*=}"
;;
--help|-h) --help|-h)
echo "--help -h: print this message" echo "--help -h: print this message"
echo "--target -t: set the target system to install on" echo "--target -t: set the target system to rebuild on"
echo "--flake -f: set the flake to install on the target system" echo "--flake -f: set the flake to rebuild on the target system"
echo "--user -u: set the user to install flake as on the target system" echo "--mode -m: set the mode to rebuild flake as on the target system"
echo "--user -u: set the user to rebuild flake as on the target system"
exit 0 exit 0
;; ;;
*) *)
@ -32,10 +37,11 @@ done
target=${target:-$(hostname)} target=${target:-$(hostname)}
flake=${flake:-$target} flake=${flake:-$target}
mode=${mode:-switch} mode=${mode:-switch}
user=${user:-$USER}
if [[ "$target" == "$(hostname)" ]] if [[ "$target" == "$(hostname)" ]]
then then
nixos-rebuild $mode --use-remote-sudo --flake .#$flake nixos-rebuild $mode --use-remote-sudo --flake .#$flake
else else
nixos-rebuild $mode --use-remote-sudo --target-host $USER@$target --flake .#$flake nixos-rebuild $mode --use-remote-sudo --target-host $user@$target --flake .#$flake
fi fi