summaryrefslogtreecommitdiffstats
path: root/debian/tests/shared-functions.sh
blob: 13797d0a3cdcb15ff938a6b27a0917d032ab05c4 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# shellcheck shell=dash

check_line () {
	local db="$1"
	local expected_services="$2"

	local expected_line="$db:    $expected_services"
	local new_line

	if ! new_line=$(grep "^$1:" /etc/nsswitch.conf) ; then
		echo "ERROR: DB $db not found in /etc/nsswitch.conf" >&2
		exit 2
	fi

	local num_db_lines
	num_db_lines="$(echo "$new_line" | wc -l)"
	if [ "$num_db_lines" -ne 1 ] ; then
		echo "ERROR: Too many lines for DB $db: $num_db_lines" >&2
		exit 3
	fi

	if [ "$new_line" != "$expected_line" ] ; then
		echo "ERROR: Wrong db line in /etc/nsswitch.conf" >&2
		echo "   found: \`$new_line'" >&2
		echo "expected: \`$expected_line'" >&2
		exit 4
	fi

	echo "OK"
}


setup_pkg () {
	local pkgname=$1
	local testname=$2

	mkdir debian

	cat <<EOF > debian/control
Source: $pkgname
Section: devel
Priority: optional
Maintainer: Test User <test@example.org>
Rules-Requires-Root: no
Build-Depends: debhelper-compat (= 13), dh-sequence-installnss
Standards-Version: 4.6.1

Package: $pkgname
Architecture: all
Description: Test package for dh-nss ($testname)
 Test package for dh-nss ($testname)
EOF

	cat <<EOF > debian/rules
#!/usr/bin/make -f
%:
	dh \$@
EOF
	chmod +x debian/rules
}

build_pkg () {
	pkgname="$1"
	pkgversion="$2"
	nss_lines="$3"

	echo "$nss_lines" > debian/nss

	cat <<EOF > debian/changelog
$pkgname ($pkgversion) unstable; urgency=medium

  * Test build

 -- Test User <test@example.org>  Sun, 06 Aug 2022 11:22:33 +0200
EOF

	dpkg-buildpackage --no-sign --build=binary
}

NSSWITCH_CONF="
# /etc/nsswitch.conf

passwd:         files
group:          files
shadow:         files
gshadow:        files

hosts:    files dns
networks: files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis"