From d96e85fddd90b121a5fbdf6649fba8076e2d9acd Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 29 May 2022 09:31:12 +0200 Subject: [PATCH] file-mirror-automount hook now supports modes that cannot mount (like fakechroot) by copying the repo into the chroot --- coverage.txt | 1 + hooks/file-mirror-automount/customize00.sh | 19 ++++++++++++++++--- hooks/file-mirror-automount/setup00.sh | 15 ++++++++++++--- tests/file-mirror-automount-hook | 12 +++++++++++- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/coverage.txt b/coverage.txt index 9ff7aa7..db0c2c4 100644 --- a/coverage.txt +++ b/coverage.txt @@ -127,6 +127,7 @@ Test: file-mirror Needs-QEMU: true Test: file-mirror-automount-hook +Modes: root unshare fakechroot Needs-QEMU: true Test: mirror-is-deb diff --git a/hooks/file-mirror-automount/customize00.sh b/hooks/file-mirror-automount/customize00.sh index 8b181f8..f0432ef 100755 --- a/hooks/file-mirror-automount/customize00.sh +++ b/hooks/file-mirror-automount/customize00.sh @@ -14,13 +14,26 @@ fi xargsopts="--null --no-run-if-empty -I {} --max-args=1" -echo "unmounting the following mountpoints:" >&2 +case $MMDEBSTRAP_MODE in + root|unshare) + echo "unmounting the following mountpoints:" >&2 ;; + *) + echo "removing the following directories:" >&2 ;; +esac cat "$rootdir/run/mmdebstrap/file-mirror-automount" \ | xargs $xargsopts echo " $rootdir/{}" -cat "$rootdir/run/mmdebstrap/file-mirror-automount" \ - | xargs $xargsopts umount "$rootdir/{}" +case $MMDEBSTRAP_MODE in + root|unshare) + cat "$rootdir/run/mmdebstrap/file-mirror-automount" \ + | xargs $xargsopts umount "$rootdir/{}" + ;; + *) + cat "$rootdir/run/mmdebstrap/file-mirror-automount" \ + | xargs $xargsopts rm -r "$rootdir/{}" + ;; +esac rm "$rootdir/run/mmdebstrap/file-mirror-automount" rmdir --ignore-fail-on-non-empty "$rootdir/run/mmdebstrap" diff --git a/hooks/file-mirror-automount/setup00.sh b/hooks/file-mirror-automount/setup00.sh index c1a3c96..6cee5d1 100755 --- a/hooks/file-mirror-automount/setup00.sh +++ b/hooks/file-mirror-automount/setup00.sh @@ -12,9 +12,18 @@ env APT_CONFIG=$MMDEBSTRAP_APT_CONFIG apt-get indextargets --no-release-info \ | sed -ne 's/^Repo-URI: file:\/\+//p' \ | sort -u \ | while read path; do - echo "bind-mounting /$path into the chroot" >&2 mkdir -p "$rootdir/run/mmdebstrap" - mkdir -p "$rootdir/$path" - mount -o ro,bind "/$path" "$rootdir/$path" + case $MMDEBSTRAP_MODE in + root|unshare) + echo "bind-mounting /$path into the chroot" >&2 + mkdir -p "$rootdir/$path" + mount -o ro,bind "/$path" "$rootdir/$path" + ;; + *) + echo "copying /$path into the chroot" >&2 + mkdir -p "$rootdir/$(dirname $path)" + cp -av "/$path" "$rootdir/$(dirname $path)" + ;; + esac printf '/%s\0' "$path" >> "$rootdir/run/mmdebstrap/file-mirror-automount" done diff --git a/tests/file-mirror-automount-hook b/tests/file-mirror-automount-hook index 24e3caa..d965711 100644 --- a/tests/file-mirror-automount-hook +++ b/tests/file-mirror-automount-hook @@ -5,6 +5,16 @@ if [ ! -e /mmdebstrap-testenv ]; then echo "this test requires the cache directory to be mounted on /mnt and should only be run inside a container" >&2 exit 1 fi -{{ CMD }} --mode={{ MODE }} --variant=apt --hook-dir=./hooks/file-mirror-automount --customize-hook='rmdir "$1"/mnt/cache/debian/ "$1"/mnt/cache' {{ DIST }} /tmp/debian-chroot.tar "deb file:///mnt/cache/debian {{ DIST }} main" +if [ "$(id -u)" -eq 0 ] && ! id -u user > /dev/null 2>&1; then + adduser --gecos user --disabled-password user +fi +prefix= +[ "$(id -u)" -eq 0 ] && [ "{{ MODE }}" != "root" ] && prefix="runuser -u user --" +[ "{{ MODE }}" = "fakechroot" ] && prefix="$prefix fakechroot fakeroot" +$prefix {{ CMD }} --mode={{ MODE }} --variant=apt \ + --hook-dir=./hooks/file-mirror-automount \ + --customize-hook='[ ! -e "$1"/mnt/cache/debian/ ] || rmdir "$1"/mnt/cache/debian/' \ + --customize-hook='rmdir "$1"/mnt/cache' \ + {{ DIST }} /tmp/debian-chroot.tar "deb file:///mnt/cache/debian {{ DIST }} main" tar -tf /tmp/debian-chroot.tar | sort | diff -u tar1.txt - rm /tmp/debian-chroot.tar