summaryrefslogtreecommitdiffstats
path: root/hooks/file-mirror-automount/customize00.sh
blob: b6b9b46afdd9dad01df3abcb514475326162e42c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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"