forked from ArrayBolt3/privleap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_autopkgtest
executable file
·126 lines (113 loc) · 3.71 KB
/
run_autopkgtest
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.
set -o errexit
set -o nounset
set -o errtrace
set -o pipefail
privleap_project_dir="$(dirname "$(readlink -f "${0}")")"
target_distribution="bookworm"
autopkgtest_tarball_path="${HOME}/.cache/sbuild/${target_distribution}-amd64.tar.zst"
create_autopkgtest_tarball() {
mkdir -p ~/.cache/sbuild
sudo mmdebstrap \
--include=ca-certificates \
--skip=output/dev \
--variant=buildd \
"${target_distribution}" \
"${autopkgtest_tarball_path}" \
--customize-hook='chroot "$1" passwd --delete root' \
--customize-hook='chroot "$1" useradd --home-dir /home/user --create-home user' \
--customize-hook='chroot "$1" passwd --delete user' \
--customize-hook='cp /etc/hosts "$1/etc/hosts"' \
--customize-hook=/usr/share/autopkgtest/setup-commands/setup-testbed \
https://deb.debian.org/debian
}
offer_package_install() {
local pkg_name install_yn
pkg_name="$1"
1>&2 echo "${pkg_name} is not installed, but is needed to run the test suite."
1>&2 echo -n 'Would you like to install it now? [y/N] '
read -r install_yn
if [ "${install_yn,,}" = 'y' ]; then
sudo apt-get install "${pkg_name}"
else
1>&2 echo 'Test run aborted.'
exit 1
fi
}
print_usage() {
local help_info
help_info='run_autopkgtest: Runs regression tests for privleap using autopkgtest
Usage:
run_autopkgtest [--reset-tarball]
Options:
--reset-tarball: Deletes and recreates the tarball used by unshare
for running the tests.'
1>&2 echo "${help_info}"
}
run_autopkgtest() {
local arg
arg="${1:-}"
if [ "${arg}" = '--help' ] || [ "${arg}" = '-h' ] || [ "${arg}" = '-?' ]; then
print_usage
exit 0
fi
if [ "$(id -u)" = '0' ]; then
1>&2 echo 'Do not run this script as root!'
exit 1
fi
if [ "${arg}" = '--reset-tarball' ]; then
rm -f "${autopkgtest_tarball_path}"
elif [ -n "${arg}" ]; then
1>&2 echo "Unrecognized argument: '${arg}'. Try 'run_autopkgtest --help' for usage info."
exit 1
fi
## Dependency checks
if ! [ -x '/usr/bin/unshare' ]; then
1>&2 echo 'unshare is not executable or does not exist!'
exit 1
fi
if ! [ -f '/usr/bin/autopkgtest' ]; then
offer_package_install 'autopkgtest'
fi
if ! [ -f '/usr/bin/mmdebstrap' ]; then
offer_package_install 'mmdebstrap'
fi
if ! [ -f '/usr/bin/dh' ]; then
offer_package_install 'debhelper'
fi
if ! [ -f '/usr/share/keyrings/debian-archive-bookworm-stable.gpg' ]; then
offer_package_install 'debian-archive-keyring'
fi
if [ "$(basename "${privleap_project_dir}")" != 'privleap' ]; then
1>&2 echo 'The run_autopkgtest script does not appear to be in the root of the privleap source tree!'
exit 1
fi
if [ "$(stat -c "%u|%a" /usr/bin/newuidmap)" != '0|4755' ]; then
1>&2 echo 'autopkgtest requires /usr/bin/newuidmap to be SUID-root!'
exit 1
fi
if [ "$(stat -c "%u|%a" /usr/bin/newgidmap)" != '0|4755' ]; then
1>&2 echo 'autopkgtest requires /usr/bin/newgidmap to be SUID-root!'
exit 1
fi
if [ "$(pwd)" != "${privleap_project_dir}" ]; then
cd "${privleap_project_dir}" >/dev/null || {
1>&2 echo 'Cannot change to privleap source tree directory!'
exit 1
}
fi
if ! [ -f "${autopkgtest_tarball_path}" ]; then
create_autopkgtest_tarball
fi
dpkg-buildpackage -i -us -uc -b || {
1>&2 echo 'Cannot build privleap deb package!'
exit 1
}
cd ..
autopkgtest -l "${privleap_project_dir}/privleap-test-log.txt" \
--apt-upgrade -B privleap*.deb "${privleap_project_dir}" -- unshare
echo "Test complete. Results are stored in ${privleap_project_dir}/privleap-test-log.txt."
}
run_autopkgtest "$@"