[arch-projects] [devtools] [PATCH 1/2] makechrootpkg: specify makepkg.conf with -M
PKGDEST and other variables can be set in /etc/makepkg.conf and local correspondents in $HOME, with the file in /etc taking precedence. Specifying a default makepkg.conf on the command line (similar to makepkg) allows to change the directory where build products are moved (move_products), without the need to modify the system configuration in /etc/makepkg.conf or rely on sudoers policy. Fixes FS#44827 --- makechrootpkg.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index cd9efce..efb3cdd 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -21,6 +21,7 @@ run_namcap=false temp_chroot=false chrootdir= passeddir= +makepkg_conf=/etc/makepkg.conf declare -a install_pkgs declare -i ret=0 @@ -63,6 +64,7 @@ usage() { echo " Default: $copy" echo '-n Run namcap on the package' echo '-T Build in a temporary directory' + echo '-M Load variables from an alternate config file' exit 1 } @@ -252,7 +254,7 @@ move_products() { orig_argv=("$@") -while getopts 'hcur:I:l:nTD:d:' arg; do +while getopts 'hcur:I:l:nTD:d:M:' arg; do case "$arg" in c) clean_first=true ;; D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; @@ -263,11 +265,13 @@ while getopts 'hcur:I:l:nTD:d:' arg; do l) copy="$OPTARG" ;; n) run_namcap=true; makepkg_args+=(-i) ;; T) temp_chroot=true; copy+="-$$" ;; + M) makepkg_conf="$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." check_root "$0" "${orig_argv[@]}" @@ -307,7 +311,7 @@ fi umask 0022 load_vars "${XDG_CONFIG_HOME:-$USER_HOME/.config}/pacman/makepkg.conf" || load_vars "$USER_HOME/.makepkg.conf" -load_vars /etc/makepkg.conf +load_vars "$makepkg_conf" # Use PKGBUILD directory if these don't exist [[ -d $PKGDEST ]] || PKGDEST=$PWD -- 2.9.0
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
On 19/07, Alad Wenter wrote:
PKGDEST and other variables can be set in /etc/makepkg.conf and local correspondents in $HOME, with the file in /etc taking precedence. Specifying a default makepkg.conf on the command line (similar to makepkg) allows to change the directory where build products are moved (move_products), without the need to modify the system configuration in /etc/makepkg.conf or rely on sudoers policy.
Aah, /etc/makepkg.conf shouldn't take precedence, that's a bug. -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
Johannes Löthberg via arch-projects wrote:
On 19/07, Alad Wenter wrote:
PKGDEST and other variables can be set in /etc/makepkg.conf and local correspondents in $HOME, with the file in /etc taking precedence. Specifying a default makepkg.conf on the command line (similar to makepkg) allows to change the directory where build products are moved (move_products), without the need to modify the system configuration in /etc/makepkg.conf or rely on sudoers policy.
Aah, /etc/makepkg.conf shouldn't take precedence, that's a bug.
Right, so the two load_vars lines should be swapped. Would you say there's still a use in an -M switch? A program may want to change PKGDEST and other variables, without modifying user configuration, either. Another question: load_vars has -f $makepkg_conf; this should probably be -r $makepkg_conf as in makepkg?
On Wed, Jul 20, 2016 at 1:07 PM Alad Wenter <alad@archlinux.info> wrote:
Johannes Löthberg via arch-projects wrote:
On 19/07, Alad Wenter wrote:
PKGDEST and other variables can be set in /etc/makepkg.conf and local correspondents in $HOME, with the file in /etc taking precedence. Specifying a default makepkg.conf on the command line (similar to makepkg) allows to change the directory where build products are moved (move_products), without the need to modify the system configuration in /etc/makepkg.conf or rely on sudoers policy.
Aah, /etc/makepkg.conf shouldn't take precedence, that's a bug.
Right, so the two load_vars lines should be swapped. Would you say there's still a use in an -M switch? A program may want to change PKGDEST and other variables, without modifying user configuration, either.
Another question: load_vars has -f $makepkg_conf; this should probably be -r $makepkg_conf as in makepkg?
Note that load_vars does not read variables that have been set already. So the order is correct.
Jan Alexander Steffens via arch-projects wrote:
On Wed, Jul 20, 2016 at 1:07 PM Alad Wenter <alad@archlinux.info <mailto:alad@archlinux.info>> wrote:
Johannes Löthberg via arch-projects wrote: > On 19/07, Alad Wenter wrote: >> PKGDEST and other variables can be set in /etc/makepkg.conf and local >> correspondents in $HOME, with the file in /etc taking precedence. >> Specifying a default makepkg.conf on the command line (similar to >> makepkg) allows to change the directory where build products are moved >> (move_products), without the need to modify the system configuration >> in /etc/makepkg.conf or rely on sudoers policy. >> > > Aah, /etc/makepkg.conf shouldn't take precedence, that's a bug. > Right, so the two load_vars lines should be swapped. Would you say there's still a use in an -M switch? A program may want to change PKGDEST and other variables, without modifying user configuration, either.
Another question: load_vars has -f $makepkg_conf; this should probably be -r $makepkg_conf as in makepkg?
Note that load_vars does not read variables that have been set already. So the order is correct.
Oh, clever. In that case I'd suggest to instead expand the usage section, as it differs from makepkg. For example: "makechrootpkg reads *DEST, PACKAGER and MAKEFLAGS from /etc/makepkg.conf and $XDG_CONFIG_HOME/pacman/makepkg.conf (in this order), if those variables were not set already for example, from the sudo command line)." Thoughts?
participants (3)
-
Alad Wenter
-
Jan Alexander Steffens
-
Johannes Löthberg