[arch-projects] [devtools] [PATCH 2/2] makechrootpkg: run makepkg as specified user
Alad Wenter
alad at archlinux.info
Tue Jul 19 16:53:56 UTC 2016
Fixes FS#43432
---
makechrootpkg.in | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/makechrootpkg.in b/makechrootpkg.in
index efb3cdd..1c4b0c0 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -22,6 +22,7 @@ temp_chroot=false
chrootdir=
passeddir=
makepkg_conf=/etc/makepkg.conf
+makepkg_user=
declare -a install_pkgs
declare -i ret=0
@@ -65,6 +66,7 @@ usage() {
echo '-n Run namcap on the package'
echo '-T Build in a temporary directory'
echo '-M Load variables from an alternate config file'
+ echo '-U Run makepkg as a specified user'
exit 1
}
@@ -219,13 +221,13 @@ download_sources() {
chmod 1777 "$builddir"
# Ensure sources are downloaded
- if [[ -n $SUDO_USER ]]; then
- sudo -u $SUDO_USER env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \
+ makepkg_user=${makepkg_user:-$SUDO_USER}
+ if [[ -n $makepkg_user ]]; then
+ sudo -u "$makepkg_user" env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \
makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o
else
- ( export SRCDEST BUILDDIR="$builddir"
- makepkg --asroot --config="$copydir/etc/makepkg.conf" --verifysource -o
- )
+ error "Running makepkg as root is not allowed."
+ exit 1
fi
(( $? != 0 )) && die "Could not download sources."
@@ -254,7 +256,7 @@ move_products() {
orig_argv=("$@")
-while getopts 'hcur:I:l:nTD:d:M:' arg; do
+while getopts 'hcur:I:l:nTD:d:M:U:' arg; do
case "$arg" in
c) clean_first=true ;;
D) bindmounts_ro+=(--bind-ro="$OPTARG") ;;
@@ -266,12 +268,14 @@ while getopts 'hcur:I:l:nTD:d:M:' arg; do
n) run_namcap=true; makepkg_args+=(-i) ;;
T) temp_chroot=true; copy+="-$$" ;;
M) makepkg_conf="$OPTARG" ;;
+ U) makepkg_user="$OPTARG" ;;
h|*) usage ;;
esac
done
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
[[ ! -f $makepkg_conf ]] && die "$makepkg_conf does not exist."
+[[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.'
check_root "$0" "${orig_argv[@]}"
--
2.9.0
More information about the arch-projects
mailing list