From 7b0a11677a7c5a3a9490a1d7f30f590265db7689 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sat, 3 Aug 2019 23:05:17 -0400 Subject: makechrootpkg: make the -U option work for the first time ever The -U option was initially introduced in commit cda9cf436b2897b063c1e40efb144404aad8b821 in order to enable running makechrootpkg as root, delegating to another, manually selected, user to perform various non-root tasks (given that makepkg was modified to throw fatal errors when run as root without the option of --asroot to disable that). However, it was only ever implemented for the --verifysource option outside of the chroot, and the builduser inside the chroot is created with the same uid as the makechrootpkg invoker. It needs to run as the same uid, because it needs rw access to $startdir and $SRCDEST! Additionally this lets the invoking user more easily inspect the build directory in case of problems... The correct solution for this is to properly implement the initial intention of the -U option, and make it override the autodetection of the "invoking user" which is normally done by inspecting $SUDO_USER. This is then used as the single source of truth for "who am I pretending to be". Signed-off-by: Eli Schwartz Signed-off-by: Levente Polyak --- makechrootpkg.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 7c3cc93..2407115 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -172,8 +172,8 @@ prepare_chroot() { (( keepbuilddir )) || rm -rf "$copydir/build" local builduser_uid builduser_gid - builduser_uid="${SUDO_UID:-$UID}" - builduser_gid="$(id -g "$builduser_uid")" + builduser_uid="$(id -u "$makepkg_user")" + builduser_gid="$(id -g "$makepkg_user")" local install="install -o $builduser_uid -g $builduser_gid" local x -- cgit v1.2.3-70-g09d2