improve support of non-sudo setup, by default support doas

aldo better support when launched from root
This commit is contained in:
Jaromil 2024-05-13 01:30:58 +02:00
parent 2082198b36
commit bae8af351b

38
tomb
View File

@ -48,8 +48,6 @@ for arg in "${(@)argv}"; do OLDARGS+=("$arg"); done
typeset -a DD WIPE PINENTRY SUDO typeset -a DD WIPE PINENTRY SUDO
DD=(dd) DD=(dd)
WIPE=(rm -f) WIPE=(rm -f)
PINENTRY=(pinentry)
SUDO=(sudo)
# load zsh regex module # load zsh regex module
zmodload zsh/mapfile zmodload zsh/mapfile
@ -133,15 +131,29 @@ _sudo() {
esac esac
else else
local msg="[sudo] Enter password for user ::1 user:: to gain superuser privileges" if [[ "`id -u`" = "0" ]]; then
command -v gettext 1>/dev/null 2>/dev/null && msg="$(gettext -s "$msg")" _verbose "Super user execution skipped (SUID caller)"
msg=${(S)msg//::1*::/$USER} ${@}
[[ -n "$SUDO_ASKPASS" ]] && local sudo_askpass="--askpass" return $?
sudo $sudo_askpass -p " elif command -v sudo 1>/dev/null 2>/dev/null; then
local msg="[sudo] Enter password for user ::1 user:: to gain superuser privileges"
command -v gettext 1>/dev/null 2>/dev/null && msg="$(gettext -s "$msg")"
msg=${(S)msg//::1*::/$USER}
[[ -n "$SUDO_ASKPASS" ]] && local sudo_askpass="--askpass"
sudo $sudo_askpass -p "
$msg $msg
" ${@} " ${@}
return $? return $?
elif command -v doas 1>/dev/null 2>/dev/null; then
local msg="Enter password for user ::1 user:: to gain superuser privileges"
command -v gettext 1>/dev/null 2>/dev/null && msg="$(gettext -s "$msg")"
msg=${(S)msg//::1*::/$USER}
doas ${@}
return $?
else
_failure "No way found to escalate privileges to super user."
fi
fi fi
} }
@ -994,7 +1006,7 @@ _list_optional_tools() {
_ensure_dependencies() { _ensure_dependencies() {
# Check for required programs # Check for required programs
for req in cryptsetup sudo gpg mkfs.ext4 e2fsck; do for req in cryptsetup gpg mkfs.ext4 e2fsck; do
command -v $req 1>/dev/null 2>/dev/null || { command -v $req 1>/dev/null 2>/dev/null || {
_failure "Missing required dependency ::1 command::. Please install it." $req; } _failure "Missing required dependency ::1 command::. Please install it." $req; }
done done
@ -1011,10 +1023,10 @@ _ensure_dependencies() {
# command -v pkexec 1>/dev/null 2>/dev/null # command -v pkexec 1>/dev/null 2>/dev/null
# [[ $? == 0 ]] && ps ax | grep '[p]olkitd' 1>/dev/null 2>/dev/null && { # [[ $? == 0 ]] && ps ax | grep '[p]olkitd' 1>/dev/null 2>/dev/null && {
# SUDO=(pkexec) } # SUDO=(pkexec) }
[[ "$SUDO" == "sudo" ]] && { # [[ "$SUDO" == "sudo" ]] && {
command -v sudo 1>/dev/null 2>/dev/null || # command -v sudo 1>/dev/null 2>/dev/null ||
_failure "No privilege escalation tool found, not even sudo" # _failure "No privilege escalation tool found, not even sudo"
} # }
# Which dd command to use # Which dd command to use
command -v dcfldd 1>/dev/null 2>/dev/null && DD=(dcfldd statusinterval=1) command -v dcfldd 1>/dev/null 2>/dev/null && DD=(dcfldd statusinterval=1)