Created function xdt_predict_su_power from end of xdt_arg_interpreter

This commit is contained in:
Thomas Schmitt 2019-12-14 15:21:27 +01:00
parent a3a351bb59
commit b8a2a0bdd3

View File

@ -212,6 +212,29 @@ xdt_reset_job() {
return 0
}
## Predict superuser power. Possibly enable sudo with lsblk -o FSTYPE and dd.
xdt_predict_su_power() {
if test "$(whoami)" = "root"
then
xdt_have_su_power=y
elif test -n "$xdt_with_sudo"
then
echo "Testing sudo to possibly get password prompting done now:" >&2
if sudo "$xdt_lsblk_cmd" -h >/dev/null
then
echo "sudo $xdt_lsblk_cmd seems ok." >&2
echo >&2
xdt_sudo_cmd=sudo
xdt_have_su_power=y
else
echo "FAILURE: Cannot execute program $xdt_lsblk_cmd by sudo" >&2
return 11
fi
fi
return 0
}
## Sets xdt_variables according to its arguments
xdt_arg_interpreter() {
xdt_next_is=
for xdt_i in "$@"
@ -299,25 +322,7 @@ xdt_arg_interpreter() {
return 16
fi
done
# Predict superuser power. Possibly enable sudo with lsblk -o FSTYPE and dd.
if test "$(whoami)" = "root"
then
xdt_have_su_power=y
elif test -n "$xdt_with_sudo"
then
echo "Testing sudo to possibly get password prompting done now:" >&2
if sudo "$xdt_lsblk_cmd" -h >/dev/null
then
echo "sudo $xdt_lsblk_cmd seems ok." >&2
echo >&2
xdt_sudo_cmd=sudo
xdt_have_su_power=y
else
echo "FAILURE: Cannot execute program $xdt_lsblk_cmd by sudo" >&2
return 11
fi
fi
xdt_predict_su_power || return "$?"
return 0
}