summaryrefslogtreecommitdiffstats
path: root/hooks/file-mirror-automount
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:14:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 14:14:39 +0000
commitee17e45964b786b48b455959dfe68715971893fb (patch)
tree118f40aa65dc838499053413b05adfd00f839c62 /hooks/file-mirror-automount
parentInitial commit. (diff)
downloadmmdebstrap-ee17e45964b786b48b455959dfe68715971893fb.tar.xz
mmdebstrap-ee17e45964b786b48b455959dfe68715971893fb.zip
Adding upstream version 1.4.3.upstream/1.4.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'hooks/file-mirror-automount')
-rwxr-xr-xhooks/file-mirror-automount/customize00.sh41
-rwxr-xr-xhooks/file-mirror-automount/setup00.sh73
2 files changed, 114 insertions, 0 deletions
diff --git a/hooks/file-mirror-automount/customize00.sh b/hooks/file-mirror-automount/customize00.sh
new file mode 100755
index 0000000..b6b9b46
--- /dev/null
+++ b/hooks/file-mirror-automount/customize00.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# shellcheck disable=SC2086
+
+set -eu
+
+if [ "${MMDEBSTRAP_VERBOSITY:-1}" -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"
+
+case $MMDEBSTRAP_MODE in
+ root|unshare)
+ echo "unmounting the following mountpoints:" >&2 ;;
+ *)
+ echo "removing the following directories:" >&2 ;;
+esac
+
+< "$rootdir/run/mmdebstrap/file-mirror-automount" \
+ xargs $xargsopts echo " $rootdir/{}"
+
+case $MMDEBSTRAP_MODE in
+ root|unshare)
+ < "$rootdir/run/mmdebstrap/file-mirror-automount" \
+ xargs $xargsopts umount "$rootdir/{}"
+ ;;
+ *)
+ < "$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
new file mode 100755
index 0000000..61f60f2
--- /dev/null
+++ b/hooks/file-mirror-automount/setup00.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+set -eu
+
+if [ "${MMDEBSTRAP_VERBOSITY:-1}" -ge 3 ]; then
+ set -x
+fi
+
+rootdir="$1"
+
+# process all configured apt repositories
+env APT_CONFIG="$MMDEBSTRAP_APT_CONFIG" apt-get indextargets --no-release-info --format '$(REPO_URI)' \
+ | sed -ne 's/^file:\/\+//p' \
+ | sort -u \
+ | while read -r path; do
+ mkdir -p "$rootdir/run/mmdebstrap"
+ if [ ! -d "/$path" ]; then
+ echo "/$path is not an existing directory" >&2
+ continue
+ fi
+ 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/$path"
+ "$MMDEBSTRAP_ARGV0" --hook-helper "$rootdir" "$MMDEBSTRAP_MODE" "$MMDEBSTRAP_HOOK" env "$MMDEBSTRAP_VERBOSITY" sync-in "/$path" "/$path" <&"$MMDEBSTRAP_HOOKSOCK" >&"$MMDEBSTRAP_HOOKSOCK"
+ ;;
+ esac
+ printf '/%s\0' "$path" >> "$rootdir/run/mmdebstrap/file-mirror-automount"
+ done
+
+# process all files given via --include
+set -f # turn off pathname expansion
+IFS=',' # split by comma
+for pkg in $MMDEBSTRAP_INCLUDE; do
+ set +f; unset IFS
+ case $pkg in
+ ./*|../*|/*) : ;; # we are interested in this case
+ *) continue ;; # not a file
+ esac
+ # undo escaping
+ pkg="$(printf '%s' "$pkg" | sed 's/%2C/,/g; s/%25/%/g')"
+ # check for existance
+ if [ ! -f "$pkg" ]; then
+ echo "$pkg does not exist" >&2
+ continue
+ fi
+ # make path absolute
+ pkg="$(realpath "$pkg")"
+ case "$pkg" in
+ /*) : ;;
+ *) echo "path for $pkg is not absolute" >&2; continue;;
+ esac
+ mkdir -p "$rootdir/run/mmdebstrap"
+ mkdir -p "$rootdir/$(dirname "$pkg")"
+ case $MMDEBSTRAP_MODE in
+ root|unshare)
+ echo "bind-mounting $pkg into the chroot" >&2
+ touch "$rootdir/$pkg"
+ mount -o bind "$pkg" "$rootdir/$pkg"
+ ;;
+ *)
+ echo "copying $pkg into the chroot" >&2
+ "$MMDEBSTRAP_ARGV0" --hook-helper "$rootdir" "$MMDEBSTRAP_MODE" "$MMDEBSTRAP_HOOK" env "$MMDEBSTRAP_VERBOSITY" upload "$pkg" "$pkg" <&"$MMDEBSTRAP_HOOKSOCK" >&"$MMDEBSTRAP_HOOKSOCK"
+ ;;
+ esac
+ printf '/%s\0' "$pkg" >> "$rootdir/run/mmdebstrap/file-mirror-automount"
+done
+set +f; unset IFS