From b8a2a0bdd3fcd81252b029fdad684a6981ec5967 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 14 Dec 2019 15:21:27 +0100 Subject: [PATCH] Created function xdt_predict_su_power from end of xdt_arg_interpreter --- xorriso-dd-target/xorriso-dd-target.xdt | 43 ++++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/xorriso-dd-target/xorriso-dd-target.xdt b/xorriso-dd-target/xorriso-dd-target.xdt index df7c1f99..c8ed57e6 100755 --- a/xorriso-dd-target/xorriso-dd-target.xdt +++ b/xorriso-dd-target/xorriso-dd-target.xdt @@ -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 }