From 1c059e813981744de281dc7d1db4b4b3b5bff1e6 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 18 Apr 2020 09:35:38 +0300 Subject: [PATCH] kiss: Elevate permissions if needed during checksum generation. This simply modifies as_root() to allow running commands as any given user and generates checksums according to the owner of the checksums file and the current user's write permissions. --- kiss | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/kiss b/kiss index 39a93c3..c31307c 100755 --- a/kiss +++ b/kiss @@ -53,12 +53,12 @@ prompt() { as_root() { # Simple function to run a command as root using either 'sudo', # 'doas' or 'su'. Hurrah for choice. - [ "$uid" = 0 ] || log "Using '${su:-su}'" + [ "$uid" = 0 ] || log "Using '${su:-su}' (to become ${user:=root})" case $su in - *sudo) sudo -E -- "$@" ;; - *doas) doas -- "$@" ;; - *) su -pc "$* <&3" 3<&0 "$(pkg_find "$pkg")/checksums" + pkg_checksums "$pkg" | { + repo_dir=$(pkg_find "$pkg")/checksums + + if [ -w "$repo_dir" ]; then + tee "$repo_dir" + else + log "$pkg" "Need permissions to generate checksums" + + user=$(stat -c %U "$repo_dir") as_root tee "$repo_dir" + fi + } log "$pkg" "Generated checksums" done