[arch-projects] [devtools] [PATCH 1/2] allow passing --setenv to nspawn

Patrick Burroughs (Celti) celti at celti.name
Sun May 1 17:47:59 UTC 2016


---
 makechrootpkg.in | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/makechrootpkg.in b/makechrootpkg.in
index 9cb25fc..1ef89a4 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -26,6 +26,7 @@ declare -i ret=0
 
 bindmounts_ro=()
 bindmounts_rw=()
+setenv=()
 
 copy=$USER
 [[ -n $SUDO_USER ]] && copy=$SUDO_USER
@@ -53,6 +54,7 @@ usage() {
 	echo '-c         Clean the chroot before building'
 	echo '-d <dir>   Bind directory into build chroot as read-write'
 	echo '-D <dir>   Bind directory into build chroot as read-only'
+	echo '-e <var>   Set an environment variable inside the chroot'
 	echo '-u         Update the working copy of the chroot before building'
 	echo '           This is useful for rebuilds without dirtying the pristine'
 	echo '           chroot'
@@ -134,7 +136,7 @@ install_packages() {
 		cp "$install_pkg" "$copydir/$pkgname"
 
 		arch-nspawn "$copydir" \
-			"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
+			"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" "${setenv[@]}" \
 			pacman -U /$pkgname --noconfirm
 		(( ret += !! $? ))
 
@@ -313,11 +315,12 @@ move_products() {
 
 orig_argv=("$@")
 
-while getopts 'hcur:I:l:nTD:d:' arg; do
+while getopts 'hcur:I:l:nTD:d:e:' arg; do
 	case "$arg" in
 		c) clean_first=true ;;
 		D) bindmounts_ro+=(--bind-ro="$OPTARG") ;;
 		d) bindmounts_rw+=(--bind="$OPTARG") ;;
+		e) setenv+=(--setenv="$OPTARG") ;;
 		u) update_first=true ;;
 		r) passeddir="$OPTARG" ;;
 		I) install_pkgs+=("$OPTARG") ;;
@@ -379,7 +382,7 @@ load_vars /etc/makepkg.conf
 create_chroot
 
 $update_first && arch-nspawn "$copydir" \
-		"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
+		"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" "${setenv[@]}" \
 		pacman -Syu --noconfirm
 
 [[ -n ${install_pkgs[*]} ]] && install_packages
@@ -391,7 +394,7 @@ prepare_chroot
 if arch-nspawn "$copydir" \
 	--bind-ro="$PWD:/startdir_host" \
 	--bind-ro="$SRCDEST:/srcdest_host" \
-	"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
+	"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" "${setenv[@]}" \
 	/chrootbuild
 then
 	move_products
-- 
2.8.2


More information about the arch-projects mailing list