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, ... }: {
users.users.root.hashedPassword = const.hashedPassword;
# security.sudo.extraConfig = ''
# Defaults rootpw
# '';
}

View file

@ -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
}

View file

@ -2,17 +2,18 @@
# Root by default.
# Usage: s [USER]
function s() {
su - "${1}"
su - ${1}
}
# Run something as root.
# Usage: sudo <COMMAND>
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