diff options
author | Karel Kočí <cynerd@email.cz> | 2022-08-09 20:15:23 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-08-09 20:15:23 +0200 |
commit | 8eaf6c4734e1184d7c31708247cba0fa01999386 (patch) | |
tree | a212ff9153adfa7acf4b2f305ec889044af90ba7 /common.sh | |
parent | 564e6d8b1340d15e1305a072f63eec0378bd7076 (diff) | |
download | nixos-personal-8eaf6c4734e1184d7c31708247cba0fa01999386.tar.gz nixos-personal-8eaf6c4734e1184d7c31708247cba0fa01999386.tar.bz2 nixos-personal-8eaf6c4734e1184d7c31708247cba0fa01999386.zip |
common.sh: fix invalid switch
Diffstat (limited to 'common.sh')
-rw-r--r-- | common.sh | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -35,16 +35,31 @@ sshdest() { awk -F- 'NF > 1 { print $2"."$1; exit } { print $1 }' <<<"$1" } +_sh() { + if [ $# -gt 1 ]; then + "$@" + else + sh -c "$1" + fi +} + _ssh() { local device="$1" shift if [ "$device" != "$(hostname)" ]; then - local -a args - [ "$1" = "sudo" ] && \ - args+=('-t') # Crude detection for terminal need - ssh "${args[@]}" "$(sshdest "$device")" -- "$@" + ssh "$(sshdest "$device")" -- "$@" else - "$@" + _sh "$@" + fi +} + +_tssh() { + local device="$1" + shift + if [ "$device" != "$(hostname)" ]; then + ssh -t "$(sshdest "$device")" -- "$@" + else + _sh "$@" fi } @@ -135,10 +150,11 @@ setenv() { info "-----------------------------------------------------------------" # TODO we should call here switch-to-configuration as well to use single # sudo session and remove one prompt. - _ssh "$device" \ - sudo sh -c \ - 'nix-env --profile /nix/var/nix/profiles/system --set "$store" && /nix/var/nix/profiles/system/bin/switch-to-configuration "$1"' \ - "$switchop" + local _store _switchop + printf -v _store '%q' "$store" + printf -v _switchop '%q' "$switchop" + _tssh "$device" \ + "sudo nix-env --profile /nix/var/nix/profiles/system --set '$_store' && sudo /nix/var/nix/profiles/system/bin/switch-to-configuration '$_switchop'" else warning "The latest system might have been already set." fi |