From a68805537459f378dcc25fff49389ad94e8f5fc2 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 29 Jan 2020 14:28:37 +0200 Subject: [PATCH] kiss: use sudo if available --- kiss | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kiss b/kiss index 4808304..1ebcc34 100755 --- a/kiss +++ b/kiss @@ -106,10 +106,16 @@ dosu() { # below. Great naming of functions all around. # # Run a command as root using the cached password. The 'su' - # command allows you to input a password via stdin. To hide - # the prompt, the command's output is sent to '/dev/tty' - # and the output of 'su' is sent to '/dev/null'. - dosudo() { su "${drop_to:-root}" -c "$* >/dev/tty" >/dev/null; } + # and 'sudo' commands allow you to input a password via stdin. + # To hide the prompt, the command's output is sent to '/dev/tty' + # and the output of 'su'/'sudo' is sent to '/dev/null'. + dosudo() { + if command -v sudo >/dev/null 2>&1; then + sudo -SEk -- su "${drop_to:-root}" -c "$* >/dev/tty" 2>/dev/null + else + su "${drop_to:-root}" -c "$* >/dev/tty" >/dev/null + fi + } # The code below uses the most secure method of sending # data over stdin based on what is available in the system.