Archive : Add support for remote unarchive.

This commit is contained in:
Dmitry Voronin 2024-03-11 23:13:18 +03:00
parent 3801872c05
commit 044360be1a
3 changed files with 19 additions and 5 deletions

View file

@ -1,3 +1,6 @@
{ const, ... }: { { const, ... }: {
users.users.root.hashedPassword = const.hashedPassword; users.users.root.hashedPassword = const.hashedPassword;
# security.sudo.extraConfig = ''
# Defaults rootpw
# '';
} }

View file

@ -234,13 +234,23 @@ function unarchive() {
# Validate. # Validate.
# _archive_check "${target}" || return 1 # _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. # Extract.
case "${target##*.}" in case "${file##*.}" in
"txz") "txz")
pv ${target} | xz -d | tar -xf - ${remote[@]} pv ${file} | xz -d | tar -xf -
;; ;;
"tgz") "tgz")
pv ${target} | gzip -d | tar -xf - ${remote[@]} pv ${file} | gzip -d | tar -xf -
;; ;;
esac esac
} }

View file

@ -2,17 +2,18 @@
# Root by default. # Root by default.
# Usage: s [USER] # Usage: s [USER]
function s() { function s() {
su - "${1}" su - ${1}
} }
# Run something as root. # Run something as root.
# Usage: sudo <COMMAND> # Usage: sudo <COMMAND>
function sudo() { function sudo() {
su -c "${*}" su -c "$(echo ${*} | tr '\n' ' ')"
} }
function _complete_s() { function _complete_s() {
_autocomplete "voronind" "dasha" _autocomplete "voronind" "dasha"
} }
complete -F _complete_s s complete -F _complete_s s
complete -F _autocomplete_nested sudo complete -F _autocomplete_nested sudo