[arch-projects] [devtools] [RFC] makechrootpkg: add generic support for additional bind mounts
Piggyback on systemd-nspawn's --bind and --bind-ro flags to allow arbitrary mount points to be added to the build container. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- This is untested, but is the result of a brief exchange I had with Pierre on IRC. It was suggested that we provide generic support for adding bind mounts rather than explicitly adding support for ccache (since all it really requires is the extra bind mount). makechrootpkg.in | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 1cd08fb..04ed04b 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -24,6 +24,9 @@ passeddir= declare -a install_pkgs declare -i ret=0 +bindmounts_ro=() +bindmounts_rw=() + copy=$USER [[ -n $SUDO_USER ]] && copy=$SUDO_USER [[ -z "$copy" || $copy = root ]] && copy=copy @@ -48,6 +51,8 @@ usage() { echo 'Flags:' echo '-h This help' 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 '-u Update the working copy of the chroot before building' echo ' This is useful for rebuilds without dirtying the pristine' echo ' chroot' @@ -65,6 +70,8 @@ while getopts 'hcur:I:l:nT' arg; do case "$arg" in h) usage ;; c) clean_first=true ;; + D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; + d) bindmounts_rw+=(--bind="$OPTARG") ;; u) update_first=true ;; r) passeddir="$OPTARG" ;; I) install_pkgs+=("$OPTARG") ;; @@ -174,7 +181,9 @@ install_packages() { pkgname="${install_pkg##*/}" cp "$install_pkg" "$copydir/$pkgname" - arch-nspawn "$copydir" pacman -U /$pkgname --noconfirm + arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -U /$pkgname --noconfirm (( ret += !! $? )) rm "$copydir/$pkgname" @@ -338,7 +347,9 @@ load_vars /etc/makepkg.conf create_chroot -$update_first && arch-nspawn "$copydir" pacman -Syu --noconfirm +$update_first && arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -Syu --noconfirm [[ -n ${install_pkgs[*]} ]] && install_packages @@ -349,6 +360,7 @@ download_sources if arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ --bind-ro="$SRCDEST:/srcdest_host" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ /chrootbuild then move_products -- 1.8.3.4
You forgot the getopts entry: --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -66,7 +66,7 @@ usage() { exit 1 } -while getopts 'hcur:I:l:nT' arg; do +while getopts 'hcd:D:ur:I:l:nT' arg; do case "$arg" in h) usage ;; c) clean_first=true ;; On 8/10/13, Dave Reisner <dreisner@archlinux.org> wrote:
Piggyback on systemd-nspawn's --bind and --bind-ro flags to allow arbitrary mount points to be added to the build container.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- This is untested, but is the result of a brief exchange I had with Pierre on IRC. It was suggested that we provide generic support for adding bind mounts rather than explicitly adding support for ccache (since all it really requires is the extra bind mount).
makechrootpkg.in | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/makechrootpkg.in b/makechrootpkg.in index 1cd08fb..04ed04b 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -24,6 +24,9 @@ passeddir= declare -a install_pkgs declare -i ret=0
+bindmounts_ro=() +bindmounts_rw=() + copy=$USER [[ -n $SUDO_USER ]] && copy=$SUDO_USER [[ -z "$copy" || $copy = root ]] && copy=copy @@ -48,6 +51,8 @@ usage() { echo 'Flags:' echo '-h This help' 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 '-u Update the working copy of the chroot before building' echo ' This is useful for rebuilds without dirtying the pristine' echo ' chroot' @@ -65,6 +70,8 @@ while getopts 'hcur:I:l:nT' arg; do case "$arg" in h) usage ;; c) clean_first=true ;; + D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; + d) bindmounts_rw+=(--bind="$OPTARG") ;; u) update_first=true ;; r) passeddir="$OPTARG" ;; I) install_pkgs+=("$OPTARG") ;; @@ -174,7 +181,9 @@ install_packages() { pkgname="${install_pkg##*/}" cp "$install_pkg" "$copydir/$pkgname"
- arch-nspawn "$copydir" pacman -U /$pkgname --noconfirm + arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -U /$pkgname --noconfirm (( ret += !! $? ))
rm "$copydir/$pkgname" @@ -338,7 +347,9 @@ load_vars /etc/makepkg.conf
create_chroot
-$update_first && arch-nspawn "$copydir" pacman -Syu --noconfirm +$update_first && arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -Syu --noconfirm
[[ -n ${install_pkgs[*]} ]] && install_packages
@@ -349,6 +360,7 @@ download_sources if arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ --bind-ro="$SRCDEST:/srcdest_host" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ /chrootbuild then move_products -- 1.8.3.4
OK... But otherwise does it do what you want? On Aug 18, 2013 2:08 PM, "Dominik Heidler" <dheidler@gmail.com> wrote:
You forgot the getopts entry:
--- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -66,7 +66,7 @@ usage() { exit 1 }
-while getopts 'hcur:I:l:nT' arg; do +while getopts 'hcd:D:ur:I:l:nT' arg; do case "$arg" in h) usage ;; c) clean_first=true ;;
On 8/10/13, Dave Reisner <dreisner@archlinux.org> wrote:
Piggyback on systemd-nspawn's --bind and --bind-ro flags to allow arbitrary mount points to be added to the build container.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- This is untested, but is the result of a brief exchange I had with Pierre on IRC. It was suggested that we provide generic support for adding bind mounts rather than explicitly adding support for ccache (since all it really requires is the extra bind mount).
makechrootpkg.in | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/makechrootpkg.in b/makechrootpkg.in index 1cd08fb..04ed04b 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -24,6 +24,9 @@ passeddir= declare -a install_pkgs declare -i ret=0
+bindmounts_ro=() +bindmounts_rw=() + copy=$USER [[ -n $SUDO_USER ]] && copy=$SUDO_USER [[ -z "$copy" || $copy = root ]] && copy=copy @@ -48,6 +51,8 @@ usage() { echo 'Flags:' echo '-h This help' 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 '-u Update the working copy of the chroot before building' echo ' This is useful for rebuilds without dirtying the pristine' echo ' chroot' @@ -65,6 +70,8 @@ while getopts 'hcur:I:l:nT' arg; do case "$arg" in h) usage ;; c) clean_first=true ;; + D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; + d) bindmounts_rw+=(--bind="$OPTARG") ;; u) update_first=true ;; r) passeddir="$OPTARG" ;; I) install_pkgs+=("$OPTARG") ;; @@ -174,7 +181,9 @@ install_packages() { pkgname="${install_pkg##*/}" cp "$install_pkg" "$copydir/$pkgname"
- arch-nspawn "$copydir" pacman -U /$pkgname --noconfirm + arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -U /$pkgname --noconfirm (( ret += !! $? ))
rm "$copydir/$pkgname" @@ -338,7 +347,9 @@ load_vars /etc/makepkg.conf
create_chroot
-$update_first && arch-nspawn "$copydir" pacman -Syu --noconfirm +$update_first && arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -Syu --noconfirm
[[ -n ${install_pkgs[*]} ]] && install_packages
@@ -349,6 +360,7 @@ download_sources if arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ --bind-ro="$SRCDEST:/srcdest_host" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ /chrootbuild then move_products -- 1.8.3.4
participants (3)
-
Dave Reisner
-
Dave Reisner
-
Dominik Heidler