summaryrefslogtreecommitdiffstats
path: root/hooks/file-mirror-automount/setup00.sh
blob: 6ccbdaf2ba97c77c4e5223ac5280acd51a998424 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 "W: /$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