From 342902f2464ff27c62cdaed78bc7074b6694dbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 8 Nov 2022 09:39:21 +0100 Subject: common.sh: improve ssh access --- common.sh | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'common.sh') diff --git a/common.sh b/common.sh index cf8c175..797457a 100644 --- a/common.sh +++ b/common.sh @@ -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 -- cgit v1.2.3