From 044360be1a7d6471e1589f5b174ded19ff7be1d2 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Mon, 11 Mar 2024 23:13:18 +0300 Subject: [PATCH] Archive : Add support for remote unarchive. --- module/common/Root.nix | 3 +++ module/common/bash/module/Archive.sh | 16 +++++++++++++--- module/common/bash/module/Su.sh | 5 +++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/module/common/Root.nix b/module/common/Root.nix index eafe8eac..4fd44a28 100644 --- a/module/common/Root.nix +++ b/module/common/Root.nix @@ -1,3 +1,6 @@ { const, ... }: { users.users.root.hashedPassword = const.hashedPassword; + # security.sudo.extraConfig = '' + # Defaults rootpw + # ''; } diff --git a/module/common/bash/module/Archive.sh b/module/common/bash/module/Archive.sh index ab084ea1..837f62f1 100644 --- a/module/common/bash/module/Archive.sh +++ b/module/common/bash/module/Archive.sh @@ -234,13 +234,23 @@ function unarchive() { # Validate. # _archive_check "${target}" || return 1 + # Remote archives. + local remote + local file="${target}" + + if [[ "${target//\\:/}" == *:* ]]; then + local host="${target%%:*}" + file="${target#*:}" + remote=("sudo" "ssh" "${host}") + fi + # Extract. - case "${target##*.}" in + case "${file##*.}" in "txz") - pv ${target} | xz -d | tar -xf - + ${remote[@]} pv ${file} | xz -d | tar -xf - ;; "tgz") - pv ${target} | gzip -d | tar -xf - + ${remote[@]} pv ${file} | gzip -d | tar -xf - ;; esac } diff --git a/module/common/bash/module/Su.sh b/module/common/bash/module/Su.sh index 74b45b2f..b7bf5ddb 100644 --- a/module/common/bash/module/Su.sh +++ b/module/common/bash/module/Su.sh @@ -2,17 +2,18 @@ # Root by default. # Usage: s [USER] function s() { - su - "${1}" + su - ${1} } # Run something as root. # Usage: sudo function sudo() { - su -c "${*}" + su -c "$(echo ${*} | tr '\n' ' ')" } function _complete_s() { _autocomplete "voronind" "dasha" } + complete -F _complete_s s complete -F _autocomplete_nested sudo