From 02812f4c062cd39ca4990cec08fa5bad64313551 Mon Sep 17 00:00:00 2001 From: Matthieu Crapet Date: Fri, 1 Jan 2021 21:46:11 +0100 Subject: [PATCH] tomb forge: useless sudo and chown Depending script invokation, behavior is not exactly similar. Assuming that if SUDO_USER is set, the _sudo invokation can be dropped (EUID=0). In the other case, user has created file, owner is already good, don't call chown. Preparation: $ tomb dig foo.tomb -s 10 Method 1: $ sudo tomb forge foo.tomb.key -v Method 2: $ tomb forge foo.tomb.key -v ... ask user password to gain superuser privileges ... Sorry, user is not allowed to execute '/bin/chown : foo.tomb.key' as root on . Signed-off-by: Matthieu Crapet --- tomb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tomb b/tomb index 2be0afc..bc76d3f 100755 --- a/tomb +++ b/tomb @@ -1955,7 +1955,7 @@ forge_key() { _failure "Operation aborted." } - _sudo chown ${_UID}:${_GID} "$TOMBKEYFILE" + [[ -n $SUDO_USER ]] && chown ${_UID}:${_GID} "$TOMBKEYFILE" _message "Done forging ::1 key file::" $TOMBKEYFILE _success "Your key is ready:" ls -lh $TOMBKEYFILE