From 8eaf6c4734e1184d7c31708247cba0fa01999386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 9 Aug 2022 20:15:23 +0200 Subject: common.sh: fix invalid switch --- common.sh | 34 +++++++++++++++++++++++++--------- flake.lock | 12 ++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/common.sh b/common.sh index 995a57e..4f005de 100644 --- a/common.sh +++ b/common.sh @@ -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 diff --git a/flake.lock b/flake.lock index 158df2e..c3482a9 100644 --- a/flake.lock +++ b/flake.lock @@ -44,11 +44,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1659356074, - "narHash": "sha256-UwV6hZZEtchvtiTCCD/ODEv1226eam8kEgEyQb7xB0E=", + "lastModified": 1660030916, + "narHash": "sha256-KeVTmST6vAS85uUaSYlzv6OWhveawfIGhqX1SMq+L30=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "ea3efc80f8ab83cb73aec39f4e76fe87afb15a08", + "rev": "3975d5158f00accda15a11180b2c08654cfb2807", "type": "github" }, "original": { @@ -58,11 +58,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659987637, - "narHash": "sha256-8l+5QiCkackVPu/F3vX7RCKHyYKxEsq/TKMuaG6UX5k=", + "lastModified": 1660017629, + "narHash": "sha256-Koz6/k7c6hx4qVz/bboxdR2QsBdkxjRWpNmsOWJtXZE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a47896bf817e7324471e687fc2bb2312fff682ce", + "rev": "9f15d6c3a74d2778c6e1af67947c95f100dc6fd2", "type": "github" }, "original": { -- cgit v1.2.3