summaryrefslogtreecommitdiffstats
path: root/tests/unshare-include-deb
blob: 2b9c54bb5287e0d6e2d5b1f2f0fe18d2f022bace (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
#!/bin/sh

set -eu
export LC_ALL=C.UTF-8

[ "{{ MODE }}" = unshare ]

trap "rm -rf /tmp/dummypkg.deb /tmp/dummypkg" EXIT INT TERM

prefix=
if [ "$(id -u)" -eq 0 ] && [ "{{ MODE }}" != "root" ] && [ "{{ MODE }}" != "auto" ]; then
	if ! id "${SUDO_USER:-user}" >/dev/null 2>&1; then
		if [ ! -e /mmdebstrap-testenv ]; then
			echo "this test modifies the system and should only be run inside a container" >&2
			exit 1
		fi
		useradd --home-dir "/home/${SUDO_USER:-user}" --create-home "${SUDO_USER:-user}"
	fi
	prefix="runuser -u ${SUDO_USER:-user} --"
fi

# instead of obtaining a .deb from our cache, we create a new package because
# otherwise apt might decide to download the package with the same name and
# version from the cache instead of using the local .deb
mkdir -p /tmp/dummypkg/DEBIAN
cat << END > "/tmp/dummypkg/DEBIAN/control"
Package: dummypkg
Priority: optional
Section: oldlibs
Maintainer: Johannes Schauer Marin Rodrigues <josch@debian.org>
Architecture: all
Multi-Arch: foreign
Source: dummypkg
Version: 1
Description: dummypkg
END
dpkg-deb --build "/tmp/dummypkg" "/tmp/dummypkg.deb"

# make the .deb only redable by its owner which will exclude the unshared user
chmod 600 /tmp/dummypkg.deb

ret=0
$prefix {{ CMD }} --variant=apt --mode={{ MODE }} --include="/tmp/dummypkg.deb" \
	{{ DIST }} /dev/null {{ MIRROR }} || ret=$?

if [ "$ret" -eq 0 ]; then
	echo "expected failure but got exit $ret" >&2
	exit 1
fi