diff --git a/coverage.sh b/coverage.sh
index 1eb87e4..c4765b6 100755
--- a/coverage.sh
+++ b/coverage.sh
@@ -126,8 +126,23 @@ if [ ! -e shared/hooks/eatmydata/customize.sh ] || [ hooks/eatmydata/customize.s
cp -a /usr/share/mmdebstrap/hooks/eatmydata/customize.sh shared/hooks/eatmydata/
fi
fi
+mkdir -p shared/hooks/file-mirror-automount
+if [ ! -e shared/hooks/file-mirror-automount/setup00.sh ] || [ hooks/file-mirror-automount/setup00.sh -nt shared/hooks/file-mirror-automount/setup00.sh ]; then
+ if [ -e hooks/file-mirror-automount/setup00.sh ]; then
+ cp -a hooks/file-mirror-automount/setup00.sh shared/hooks/file-mirror-automount/
+ else
+ cp -a /usr/share/mmdebstrap/hooks/file-mirror-automount/setup00.sh shared/hooks/file-mirror-automount/
+ fi
+fi
+if [ ! -e shared/hooks/file-mirror-automount/customize00.sh ] || [ hooks/file-mirror-automount/customize00.sh -nt shared/hooks/file-mirror-automount/customize00.sh ]; then
+ if [ -e hooks/file-mirror-automount/customize00.sh ]; then
+ cp -a hooks/file-mirror-automount/customize00.sh shared/hooks/file-mirror-automount/
+ else
+ cp -a /usr/share/mmdebstrap/hooks/file-mirror-automount/customize00.sh shared/hooks/file-mirror-automount/
+ fi
+fi
starttime=
-total=183
+total=184
skipped=0
runtests=0
i=1
@@ -1556,6 +1571,27 @@ else
skipped=$((skipped+1))
fi
+print_header "mode=$defaultmode,variant=apt: test file-mirror-automount hook"
+cat << END > shared/test.sh
+#!/bin/sh
+set -eu
+export LC_ALL=C.UTF-8
+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=$defaultmode --variant=apt --hook-dir=./hooks/file-mirror-automount --customize-hook='rmdir "\$1"/mnt/cache/debian/ "\$1"/mnt/cache' $DEFAULT_DIST /tmp/debian-chroot.tar "deb file:///mnt/cache/debian $DEFAULT_DIST main"
+tar -tf /tmp/debian-chroot.tar | sort | diff -u tar1.txt -
+rm /tmp/debian-chroot.tar
+END
+if [ "$HAVE_QEMU" = "yes" ]; then
+ ./run_qemu.sh
+ runtests=$((runtests+1))
+else
+ echo "HAVE_QEMU != yes -- Skipping test..." >&2
+ skipped=$((skipped+1))
+fi
+
print_header "mode=$defaultmode,variant=apt: mirror is deb..."
cat << END > shared/test.sh
#!/bin/sh
diff --git a/hooks/file-mirror-automount/customize00.sh b/hooks/file-mirror-automount/customize00.sh
new file mode 100755
index 0000000..8b181f8
--- /dev/null
+++ b/hooks/file-mirror-automount/customize00.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -eu
+
+if [ "$MMDEBSTRAP_VERBOSITY" -ge 3 ]; then
+ set -x
+fi
+
+rootdir="$1"
+
+if [ ! -e "$rootdir/run/mmdebstrap/file-mirror-automount" ]; then
+ exit 0
+fi
+
+xargsopts="--null --no-run-if-empty -I {} --max-args=1"
+
+echo "unmounting the following mountpoints:" >&2
+
+cat "$rootdir/run/mmdebstrap/file-mirror-automount" \
+ | xargs $xargsopts echo " $rootdir/{}"
+
+cat "$rootdir/run/mmdebstrap/file-mirror-automount" \
+ | xargs $xargsopts umount "$rootdir/{}"
+
+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
new file mode 100755
index 0000000..c1a3c96
--- /dev/null
+++ b/hooks/file-mirror-automount/setup00.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -eu
+
+if [ "$MMDEBSTRAP_VERBOSITY" -ge 3 ]; then
+ set -x
+fi
+
+rootdir="$1"
+
+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"
+ printf '/%s\0' "$path" >> "$rootdir/run/mmdebstrap/file-mirror-automount"
+ done
diff --git a/mmdebstrap b/mmdebstrap
index d0d9ddb..2696348 100755
--- a/mmdebstrap
+++ b/mmdebstrap
@@ -2176,7 +2176,10 @@ sub run_download() {
if (rindex $deb, $options->{root}, 0) {
if (!-e "$options->{root}/$deb") {
error "package file $deb not accessible from chroot directory"
- . " -- use copy:// instead of file:// or a bind-mount";
+ . " -- use copy:// instead of file:// or a bind-mount. You"
+ . " can also try using --hook-dir=/usr/share/mmdebstrap/"
+ . "hooks/file-mirror-automount to automatically create"
+ . " the necessary bind-mounts.";
}
push @essential_pkgs, $deb;
next;
@@ -6203,6 +6206,11 @@ architecture specific symlinks
--hook-dir=/usr/share/mmdebstrap/hooks/merged-usr
+Example 4: Automatically mount all directories referenced by C mirrors
+into the chroot
+
+ --hook-dir=/usr/share/mmdebstrap/hooks/file-mirror-automount
+
=item B<--skip>=I[,I,...]
B tries hard to implement sensible defaults and will try to stop
@@ -6899,6 +6907,24 @@ inside the chroot.
--customize-hook='sync-out /var/cache/apt/archives ./cache' \
unstable /dev/null
+Instead of copying potentially large amounts of data with B you can
+also use a bind-mount in combination with a C mirror to make packages
+from the outside available inside the chroot:
+
+ $ mmdebstrap --variant=apt --skip=essential/unlink \
+ --setup-hook='mkdir "$1/tmp/mirror"' \
+ --setup-hook='mount -o ro,bind /tmp/mirror "$1/tmp/mirror"' \
+ --customize-hook='sync-out /var/cache/apt/archives ./cache' \
+ --customize-hook='umount "$1/tmp/mirror"; rmdir "$1/tmp/mirror";' \
+ unstable /dev/null file:///tmp/mirror http://deb.debian.org/debian
+
+To automatically mount all directories referenced by C mirrors
+into the chroot you can use a hook:
+
+ $ mmdebstrap --variant=apt \
+ --hook-dir=/usr/share/mmdebstrap/hooks/file-mirror-automount \
+ unstable /dev/null file:///tmp/mirror1 file:///tmp/mirror2
+
Create a system that can be used with docker:
$ mmdebstrap unstable | sudo docker import - debian