diff options
author | Karel Kočí <cynerd@email.cz> | 2022-11-08 09:39:21 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-11-08 09:39:21 +0100 |
commit | 342902f2464ff27c62cdaed78bc7074b6694dbb4 (patch) | |
tree | 3078c1c501e654de7ed1650bbad5362f9866143f | |
parent | 0be1cd4e5dde86f917f8c76c4bac7599c0124a31 (diff) | |
download | nixos-personal-342902f2464ff27c62cdaed78bc7074b6694dbb4.tar.gz nixos-personal-342902f2464ff27c62cdaed78bc7074b6694dbb4.tar.bz2 nixos-personal-342902f2464ff27c62cdaed78bc7074b6694dbb4.zip |
common.sh: improve ssh access
-rw-r--r-- | common.sh | 26 |
1 files changed, 10 insertions, 16 deletions
@@ -44,31 +44,27 @@ sshhost() { 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 ssh "$(sshdest "$device")" -- "$@" else - _sh "$@" + if [ $# -gt 1 ]; then + "$@" + else + sh -c "$1" + fi fi } -_tssh() { +_rootssh() { local device="$1" - shift + local cmd="$2" if [ "$device" != "$(hostname)" ]; then - ssh -t "$(sshdest "$device")" -- "$@" + ssh -t "$(sshdest "$device")" sudo "sh -c '${cmd@Q}'" else - _sh "$@" + sudo sh -c "$cmd" fi } @@ -160,12 +156,10 @@ setenv() { _ssh "$device" \ nix store diff-closures "$cursystem" "$store" info "-----------------------------------------------------------------" - # TODO we should call here switch-to-configuration as well to use single - # sudo session and remove one prompt. local _store _switchop printf -v _store '%q' "$store" printf -v _switchop '%q' "$switchop" - _tssh "$device" "sudo '$_store/bin/nixos-system' -s '$_switchop'" + _rootssh "$device" "$_store/bin/nixos-system -s $_switchop" else warning "The latest system might have been already set." fi |