aboutsummaryrefslogtreecommitdiff
path: root/kiss
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-04-18 11:16:59 +0000
committermerakor <cem@ckyln.com>2020-04-18 11:16:59 +0000
commit804d48ebbd2ac96e2a80df9123c27f41e557d5ed (patch)
treedbad785558efec51d2d7788d3abaf59ef233700d /kiss
parentfbe8b0386a6c4486302b70a5750136888ab40db4 (diff)
downloadcpt-804d48ebbd2ac96e2a80df9123c27f41e557d5ed.tar.gz
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. FossilOrigin-Name: af560b2a56f6dffd918acb62da30241079a952779c09a12546eba524c34474a1
Diffstat (limited to 'kiss')
-rwxr-xr-xkiss20
1 files changed, 15 insertions, 5 deletions
diff --git a/kiss b/kiss
index 513bd66..6578909 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 </dev/tty ;;
+ *sudo) sudo -E -u "$user" -- "$@" ;;
+ *doas) doas -u "$user" -- "$@" ;;
+ *) su -pc "$* <&3" "$user" 3<&0 </dev/tty ;;
esac
}
@@ -1302,7 +1302,17 @@ args() {
for pkg do pkg_lint "$pkg" c; done
for pkg do pkg_sources "$pkg" c; done
for pkg do
- pkg_checksums "$pkg" > "$(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