]>
Commit | Line | Data |
---|---|---|
8d876415 DK |
1 | #!/bin/sh -- # no runable script, just for vi |
2 | ||
5d76cee1 | 3 | EXIT_CODE=0 |
8c1dd12c | 4 | |
68042532 DK |
5 | while [ -n "$1" ]; do |
6 | if [ "$1" = "-q" ]; then | |
7 | export MSGLEVEL=2 | |
8 | elif [ "$1" = "-v" ]; then | |
9 | export MSGLEVEL=4 | |
10 | elif [ "$1" = '--color=no' ]; then | |
11 | export MSGCOLOR='NO' | |
61e92778 DK |
12 | elif [ "$1" = '--color=yes' ]; then |
13 | export MSGCOLOR='YES' | |
14 | elif [ "$1" = '--color' ]; then | |
15 | export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')" | |
16 | shift | |
17 | elif [ "$1" = '--level' ]; then | |
18 | export MSGLEVEL=$2 | |
19 | shift | |
68042532 DK |
20 | else |
21 | echo >&2 "WARNING: Unknown parameter »$1« will be ignored" | |
22 | fi | |
23 | shift | |
24 | done | |
25 | export MSGLEVEL="${MSGLEVEL:-3}" | |
26 | ||
8d876415 | 27 | # we all like colorful messages |
61e92778 | 28 | if [ "${MSGCOLOR:-YES}" = 'YES' ]; then |
27cb4f6c | 29 | if [ ! -t 1 ]; then # but check that we output to a terminal |
1290422a DK |
30 | export MSGCOLOR='NO' |
31 | fi | |
32 | fi | |
33 | ||
34 | ||
35 | if [ "$MSGCOLOR" != 'NO' ]; then | |
36 | CERROR="\033[1;31m" # red | |
37 | CWARNING="\033[1;33m" # yellow | |
38 | CMSG="\033[1;32m" # green | |
39 | CINFO="\033[1;96m" # light blue | |
40 | CDEBUG="\033[1;94m" # blue | |
41 | CNORMAL="\033[0;39m" # default system console color | |
42 | CDONE="\033[1;32m" # green | |
43 | CPASS="\033[1;32m" # green | |
44 | CFAIL="\033[1;31m" # red | |
45 | CCMD="\033[1;35m" # pink | |
682a3bf7 | 46 | fi |
8d876415 | 47 | |
de81b2e2 DK |
48 | msgprintf() { |
49 | local START="$1" | |
50 | local MIDDLE="$2" | |
51 | local END="$3" | |
52 | shift 3 | |
53 | if [ -n "$1" ]; then | |
54 | printf "$START " "$1" | |
d73840dc | 55 | shift |
de81b2e2 | 56 | while [ -n "$1" ]; do |
bc8f83a5 | 57 | printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')" |
de81b2e2 DK |
58 | shift |
59 | done | |
60 | fi | |
61 | printf "${END}" | |
2a2a7ef4 | 62 | } |
de81b2e2 DK |
63 | msgdie() { msgprintf "${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; } |
64 | msgwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; } | |
65 | msgmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; } | |
66 | msginfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; } | |
67 | msgdebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; } | |
68 | msgdone() { msgprintf "${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; } | |
69 | msgnwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; } | |
70 | msgnmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@"; } | |
71 | msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; } | |
72 | msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; } | |
73 | msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; } | |
3c528b91 | 74 | msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; } |
1501a2c9 | 75 | msgreportheader() { |
68042532 | 76 | if [ -n "$MSGTEST_MSG" ]; then |
1501a2c9 | 77 | test "$1" != 'msgfailoutput' || echo |
ae7fce5a DK |
78 | if [ -n "$MSGTEST_MSGMSG" ]; then |
79 | echo "$MSGTEST_MSGMSG" | |
80 | fi | |
22ac12b2 | 81 | if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then |
1501a2c9 | 82 | echo "${CFAIL}Part of the test group: $MSGTEST_GRP" |
22ac12b2 | 83 | fi |
68042532 DK |
84 | echo -n "$MSGTEST_MSG" |
85 | unset MSGTEST_MSG | |
86 | fi | |
1501a2c9 DK |
87 | } |
88 | msgskip() { | |
89 | msgreportheader 'msgskip' | |
68ba0b7f DK |
90 | if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2; |
91 | else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi | |
92 | } | |
5229b285 | 93 | msgfail() { |
1501a2c9 | 94 | msgreportheader 'msgfail' |
68042532 | 95 | if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2; |
3c528b91 | 96 | else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi |
03aa0847 | 97 | if [ -n "$APT_DEBUG_TESTS" ]; then |
896f0ae8 | 98 | runapt $SHELL |
03aa0847 | 99 | fi |
5229b285 DK |
100 | EXIT_CODE=$((EXIT_CODE+1)); |
101 | } | |
9beb11aa DK |
102 | MSGGROUP_LEVEL=0 |
103 | msggroup() { | |
104 | if [ -n "$1" ]; then | |
105 | if [ $MSGGROUP_LEVEL = 0 ]; then | |
106 | MSGTEST_GRP='NEXT' | |
107 | fi | |
108 | MSGGROUP_LEVEL=$((MSGGROUP_LEVEL+1)); | |
109 | else | |
110 | MSGGROUP_LEVEL=$((MSGGROUP_LEVEL-1)); | |
111 | if [ $MSGGROUP_LEVEL = 0 ]; then | |
112 | unset MSGTEST_GRP | |
113 | fi | |
114 | fi | |
115 | } | |
8d876415 DK |
116 | |
117 | # enable / disable Debugging | |
fc89263e DK |
118 | if [ $MSGLEVEL -le 0 ]; then |
119 | msgdie() { true; } | |
120 | fi | |
121 | if [ $MSGLEVEL -le 1 ]; then | |
122 | msgwarn() { true; } | |
123 | msgnwarn() { true; } | |
124 | fi | |
125 | if [ $MSGLEVEL -le 2 ]; then | |
ae7fce5a DK |
126 | msgmsg() { |
127 | MSGTEST_MSGMSG="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")" | |
128 | } | |
fc89263e | 129 | msgnmsg() { true; } |
9beb11aa DK |
130 | msgtest() { |
131 | MSGTEST_MSG="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")" | |
132 | if [ "$MSGTEST_GRP" = 'NEXT' ]; then | |
133 | MSGTEST_GRP="$MSGTEST_MSG" | |
134 | fi | |
135 | } | |
3c528b91 | 136 | msgpass() { printf " ${CPASS}P${CNORMAL}"; } |
fc89263e DK |
137 | fi |
138 | if [ $MSGLEVEL -le 3 ]; then | |
139 | msginfo() { true; } | |
140 | msgninfo() { true; } | |
141 | fi | |
142 | if [ $MSGLEVEL -le 4 ]; then | |
143 | msgdebug() { true; } | |
144 | msgndebug() { true; } | |
145 | fi | |
146 | msgdone() { | |
147 | if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] || | |
148 | [ "$1" = "info" -a $MSGLEVEL -le 3 ] || | |
149 | [ "$1" = "msg" -a $MSGLEVEL -le 2 ] || | |
150 | [ "$1" = "warn" -a $MSGLEVEL -le 1 ] || | |
151 | [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then | |
152 | true; | |
153 | else | |
3c528b91 | 154 | printf "${CDONE}DONE${CNORMAL}\n"; |
fc89263e DK |
155 | fi |
156 | } | |
e43a426e MV |
157 | getaptconfig() { |
158 | if [ -f ./aptconfig.conf ]; then | |
5465192b | 159 | echo "$(readlink -f ./aptconfig.conf)" |
e43a426e | 160 | elif [ -f ../aptconfig.conf ]; then |
5465192b DK |
161 | echo "$(readlink -f ../aptconfig.conf)" |
162 | elif [ -f ../../aptconfig.conf ]; then | |
163 | echo "$(readlink -f ../../aptconfig.conf)" | |
164 | elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then | |
165 | echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")" | |
166 | fi | |
e43a426e | 167 | } |
8d876415 DK |
168 | runapt() { |
169 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
846856f4 DK |
170 | local CMD="$1" |
171 | shift | |
3abb6a6a | 172 | case "$CMD" in |
a311fb96 | 173 | sh|aptitude|*/*|command) ;; |
3b8eb3bc DK |
174 | *) CMD="${BUILDDIRECTORY}/$CMD";; |
175 | esac | |
896f0ae8 | 176 | MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@" |
8d876415 | 177 | } |
846856f4 DK |
178 | aptconfig() { runapt apt-config "$@"; } |
179 | aptcache() { runapt apt-cache "$@"; } | |
180 | aptcdrom() { runapt apt-cdrom "$@"; } | |
181 | aptget() { runapt apt-get "$@"; } | |
182 | aptftparchive() { runapt apt-ftparchive "$@"; } | |
183 | aptkey() { runapt apt-key "$@"; } | |
184 | aptmark() { runapt apt-mark "$@"; } | |
4f6d26b4 | 185 | aptsortpkgs() { runapt apt-sortpkgs "$@"; } |
796673c3 | 186 | apt() { runapt apt "$@"; } |
3b8eb3bc DK |
187 | apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; } |
188 | aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; } | |
189 | aptitude() { runapt aptitude "$@"; } | |
8d50b63f | 190 | aptextracttemplates() { runapt apt-extracttemplates "$@"; } |
3082603f | 191 | aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; } |
ad7e0941 | 192 | aptdumpsolver() { runapt "${APTDUMPSOLVER}" "$@"; } |
3b8eb3bc | 193 | |
158fda31 | 194 | dpkg() { |
b0be0e09 | 195 | "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@" |
158fda31 | 196 | } |
ce7f128c | 197 | dpkgcheckbuilddeps() { |
63c71412 | 198 | command dpkg-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@" |
b6b5a542 | 199 | } |
3fa950f1 | 200 | gdb() { |
b07aeb1a DK |
201 | local CMD |
202 | case "$1" in | |
203 | aptget) CMD="apt-get";; | |
204 | aptcache) CMD="apt-cache";; | |
5465192b DK |
205 | aptcdrom) CMD="apt-cdrom";; |
206 | aptconfig) CMD="apt-config";; | |
b07aeb1a DK |
207 | aptmark) CMD="apt-mark";; |
208 | apthelper) CMD="apt-helper";; | |
3d8232bf | 209 | aptftparchive) CMD="apt-ftparchive";; |
63c71412 | 210 | dpkg) shift; runapt "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;; |
b07aeb1a DK |
211 | *) CMD="$1";; |
212 | esac | |
ce928105 | 213 | shift |
921a9626 DK |
214 | if [ "${CMD##*/}" = "$CMD" ]; then |
215 | CMD="${BUILDDIRECTORY}/${CMD}" | |
216 | fi | |
217 | runapt command gdb --quiet -ex run "$CMD" --args "$CMD" "$@" | |
ae99ce2e | 218 | } |
8d876415 | 219 | |
8c1dd12c | 220 | exitwithstatus() { |
f91bd741 MV |
221 | # error if we about to overflow, but ... |
222 | # "255 failures ought to be enough for everybody" | |
5d76cee1 MV |
223 | if [ $EXIT_CODE -gt 255 ]; then |
224 | msgdie "Total failure count $EXIT_CODE too big" | |
f91bd741 | 225 | fi |
5d76cee1 | 226 | exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255)); |
8c1dd12c MV |
227 | } |
228 | ||
804d4a0d DK |
229 | shellsetedetector() { |
230 | local exit_status=$? | |
231 | if [ "$exit_status" != '0' ]; then | |
3c528b91 | 232 | printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n" |
804d4a0d DK |
233 | if [ "$EXIT_CODE" = '0' ]; then |
234 | EXIT_CODE="$exit_status" | |
235 | fi | |
236 | fi | |
237 | } | |
238 | ||
b720d0bd | 239 | addtrap() { |
8437b7d4 DK |
240 | if [ "$1" = 'prefix' ]; then |
241 | CURRENTTRAP="$2 $CURRENTTRAP" | |
242 | else | |
243 | CURRENTTRAP="$CURRENTTRAP $1" | |
244 | fi | |
804d4a0d | 245 | trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM |
b720d0bd | 246 | } |
8d876415 | 247 | |
bc8f83a5 DK |
248 | escape_shell() { |
249 | echo "$@" | sed -e "s#'#'\"'\"'#g" | |
250 | } | |
251 | ||
8d876415 | 252 | setupenvironment() { |
0d303f17 DK |
253 | # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir) |
254 | if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then | |
255 | unset TMPDIR | |
256 | fi | |
63c71412 | 257 | TMPWORKINGDIRECTORY="$(mktemp -d)" |
bc8f83a5 DK |
258 | addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';" |
259 | if [ -n "$TMPDIR_ADD" ]; then | |
260 | TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}" | |
261 | mkdir -p "$TMPWORKINGDIRECTORY" | |
262 | unset TMPDIR_ADD | |
263 | export TMPDIR="$TMPWORKINGDIRECTORY" | |
264 | fi | |
63c71412 | 265 | msgninfo "Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…" |
5c0dd6fc | 266 | |
03aa0847 | 267 | mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded" |
68ba0b7f DK |
268 | if [ "$(id -u)" = '0' ]; then |
269 | # relax permissions so that running as root with user switching works | |
270 | umask 022 | |
03aa0847 DK |
271 | chmod 711 "$TMPWORKINGDIRECTORY" |
272 | chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded" | |
68ba0b7f DK |
273 | fi |
274 | ||
63c71412 | 275 | TESTDIRECTORY="$(readlink -f "$(dirname $0)")" |
5c0dd6fc | 276 | # allow overriding the default BUILDDIR location |
63c71412 DK |
277 | SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}" |
278 | BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}" | |
279 | LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}" | |
280 | METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}" | |
281 | APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}" | |
282 | APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}" | |
283 | APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}" | |
284 | APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}" | |
8d876415 | 285 | test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" |
5c0dd6fc MV |
286 | # ----- |
287 | ||
63c71412 | 288 | cd "$TMPWORKINGDIRECTORY" |
cd725954 | 289 | mkdir rootdir aptarchive keys |
8d876415 | 290 | cd rootdir |
b29c3712 | 291 | mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d |
8fe964f1 | 292 | mkdir -p usr/bin var/cache var/lib var/log tmp |
cffea9af | 293 | mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers |
cd725954 | 294 | touch var/lib/dpkg/available |
8d876415 | 295 | mkdir -p usr/lib/apt |
63c71412 | 296 | ln -s "${METHODSDIR}" usr/lib/apt/methods |
1f6cf9e7 DK |
297 | if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then |
298 | mkdir -p usr/lib/apt/solvers | |
299 | ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump | |
300 | ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt | |
301 | echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc/apt/apt.conf.d/externalsolver.conf | |
302 | fi | |
291a386f MV |
303 | # use the autoremove from the BUILDDIRECTORY if its there, otherwise |
304 | # system | |
63c71412 DK |
305 | if [ -e "${BUILDDIRECTORY}/../../debian/apt.conf.autoremove" ]; then |
306 | ln -s "${BUILDDIRECTORY}/../../debian/apt.conf.autoremove" etc/apt/apt.conf.d/01autoremove | |
291a386f MV |
307 | else |
308 | ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove | |
309 | fi | |
8d876415 | 310 | cd .. |
63c71412 DK |
311 | local BASENAME="${0##*/}" |
312 | local PACKAGESFILE="Packages-${BASENAME#*-}" | |
53ea1b56 DK |
313 | if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then |
314 | cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages | |
8f8169ac | 315 | fi |
63c71412 | 316 | local SOURCESSFILE="Sources-${BASENAME#*-}" |
53ea1b56 DK |
317 | if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then |
318 | cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources | |
8f8169ac | 319 | fi |
3abb6a6a DK |
320 | find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \; |
321 | chmod 644 keys/* | |
63c71412 | 322 | ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg |
d6cf2345 | 323 | |
cffea9af | 324 | echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf |
94eb3bee | 325 | echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf |
8d876415 | 326 | echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf |
9d2a8a73 | 327 | echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf |
23e64f6d DK |
328 | # either store apt-key were we can access it, even if we run it as a different user |
329 | #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/" | |
330 | #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key" | |
331 | #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf | |
332 | # destroys coverage reporting though, so we disable changing user for the calling gpgv | |
333 | echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf | |
68ba0b7f | 334 | if [ "$(id -u)" = '0' ]; then |
23e64f6d | 335 | echo 'Binary::gpgv::Debug::NoDropPrivs "true";' >>aptconfig.conf |
68ba0b7f | 336 | fi |
b0be0e09 | 337 | |
63c71412 | 338 | cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF |
b0be0e09 DK |
339 | #!/bin/sh |
340 | set -e | |
3abb6a6a | 341 | if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then |
63c71412 | 342 | if [ -n "\$LD_LIBRARY_PATH" ]; then |
3abb6a6a | 343 | export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\${LD_LIBRARY_PATH}" |
b0be0e09 | 344 | else |
3abb6a6a | 345 | export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}' |
b0be0e09 | 346 | fi |
921a9626 | 347 | if [ -n "\$LD_PRELOAD" ]; then |
63c71412 | 348 | export LD_PRELOAD="noopchroot.so \${LD_PRELOAD}" |
921a9626 | 349 | else |
63c71412 | 350 | export LD_PRELOAD="noopchroot.so" |
921a9626 DK |
351 | fi |
352 | fi | |
63c71412 DK |
353 | EOF |
354 | cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" | |
355 | cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF | |
3abb6a6a DK |
356 | exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\ |
357 | --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\ | |
63c71412 DK |
358 | --force-not-root --force-bad-path "\$@" |
359 | EOF | |
360 | cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF | |
3abb6a6a DK |
361 | exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\ |
362 | --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\ | |
b0be0e09 DK |
363 | --force-not-root --force-bad-path "\$@" |
364 | EOF | |
921a9626 | 365 | chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" |
b0be0e09 DK |
366 | echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg |
367 | ||
533fe3d1 DK |
368 | { |
369 | if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then | |
370 | echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it… | |
371 | fi | |
87d6947d | 372 | echo 'quiet "0";' |
533fe3d1 DK |
373 | echo 'quiet::NoUpdate "true";' |
374 | echo 'quiet::NoStatistic "true";' | |
375 | # too distracting for users, but helpful to detect changes | |
376 | echo 'Acquire::Progress::Ignore::ShowErrorText "true";' | |
377 | echo 'Acquire::Progress::Diffpercent "true";' | |
378 | # in testcases, it can appear as if localhost has a rotation setup, | |
379 | # hide this as we can't really deal with it properly | |
380 | echo 'Acquire::Failure::ShowIP "false";' | |
ebca2f25 DK |
381 | # fakeroot can't fake everything, so disabled in production but good for tests |
382 | echo 'APT::Sandbox::Verify "true";' | |
533fe3d1 | 383 | } >> aptconfig.conf |
d6cf2345 | 384 | |
68ba0b7f DK |
385 | cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" |
386 | if [ "$(id -u)" = '0' ]; then | |
387 | chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" | |
388 | fi | |
389 | echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https | |
d6cf2345 | 390 | echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary |
23d35ec1 | 391 | echo 'Acquire::Connect::AddrConfig "false";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig |
276e51dd | 392 | configcompression '.' 'gz' #'bz2' 'lzma' 'xz' |
c5ede4ca | 393 | confighashes 'SHA1' # these are tests, not security best-practices |
77a45beb | 394 | |
4bb006d1 | 395 | # create some files in /tmp and look at user/group to get what this means |
eab57e08 | 396 | TEST_DEFAULT_USER="$(id -un)" |
4bb006d1 DK |
397 | if [ "$(uname)" = 'GNU/kFreeBSD' ]; then |
398 | TEST_DEFAULT_GROUP='root' | |
399 | else | |
eab57e08 | 400 | TEST_DEFAULT_GROUP="$(id -gn)" |
4bb006d1 DK |
401 | fi |
402 | ||
ce7f128c | 403 | # cleanup the environment a bit |
995a4bf6 | 404 | # prefer our apt binaries over the system apt binaries |
8c617819 | 405 | export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin" |
be233796 | 406 | export LC_ALL=C.UTF-8 |
3b8eb3bc | 407 | unset LANGUAGE APT_CONFIG |
ce7f128c | 408 | unset GREP_OPTIONS DEB_BUILD_PROFILES |
59f57473 | 409 | unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy |
8d876415 DK |
410 | msgdone "info" |
411 | } | |
412 | ||
ea65d079 DK |
413 | getarchitecture() { |
414 | if [ "$1" = "native" -o -z "$1" ]; then | |
415 | eval `aptconfig shell ARCH APT::Architecture` | |
416 | if [ -n "$ARCH" ]; then | |
417 | echo $ARCH | |
418 | else | |
5834d7a1 | 419 | dpkg --print-architecture |
ea65d079 DK |
420 | fi |
421 | else | |
422 | echo $1 | |
423 | fi | |
424 | } | |
425 | ||
53ea1b56 | 426 | getarchitectures() { |
081c9d44 | 427 | aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' ' |
53ea1b56 DK |
428 | } |
429 | ||
3dcdc1f9 DK |
430 | getarchitecturesfromcommalist() { |
431 | echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/" | |
432 | } | |
433 | ||
8d876415 | 434 | configarchitecture() { |
18908589 DK |
435 | { |
436 | echo "APT::Architecture \"$(getarchitecture $1)\";" | |
437 | while [ -n "$1" ]; do | |
438 | echo "APT::Architectures:: \"$(getarchitecture $1)\";" | |
439 | shift | |
440 | done | |
441 | } >rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
53ea1b56 DK |
442 | configdpkg |
443 | } | |
444 | ||
445 | configdpkg() { | |
446 | if [ ! -e rootdir/var/lib/dpkg/status ]; then | |
63c71412 DK |
447 | local BASENAME="${0##*/}" |
448 | local STATUSFILE="status-${BASENAME#*-}" | |
53ea1b56 DK |
449 | if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then |
450 | cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status | |
451 | else | |
452 | echo -n > rootdir/var/lib/dpkg/status | |
453 | fi | |
454 | fi | |
18908589 | 455 | rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg |
846856f4 | 456 | if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then |
53ea1b56 DK |
457 | local ARCHS="$(getarchitectures)" |
458 | if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then | |
459 | DPKGARCH="$(dpkg --print-architecture)" | |
460 | for ARCH in ${ARCHS}; do | |
feae193b | 461 | if [ "${ARCH}" != "${DPKGARCH}" ]; then |
18908589 | 462 | if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then |
feae193b | 463 | # old-style used e.g. in Ubuntu-P – and as it seems travis |
18908589 DK |
464 | echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg |
465 | echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg | |
feae193b DK |
466 | fi |
467 | fi | |
53ea1b56 DK |
468 | done |
469 | if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then | |
05343a22 DK |
470 | # dpkg doesn't really check the version as long as it is fully installed, |
471 | # but just to be sure we choose one above the required version | |
472 | insertinstalledpackage 'dpkg' "all" '1.16.2+fake' | |
53ea1b56 DK |
473 | fi |
474 | fi | |
475 | fi | |
8d876415 DK |
476 | } |
477 | ||
0c787570 DK |
478 | configdpkgnoopchroot() { |
479 | # create a library to noop chroot() and rewrite maintainer script executions | |
480 | # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown | |
481 | # chroot directory dpkg could chroot into to execute the maintainer scripts | |
482 | msgtest 'Building library to preload to make maintainerscript work in' 'dpkg' | |
63c71412 | 483 | cat > noopchroot.c << EOF |
0c787570 DK |
484 | #define _GNU_SOURCE |
485 | #include <stdio.h> | |
486 | #include <stdlib.h> | |
487 | #include <string.h> | |
488 | #include <dlfcn.h> | |
489 | ||
490 | static char * chrootdir = NULL; | |
491 | ||
492 | int chroot(const char *path) { | |
493 | printf("WARNING: CHROOTing to %s was ignored!\n", path); | |
494 | free(chrootdir); | |
495 | chrootdir = strdup(path); | |
496 | return 0; | |
497 | } | |
498 | int execvp(const char *file, char *const argv[]) { | |
499 | static int (*func_execvp) (const char *, char * const []) = NULL; | |
500 | if (func_execvp == NULL) | |
501 | func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp"); | |
502 | if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0) | |
503 | return func_execvp(file, argv); | |
504 | printf("REWRITE execvp call %s into %s\n", file, chrootdir); | |
950733c9 JAK |
505 | char *newfile; |
506 | if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) { | |
507 | perror("asprintf"); | |
508 | return -1; | |
509 | } | |
b0be0e09 | 510 | char const * const baseadmindir = "/var/lib/dpkg"; |
950733c9 JAK |
511 | char *admindir; |
512 | if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) { | |
513 | perror("asprintf"); | |
514 | return -1; | |
515 | } | |
b0be0e09 | 516 | setenv("DPKG_ADMINDIR", admindir, 1); |
0c787570 DK |
517 | return func_execvp(newfile, argv); |
518 | } | |
519 | EOF | |
950733c9 | 520 | testsuccess --nomsg gcc -Wall -fPIC -shared -o noopchroot.so noopchroot.c -ldl |
0c787570 | 521 | } |
276e51dd | 522 | configcompression() { |
abec2980 | 523 | local CMD='apthelper cat-file -C' |
276e51dd DK |
524 | while [ -n "$1" ]; do |
525 | case "$1" in | |
3c528b91 | 526 | '.') printf ".\t.\tcat\n";; |
abec2980 DK |
527 | 'gz') printf "gzip\tgz\t$CMD $1\n";; |
528 | 'bz2') printf "bzip2\tbz2\t$CMD $1\n";; | |
529 | *) printf "$1\t$1\t$CMD $1\n";; | |
276e51dd DK |
530 | esac |
531 | shift | |
63c71412 | 532 | done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" |
276e51dd | 533 | } |
c5ede4ca DK |
534 | confighashes() { |
535 | { | |
536 | echo 'APT::FTPArchive {' | |
537 | { | |
538 | while [ -n "$1" ]; do | |
539 | printf "$1" | tr 'a-z' 'A-Z' | |
540 | printf "\t\"true\";\n" | |
541 | shift | |
542 | done | |
543 | for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do | |
544 | printf "$h\t\"false\";\n" | |
545 | done | |
546 | } | awk '!x[$1]++' | |
547 | echo '};' | |
548 | } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf" | |
549 | } | |
5f982b9d DK |
550 | forcecompressor() { |
551 | COMPRESSOR="$1" | |
912a6131 | 552 | COMPRESS="$1" |
abec2980 | 553 | COMPRESSOR_CMD="apthelper cat-file -C $1" |
5f982b9d DK |
554 | case $COMPRESSOR in |
555 | gzip) COMPRESS='gz';; | |
556 | bzip2) COMPRESS='bz2';; | |
5f982b9d DK |
557 | esac |
558 | local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor" | |
559 | echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; }; | |
912a6131 | 560 | Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE" |
5f982b9d DK |
561 | } |
562 | ||
75954ae2 | 563 | setupsimplenativepackage() { |
ce9864a8 DK |
564 | local NAME="$1" |
565 | local ARCH="$2" | |
566 | local VERSION="$3" | |
567 | local RELEASE="${4:-unstable}" | |
568 | local DEPENDENCIES="$5" | |
14109555 | 569 | local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} |
18908589 DK |
570 | If you find such a package installed on your system, |
571 | something went horribly wrong! They are autogenerated | |
3d284148 | 572 | und used only by testcases and serve no other purpose…"}" |
18908589 | 573 | |
b7899b00 DK |
574 | local SECTION="${7:-others}" |
575 | local DISTSECTION | |
63c71412 | 576 | if [ "$SECTION" = "${SECTION#*/}" ]; then |
b7899b00 DK |
577 | DISTSECTION="main" |
578 | else | |
63c71412 | 579 | DISTSECTION="${SECTION%/*}" |
b7899b00 | 580 | fi |
ce9864a8 DK |
581 | local BUILDDIR=incoming/${NAME}-${VERSION} |
582 | mkdir -p ${BUILDDIR}/debian/source | |
583 | cd ${BUILDDIR} | |
584 | echo "* most suckless software product ever" > FEATURES | |
b7899b00 DK |
585 | test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright |
586 | test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low | |
ce9864a8 DK |
587 | |
588 | * Initial release | |
589 | ||
b7899b00 DK |
590 | -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog |
591 | test -e debian/control || echo "Source: $NAME | |
592 | Section: $SECTION | |
ce9864a8 DK |
593 | Priority: optional |
594 | Maintainer: Joe Sixpack <joe@example.org> | |
595 | Build-Depends: debhelper (>= 7) | |
596 | Standards-Version: 3.9.1 | |
597 | ||
875bcb36 DK |
598 | Package: $NAME" > debian/control |
599 | if [ "$ARCH" = 'all' ]; then | |
600 | echo "Architecture: all" >> debian/control | |
601 | else | |
602 | echo "Architecture: any" >> debian/control | |
603 | fi | |
ce9864a8 | 604 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control |
18908589 DK |
605 | echo "Description: $DESCRIPTION" >> debian/control |
606 | ||
b7899b00 DK |
607 | test -e debian/compat || echo "7" > debian/compat |
608 | test -e debian/source/format || echo "3.0 (native)" > debian/source/format | |
ce9864a8 | 609 | test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules |
75954ae2 DK |
610 | cd - > /dev/null |
611 | } | |
612 | ||
613 | buildsimplenativepackage() { | |
614 | local NAME="$1" | |
d56e2917 DK |
615 | local NM |
616 | if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then | |
617 | NM="$(echo "$NAME" | cut -c 1-4)" | |
618 | else | |
619 | NM="$(echo "$NAME" | cut -c 1)" | |
620 | fi | |
75954ae2 DK |
621 | local ARCH="$2" |
622 | local VERSION="$3" | |
623 | local RELEASE="${4:-unstable}" | |
624 | local DEPENDENCIES="$5" | |
14109555 | 625 | local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} |
18908589 DK |
626 | If you find such a package installed on your system, |
627 | something went horribly wrong! They are autogenerated | |
3d284148 | 628 | und used only by testcases and serve no other purpose…"}" |
18908589 | 629 | |
75954ae2 | 630 | local SECTION="${7:-others}" |
d67004e0 | 631 | local PRIORITY="${8:-optional}" |
63c71412 DK |
632 | local FILE_TREE="$9" |
633 | local COMPRESS_TYPE="${10:-gzip}" | |
75954ae2 | 634 | local DISTSECTION |
63c71412 | 635 | if [ "$SECTION" = "${SECTION#*/}" ]; then |
75954ae2 DK |
636 | DISTSECTION="main" |
637 | else | |
63c71412 | 638 | DISTSECTION="${SECTION%/*}" |
75954ae2 | 639 | fi |
63c71412 | 640 | local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}" |
b761356f | 641 | |
0c787570 | 642 | msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME" |
63c71412 DK |
643 | mkdir -p "$BUILDDIR/debian/source" |
644 | echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES" | |
b761356f | 645 | echo "#!/bin/sh |
63c71412 | 646 | echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}" |
b761356f | 647 | |
63c71412 | 648 | echo "Copyleft by Joe Sixpack $(date +%Y)" > "${BUILDDIR}/debian/copyright" |
b761356f DK |
649 | echo "$NAME ($VERSION) $RELEASE; urgency=low |
650 | ||
651 | * Initial release | |
652 | ||
63c71412 DK |
653 | -- Joe Sixpack <joe@example.org> $(date -R)" > "${BUILDDIR}/debian/changelog" |
654 | { | |
655 | echo "Source: $NAME | |
d67004e0 | 656 | Priority: $PRIORITY |
b761356f | 657 | Maintainer: Joe Sixpack <joe@example.org> |
63c71412 DK |
658 | Standards-Version: 3.9.3" |
659 | if [ "$SECTION" != '<none>' ]; then | |
660 | echo "Section: $SECTION" | |
661 | fi | |
662 | local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')" | |
663 | test -z "$BUILDDEPS" || echo "$BUILDDEPS" | |
664 | echo " | |
665 | Package: $NAME" | |
b761356f | 666 | |
63c71412 DK |
667 | if [ "$ARCH" = 'all' ]; then |
668 | echo "Architecture: all" | |
669 | else | |
670 | echo "Architecture: any" | |
671 | fi | |
672 | local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')" | |
673 | test -z "$DEPS" || echo "$DEPS" | |
674 | echo "Description: $DESCRIPTION" | |
675 | } > "${BUILDDIR}/debian/control" | |
01f520ce | 676 | |
63c71412 DK |
677 | echo '3.0 (native)' > "${BUILDDIR}/debian/source/format" |
678 | cd "${BUILDDIR}/.." | |
0c787570 DK |
679 | testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION} |
680 | cd - >/dev/null | |
63c71412 | 681 | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \ |
f1828b69 | 682 | | while read SRC; do |
63c71412 | 683 | echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist" |
f1828b69 | 684 | # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then |
33a22672 | 685 | # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \ |
bd7fb5aa | 686 | # adv --yes --default-key 'Joe Sixpack' \ |
f1828b69 DK |
687 | # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC" |
688 | # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC" | |
689 | # fi | |
b761356f | 690 | done |
84aa13f4 | 691 | |
3dcdc1f9 | 692 | for arch in $(getarchitecturesfromcommalist "$ARCH"); do |
0c787570 | 693 | msgtest "Build binary package for ${RELEASE} in ${SECTION}" "$NAME" |
63c71412 DK |
694 | rm -rf "${BUILDDIR}/debian/tmp" |
695 | mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin" | |
696 | cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" | |
697 | cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}" | |
42c1513b | 698 | if [ -n "$FILE_TREE" ]; then |
63c71412 | 699 | cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp" |
42c1513b | 700 | fi |
42c1513b | 701 | |
63c71412 DK |
702 | (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch) |
703 | (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN/md5sums) | |
846856f4 | 704 | local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log" |
d56e2917 | 705 | # ensure the right permissions as dpkg-deb insists |
63c71412 DK |
706 | chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN" |
707 | testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.." | |
708 | echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist" | |
84aa13f4 DK |
709 | done |
710 | ||
d56e2917 | 711 | local CHANGEPATH="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}" |
63c71412 DK |
712 | mkdir -p "$CHANGEPATH" |
713 | cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH" | |
5a635ee4 | 714 | rm -rf "${BUILDDIR}" |
b761356f | 715 | msgdone "info" |
75954ae2 DK |
716 | } |
717 | ||
718 | buildpackage() { | |
719 | local BUILDDIR=$1 | |
720 | local RELEASE=$2 | |
721 | local SECTION=$3 | |
ea65d079 | 722 | local ARCH=$(getarchitecture $4) |
846856f4 DK |
723 | local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')" |
724 | local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")" | |
0c787570 | 725 | msgtest "Build package for ${RELEASE} in ${SECTION}" "$PKGNAME" |
63c71412 | 726 | cd "$BUILDDIR" |
75954ae2 DK |
727 | if [ "$ARCH" = "all" ]; then |
728 | ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" | |
729 | fi | |
0c787570 | 730 | testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH |
63c71412 DK |
731 | cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG" |
732 | local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")" | |
733 | local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')" | |
ce9864a8 | 734 | cd - > /dev/null |
b7899b00 | 735 | for PKG in $PKGS; do |
63c71412 | 736 | echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist" |
b7899b00 DK |
737 | done |
738 | for SRC in $SRCS; do | |
63c71412 | 739 | echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist" |
b7899b00 | 740 | done |
ce9864a8 DK |
741 | } |
742 | ||
743 | buildaptarchive() { | |
ce9864a8 | 744 | if [ -d incoming ]; then |
846856f4 | 745 | buildaptarchivefromincoming "$@" |
ce9864a8 | 746 | else |
846856f4 | 747 | buildaptarchivefromfiles "$@" |
ce9864a8 DK |
748 | fi |
749 | } | |
750 | ||
751 | createaptftparchiveconfig() { | |
63c71412 | 752 | local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')" |
016bea82 DK |
753 | local COMPRESSORS="${COMPRESSORS%* }" |
754 | local ARCHS="$(getarchitectures)" | |
c5ede4ca DK |
755 | cat > ftparchive.conf <<EOF |
756 | Dir { | |
757 | ArchiveDir "$(readlink -f .)"; | |
758 | CacheDir "$(readlink -f ..)"; | |
759 | FileListDir "$(readlink -f pool/)"; | |
b7899b00 DK |
760 | }; |
761 | Default { | |
c5ede4ca DK |
762 | Packages::Compress "$COMPRESSORS"; |
763 | Sources::Compress "$COMPRESSORS"; | |
764 | Contents::Compress "$COMPRESSORS"; | |
765 | Translation::Compress "$COMPRESSORS"; | |
18331adf | 766 | LongDescription "false"; |
ce9864a8 DK |
767 | }; |
768 | TreeDefault { | |
769 | Directory "pool/"; | |
770 | SrcDirectory "pool/"; | |
771 | }; | |
c5ede4ca | 772 | EOF |
b7899b00 | 773 | for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do |
63c71412 DK |
774 | cat <<EOF |
775 | tree "dists/$DIST" { | |
1dd20368 | 776 | Architectures "$ARCHS all source"; |
63c71412 DK |
777 | FileList "${DIST}.\$(SECTION).pkglist"; |
778 | SourceFileList "${DIST}.\$(SECTION).srclist"; | |
779 | Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')"; | |
780 | }; | |
781 | EOF | |
782 | done >> ftparchive.conf | |
ce9864a8 DK |
783 | } |
784 | ||
785 | buildaptftparchivedirectorystructure() { | |
b7899b00 DK |
786 | local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')" |
787 | for DIST in $DISTS; do | |
788 | local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)" | |
789 | for SECTION in $SECTIONS; do | |
790 | local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')" | |
791 | for ARCH in $ARCHS; do | |
63c71412 | 792 | mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}" |
b7899b00 | 793 | done |
63c71412 DK |
794 | mkdir -p "dists/${DIST}/${SECTION}/source" |
795 | mkdir -p "dists/${DIST}/${SECTION}/i18n" | |
b7899b00 | 796 | done |
ce9864a8 | 797 | done |
ce9864a8 DK |
798 | } |
799 | ||
9b78cda6 | 800 | insertpackage() { |
10e100e5 | 801 | local RELEASES="$1" |
9b78cda6 DK |
802 | local NAME="$2" |
803 | local ARCH="$3" | |
804 | local VERSION="$4" | |
805 | local DEPENDENCIES="$5" | |
d67004e0 | 806 | local PRIORITY="${6:-optional}" |
10e100e5 | 807 | local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES} |
18908589 DK |
808 | If you find such a package installed on your system, |
809 | something went horribly wrong! They are autogenerated | |
3d284148 | 810 | und used only by testcases and serve no other purpose…"}" |
d67004e0 | 811 | local ARCHS="" |
10e100e5 DK |
812 | for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do |
813 | if [ "$RELEASE" = 'installed' ]; then | |
814 | insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7" | |
815 | continue | |
d67004e0 | 816 | fi |
10e100e5 | 817 | for arch in $(getarchitecturesfromcommalist "$ARCH"); do |
1dd20368 | 818 | if [ "$arch" = 'none' ]; then |
10e100e5 DK |
819 | ARCHS="$(getarchitectures)" |
820 | else | |
821 | ARCHS="$arch" | |
822 | fi | |
823 | for BUILDARCH in $ARCHS; do | |
824 | local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}" | |
63c71412 DK |
825 | mkdir -p "$PPATH" |
826 | { | |
827 | echo "Package: $NAME | |
d67004e0 | 828 | Priority: $PRIORITY |
9b78cda6 | 829 | Section: other |
2c085486 | 830 | Installed-Size: 42 |
63c71412 DK |
831 | Maintainer: Joe Sixpack <joe@example.org>" |
832 | test "$arch" = 'none' || echo "Architecture: $arch" | |
833 | echo "Version: $VERSION | |
834 | Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" | |
835 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" | |
836 | echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" | |
837 | echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" | |
838 | echo | |
839 | } >> "${PPATH}/Packages" | |
10e100e5 | 840 | done |
d67004e0 | 841 | done |
63c71412 DK |
842 | mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n" |
843 | touch "aptarchive/dists/${RELEASE}/main/source/Sources" | |
10e100e5 | 844 | echo "Package: $NAME |
0e0d9919 DK |
845 | Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1) |
846 | Description-en: $DESCRIPTION | |
63c71412 | 847 | " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en" |
10e100e5 | 848 | done |
9b78cda6 DK |
849 | } |
850 | ||
234675b7 | 851 | insertsource() { |
07aca07a | 852 | local RELEASES="$1" |
234675b7 DK |
853 | local NAME="$2" |
854 | local ARCH="$3" | |
855 | local VERSION="$4" | |
856 | local DEPENDENCIES="$5" | |
07aca07a | 857 | local BINARY="${6:-$NAME}" |
234675b7 | 858 | local ARCHS="" |
07aca07a DK |
859 | for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do |
860 | local SPATH="aptarchive/dists/${RELEASE}/main/source" | |
861 | mkdir -p $SPATH | |
862 | local FILE="${SPATH}/Sources" | |
863 | local DSCFILE="${NAME}_${VERSION}.dsc" | |
864 | local TARFILE="${NAME}_${VERSION}.tar.gz" | |
865 | echo "Package: $NAME | |
a8275acf | 866 | Binary: $BINARY |
234675b7 DK |
867 | Version: $VERSION |
868 | Maintainer: Joe Sixpack <joe@example.org> | |
869 | Architecture: $ARCH" >> $FILE | |
07aca07a DK |
870 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE" |
871 | echo "Files: | |
63c71412 DK |
872 | $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE" |
873 | $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE" | |
55ae7a51 | 874 | Checksums-Sha256: |
63c71412 DK |
875 | $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE" |
876 | $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE" | |
877 | " >> "$FILE" | |
07aca07a | 878 | done |
234675b7 DK |
879 | } |
880 | ||
dfc2b1be DK |
881 | insertinstalledpackage() { |
882 | local NAME="$1" | |
883 | local ARCH="$2" | |
884 | local VERSION="$3" | |
885 | local DEPENDENCIES="$4" | |
d67004e0 | 886 | local PRIORITY="${5:-optional}" |
d4b4e5ea | 887 | local STATUS="${6:-install ok installed}" |
14109555 | 888 | local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed |
18908589 DK |
889 | If you find such a package installed on your system, |
890 | something went horribly wrong! They are autogenerated | |
3d284148 | 891 | und used only by testcases and serve no other purpose…"}" |
18908589 | 892 | |
53ea1b56 DK |
893 | local FILE='rootdir/var/lib/dpkg/status' |
894 | local INFO='rootdir/var/lib/dpkg/info' | |
3dcdc1f9 | 895 | for arch in $(getarchitecturesfromcommalist "$ARCH"); do |
d67004e0 | 896 | echo "Package: $NAME |
d4b4e5ea | 897 | Status: $STATUS |
d67004e0 | 898 | Priority: $PRIORITY |
dfc2b1be DK |
899 | Section: other |
900 | Installed-Size: 42 | |
901 | Maintainer: Joe Sixpack <joe@example.org> | |
63c71412 DK |
902 | Version: $VERSION" >> "$FILE" |
903 | test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE" | |
904 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE" | |
905 | echo "Description: $DESCRIPTION" >> "$FILE" | |
906 | echo >> "$FILE" | |
53ea1b56 | 907 | if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then |
63c71412 | 908 | echo -n > "${INFO}/${NAME}:${arch}.list" |
53ea1b56 | 909 | else |
63c71412 | 910 | echo -n > "${INFO}/${NAME}.list" |
53ea1b56 | 911 | fi |
d67004e0 | 912 | done |
dfc2b1be DK |
913 | } |
914 | ||
915 | ||
ce9864a8 | 916 | buildaptarchivefromincoming() { |
63c71412 | 917 | msginfo "Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…" |
ce9864a8 DK |
918 | cd aptarchive |
919 | [ -e pool ] || ln -s ../incoming pool | |
920 | [ -e ftparchive.conf ] || createaptftparchiveconfig | |
921 | [ -e dists ] || buildaptftparchivedirectorystructure | |
b7899b00 | 922 | msgninfo "\tGenerate Packages, Sources and Contents files… " |
31be38d2 | 923 | testsuccess aptftparchive generate ftparchive.conf |
ce9864a8 DK |
924 | cd - > /dev/null |
925 | msgdone "info" | |
4dbfe436 | 926 | generatereleasefiles "$@" |
ce9864a8 DK |
927 | } |
928 | ||
929 | buildaptarchivefromfiles() { | |
63c71412 | 930 | msginfo "Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…" |
8d041b4f DK |
931 | local DIR='aptarchive' |
932 | if [ -d "${DIR}/dists" ]; then DIR="${DIR}/dists"; fi | |
933 | find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do | |
9b78cda6 | 934 | msgninfo "\t${line} file… " |
276e51dd | 935 | compressfile "$line" "$1" |
8d876415 | 936 | msgdone "info" |
9b78cda6 | 937 | done |
e3c62328 | 938 | generatereleasefiles "$@" |
9b78cda6 DK |
939 | } |
940 | ||
276e51dd | 941 | compressfile() { |
63c71412 | 942 | cat "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | while read compressor extension command; do |
276e51dd DK |
943 | if [ "$compressor" = '.' ]; then |
944 | if [ -n "$2" ]; then | |
945 | touch -d "$2" "$1" | |
946 | fi | |
947 | continue | |
948 | fi | |
949 | cat "$1" | $command > "${1}.${extension}" | |
950 | if [ -n "$2" ]; then | |
951 | touch -d "$2" "${1}.${extension}" | |
952 | fi | |
953 | done | |
954 | } | |
955 | ||
a3bbbab7 | 956 | # can be overridden by testcases for their pleasure |
bf9e7447 DK |
957 | getcodenamefromsuite() { |
958 | case "$1" in | |
959 | unstable) echo 'sid';; | |
960 | *) echo -n "$1";; | |
961 | esac | |
962 | } | |
a3bbbab7 | 963 | getreleaseversionfromsuite() { true; } |
718f797c | 964 | getlabelfromsuite() { true; } |
d56e2917 | 965 | getoriginfromsuite() { true; } |
1dd20368 | 966 | getarchitecturesfromreleasefile() { echo "all $(getarchitectures)"; } |
a3bbbab7 | 967 | |
c5ede4ca DK |
968 | aptftparchiverelease() { |
969 | aptftparchive -qq release "$@" | sed -e '/0 Release$/ d' # remove the self reference | |
970 | } | |
9b78cda6 | 971 | generatereleasefiles() { |
884a4c0a DK |
972 | # $1 is the Date header and $2 is the ValidUntil header to be set |
973 | # both should be given in notation date/touch can understand | |
1dd20368 DK |
974 | local DATE="$1" |
975 | local VALIDUNTIL="$2" | |
9b78cda6 | 976 | if [ -e aptarchive/dists ]; then |
87d6947d | 977 | msgninfo "\tGenerate Release files for dists… " |
9b78cda6 | 978 | for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do |
1dd20368 | 979 | local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")" |
a3bbbab7 DK |
980 | local SUITE="$(echo "$dir" | cut -d'/' -f 4)" |
981 | local CODENAME="$(getcodenamefromsuite $SUITE)" | |
982 | local VERSION="$(getreleaseversionfromsuite $SUITE)" | |
718f797c | 983 | local LABEL="$(getlabelfromsuite $SUITE)" |
d56e2917 | 984 | local ORIGIN="$(getoriginfromsuite $SUITE)" |
63c71412 | 985 | aptftparchiverelease "$dir" \ |
884a4c0a DK |
986 | -o APT::FTPArchive::Release::Suite="${SUITE}" \ |
987 | -o APT::FTPArchive::Release::Codename="${CODENAME}" \ | |
bc7a59dd DK |
988 | -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \ |
989 | -o APT::FTPArchive::Release::Label="${LABEL}" \ | |
990 | -o APT::FTPArchive::Release::Origin="${ORIGIN}" \ | |
991 | -o APT::FTPArchive::Release::Version="${VERSION}" \ | |
63c71412 | 992 | > "$dir/Release" |
a3bbbab7 | 993 | if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then |
35faae11 | 994 | sed -i '/^Date: / a\ |
63c71412 | 995 | NotAutomatic: yes' "$dir/Release" |
35faae11 | 996 | fi |
9b78cda6 DK |
997 | done |
998 | else | |
87d6947d | 999 | msgninfo "\tGenerate Release files for flat… " |
c5ede4ca | 1000 | aptftparchiverelease ./aptarchive > aptarchive/Release |
8d876415 | 1001 | fi |
1dd20368 | 1002 | if [ -n "$DATE" -a "$DATE" != "now" ]; then |
fe0f7911 | 1003 | for release in $(find ./aptarchive -name 'Release'); do |
1dd20368 DK |
1004 | sed -i "s/^Date: .*$/Date: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release" |
1005 | touch -d "$DATE" "$release" | |
fe0f7911 | 1006 | done |
8d876415 | 1007 | fi |
1dd20368 | 1008 | if [ -n "$VALIDUNTIL" ]; then |
c5ede4ca | 1009 | sed -i "/^Date: / a\ |
1dd20368 | 1010 | Valid-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release') |
c5ede4ca | 1011 | fi |
b7899b00 | 1012 | msgdone "info" |
8d876415 DK |
1013 | } |
1014 | ||
b7899b00 | 1015 | setupdistsaptarchive() { |
63c71412 | 1016 | local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')" |
b7899b00 DK |
1017 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list |
1018 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list | |
1019 | for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do | |
63c71412 | 1020 | SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ') |
b7899b00 | 1021 | msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… " |
63c71412 DK |
1022 | echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list" |
1023 | echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list" | |
b7899b00 DK |
1024 | msgdone "info" |
1025 | done | |
1026 | } | |
1027 | ||
1028 | setupflataptarchive() { | |
63c71412 DK |
1029 | local APTARCHIVE="$(readlink -f ./aptarchive)" |
1030 | local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')" | |
1031 | if [ -f "${APTARCHIVE}/Packages" ]; then | |
8d876415 | 1032 | msgninfo "\tadd deb sources.list line… " |
63c71412 DK |
1033 | echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list' |
1034 | msgdone 'info' | |
8d876415 | 1035 | else |
63c71412 | 1036 | rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list' |
8d876415 | 1037 | fi |
63c71412 | 1038 | if [ -f "${APTARCHIVE}/Sources" ]; then |
8d876415 | 1039 | msgninfo "\tadd deb-src sources.list line… " |
63c71412 DK |
1040 | echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list' |
1041 | msgdone 'info' | |
8d876415 | 1042 | else |
63c71412 | 1043 | rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list' |
8d876415 | 1044 | fi |
b7899b00 DK |
1045 | } |
1046 | ||
1047 | setupaptarchive() { | |
4dbfe436 DK |
1048 | local NOUPDATE=0 |
1049 | if [ "$1" = '--no-update' ]; then | |
1050 | NOUPDATE=1 | |
1051 | shift | |
1052 | fi | |
1053 | buildaptarchive "$@" | |
b7899b00 DK |
1054 | if [ -e aptarchive/dists ]; then |
1055 | setupdistsaptarchive | |
1056 | else | |
1057 | setupflataptarchive | |
1058 | fi | |
9d653a6d | 1059 | signreleasefiles 'Joe Sixpack' |
4dbfe436 | 1060 | if [ "1" != "$NOUPDATE" ]; then |
5684f71f | 1061 | testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true |
b2ea1a47 | 1062 | fi |
8d876415 DK |
1063 | } |
1064 | ||
f213b6ea DK |
1065 | signreleasefiles() { |
1066 | local SIGNER="${1:-Joe Sixpack}" | |
07cb47e7 | 1067 | local REPODIR="${2:-aptarchive}" |
f1e1abd8 | 1068 | local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')" |
33a22672 | 1069 | local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes" |
f1e1abd8 | 1070 | msgninfo "\tSign archive with $SIGNER key $KEY… " |
29a59c46 DK |
1071 | local REXKEY='keys/rexexpired' |
1072 | local SECEXPIREBAK="${REXKEY}.sec.bak" | |
1073 | local PUBEXPIREBAK="${REXKEY}.pub.bak" | |
1074 | if [ "${SIGNER}" = 'Rex Expired' ]; then | |
1075 | # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time | |
1076 | # option doesn't exist anymore (and using faketime would add a new obscure dependency) | |
1077 | # therefore we 'temporary' make the key not expired and restore a backup after signing | |
63c71412 DK |
1078 | cp "${REXKEY}.sec" "$SECEXPIREBAK" |
1079 | cp "${REXKEY}.pub" "$PUBEXPIREBAK" | |
29a59c46 DK |
1080 | local SECUNEXPIRED="${REXKEY}.sec.unexpired" |
1081 | local PUBUNEXPIRED="${REXKEY}.pub.unexpired" | |
1082 | if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then | |
63c71412 DK |
1083 | cp "$SECUNEXPIRED" "${REXKEY}.sec" |
1084 | cp "$PUBUNEXPIRED" "${REXKEY}.pub" | |
29a59c46 | 1085 | else |
f1e1abd8 DK |
1086 | if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then |
1087 | cat setexpire.gpg | |
1088 | exit 1 | |
1089 | fi | |
63c71412 DK |
1090 | cp "${REXKEY}.sec" "$SECUNEXPIRED" |
1091 | cp "${REXKEY}.pub" "$PUBUNEXPIRED" | |
29a59c46 DK |
1092 | fi |
1093 | fi | |
63c71412 | 1094 | for RELEASE in $(find "${REPODIR}/" -name Release); do |
785cb6fc | 1095 | testsuccess $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}" |
e3c62328 | 1096 | local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" |
785cb6fc | 1097 | testsuccess $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE" |
e3c62328 | 1098 | # we might have set a specific date for the Release file, so copy it |
63c71412 | 1099 | touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg" "${INRELEASE}" |
f213b6ea | 1100 | done |
29a59c46 | 1101 | if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then |
63c71412 DK |
1102 | mv -f "$SECEXPIREBAK" "${REXKEY}.sec" |
1103 | mv -f "$PUBEXPIREBAK" "${REXKEY}.pub" | |
29a59c46 | 1104 | fi |
63c71412 | 1105 | msgdone 'info' |
f213b6ea DK |
1106 | } |
1107 | ||
8eafc759 DK |
1108 | redatereleasefiles() { |
1109 | local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')" | |
1110 | for release in $(find aptarchive/ -name 'Release'); do | |
63c71412 DK |
1111 | sed -i "s/^Date: .*$/Date: ${DATE}/" "$release" |
1112 | touch -d "$DATE" "$release" | |
8eafc759 DK |
1113 | done |
1114 | signreleasefiles "${2:-Joe Sixpack}" | |
1115 | } | |
1116 | ||
f2c0ec8b | 1117 | webserverconfig() { |
6c0765c0 | 1118 | local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}" |
b0314abb DK |
1119 | local NOCHECK=false |
1120 | if [ "$1" = '--no-check' ]; then | |
1121 | NOCHECK=true | |
1122 | shift | |
1123 | fi | |
0d58c26a | 1124 | local DOWNLOG='rootdir/tmp/download-testfile.log' |
b0314abb | 1125 | local STATUS='downloaded/webserverconfig.status' |
0d58c26a | 1126 | rm -f "$STATUS" "$DOWNLOG" |
6c0765c0 | 1127 | # very very basic URI encoding |
b0314abb DK |
1128 | local URI |
1129 | if [ -n "$2" ]; then | |
1130 | msgtest "Set webserver config option '${1}' to" "$2" | |
6c0765c0 | 1131 | URI="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')" |
b0314abb DK |
1132 | else |
1133 | msgtest 'Clear webserver config option' "${1}" | |
6c0765c0 | 1134 | URI="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')" |
b0314abb DK |
1135 | fi |
1136 | if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then | |
f2c0ec8b DK |
1137 | msgpass |
1138 | else | |
68042532 DK |
1139 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output" |
1140 | cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true | |
1141 | msgfailoutput '' "$OUTPUT" | |
f2c0ec8b | 1142 | fi |
b0314abb | 1143 | $NOCHECK || testwebserverlaststatuscode '200' |
f2c0ec8b DK |
1144 | } |
1145 | ||
fd46d305 | 1146 | rewritesourceslist() { |
63c71412 | 1147 | local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')" |
af9e40c9 | 1148 | local APTARCHIVE2="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')" |
fd46d305 | 1149 | for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do |
af9e40c9 DK |
1150 | sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \ |
1151 | -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \ | |
1152 | -e "s#https://localhost:${APTHTTPSPORT}/#${1}#" | |
fd46d305 DK |
1153 | done |
1154 | } | |
1155 | ||
5572f6bd MV |
1156 | # wait for up to 10s for a pid file to appear to avoid possible race |
1157 | # when a helper is started and dosn't write the PID quick enough | |
1158 | waitforpidfile() { | |
1159 | local PIDFILE="$1" | |
1160 | for i in $(seq 10); do | |
1161 | if test -s "$PIDFILE"; then | |
1162 | return 0 | |
1163 | fi | |
1164 | sleep 1 | |
1165 | done | |
1166 | msgdie "waiting for $PIDFILE failed" | |
1167 | return 1 | |
1168 | } | |
1169 | ||
f213b6ea | 1170 | changetowebserver() { |
6c0765c0 | 1171 | local REWRITE='no' |
23af9f40 | 1172 | if [ "$1" != '--no-rewrite' ]; then |
6c0765c0 | 1173 | REWRITE='yes' |
23af9f40 DK |
1174 | else |
1175 | shift | |
1176 | fi | |
63c71412 | 1177 | if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then |
fbd29dd6 | 1178 | cd aptarchive |
a0db467c | 1179 | local LOG="webserver.log" |
6c0765c0 | 1180 | if ! aptwebserver --port 0 -o aptwebserver::fork=1 -o aptwebserver::portfile='aptwebserver.port' "$@" >$LOG 2>&1 ; then |
3abb6a6a | 1181 | cat "$LOG" |
bee0670b DK |
1182 | false |
1183 | fi | |
6c0765c0 | 1184 | waitforpidfile aptwebserver.pid |
e3c62328 DK |
1185 | local PID="$(cat aptwebserver.pid)" |
1186 | if [ -z "$PID" ]; then | |
1187 | msgdie 'Could not fork aptwebserver successfully' | |
1188 | fi | |
1189 | addtrap "kill $PID;" | |
6c0765c0 DK |
1190 | waitforpidfile aptwebserver.port |
1191 | APTHTTPPORT="$(cat aptwebserver.port)" | |
1192 | if [ -z "$APTHTTPPORT" ]; then | |
1193 | msgdie 'Could not get port for aptwebserver successfully' | |
1194 | fi | |
fbd29dd6 | 1195 | cd - > /dev/null |
c5bcc607 | 1196 | else |
3d284148 | 1197 | msgdie 'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver' |
f213b6ea | 1198 | fi |
6c0765c0 DK |
1199 | if [ "$REWRTE" != 'yes' ]; then |
1200 | rewritesourceslist "http://localhost:${APTHTTPPORT}/" | |
1201 | fi | |
fd46d305 DK |
1202 | } |
1203 | ||
1204 | changetohttpswebserver() { | |
e75e5879 | 1205 | if ! command -v stunnel4 >/dev/null 2>&1; then |
fd46d305 DK |
1206 | msgdie 'You need to install stunnel4 for https testcases' |
1207 | fi | |
1208 | if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then | |
dc95fee1 | 1209 | changetowebserver --no-rewrite "$@" |
fd46d305 DK |
1210 | fi |
1211 | echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid | |
68ba0b7f | 1212 | cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem |
23af9f40 | 1213 | output = /dev/null |
fd46d305 DK |
1214 | |
1215 | [https] | |
6c0765c0 DK |
1216 | accept = 0 |
1217 | connect = $APTHTTPPORT | |
63c71412 | 1218 | " > "${TMPWORKINGDIRECTORY}/stunnel.conf" |
fd46d305 | 1219 | stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf" |
5572f6bd | 1220 | waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid" |
63c71412 | 1221 | local PID="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")" |
5572f6bd MV |
1222 | if [ -z "$PID" ]; then |
1223 | msgdie 'Could not fork stunnel4 successfully' | |
1224 | fi | |
fd46d305 | 1225 | addtrap 'prefix' "kill ${PID};" |
6c0765c0 DK |
1226 | APTHTTPSPORT="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)" |
1227 | webserverconfig 'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}" | |
1228 | rewritesourceslist "https://localhost:${APTHTTPSPORT}/" | |
f213b6ea DK |
1229 | } |
1230 | ||
c45233ea DK |
1231 | changetocdrom() { |
1232 | mkdir -p rootdir/media/cdrom/.disk | |
1233 | local CD="$(readlink -f rootdir/media/cdrom)" | |
63c71412 DK |
1234 | cat > rootdir/etc/apt/apt.conf.d/00cdrom <<EOF |
1235 | acquire::cdrom::mount "${CD}"; | |
1236 | acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}"; | |
1237 | acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted"; | |
1238 | acquire::cdrom::autodetect 0; | |
1239 | EOF | |
1240 | echo -n "$1" > "${CD}/.disk/info" | |
c45233ea DK |
1241 | if [ ! -d aptarchive/dists ]; then |
1242 | msgdie 'Flat file archive cdroms can not be created currently' | |
1243 | return 1 | |
1244 | fi | |
a0975c8d | 1245 | mv aptarchive/dists "$CD" |
63c71412 | 1246 | ln -s "$(readlink -f ./incoming)" "$CD/pool" |
c45233ea | 1247 | find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete |
a0975c8d DK |
1248 | # start with an unmounted disk |
1249 | mv "${CD}" "${CD}-unmounted" | |
1250 | # we don't want the disk to be modifiable | |
bc8f83a5 | 1251 | addtrap 'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;" |
b0314abb | 1252 | chmod -R 555 rootdir/media/cdrom-unmounted/dists |
c45233ea DK |
1253 | } |
1254 | ||
fd46d305 | 1255 | downloadfile() { |
ed793a19 | 1256 | local PROTO="${1%%:*}" |
27925d82 | 1257 | if ! apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \ |
dcbb364f | 1258 | download-file "$1" "$2" "$3" 2>&1 ; then |
27925d82 DK |
1259 | return 1 |
1260 | fi | |
fd46d305 | 1261 | # only if the file exists the download was successful |
b0314abb | 1262 | if [ -r "$2" ]; then |
fd46d305 DK |
1263 | return 0 |
1264 | else | |
1265 | return 1 | |
1266 | fi | |
1267 | } | |
1268 | ||
f213b6ea | 1269 | checkdiff() { |
03aa0847 | 1270 | local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" |
8d876415 | 1271 | if [ -n "$DIFFTEXT" ]; then |
0d58c26a DK |
1272 | echo >&2 |
1273 | echo >&2 "$DIFFTEXT" | |
8d876415 DK |
1274 | return 1 |
1275 | else | |
1276 | return 0 | |
1277 | fi | |
1278 | } | |
1279 | ||
22ac12b2 DK |
1280 | testoutputequal() { |
1281 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output" | |
1282 | local COMPAREFILE="$1" | |
1283 | shift | |
63c71412 | 1284 | if "$@" 2>&1 | checkdiff "$COMPAREFILE" - >"$OUTPUT" 2>&1; then |
22ac12b2 DK |
1285 | msgpass |
1286 | else | |
1287 | echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}" | |
1288 | cat "$COMPAREFILE" >>"${OUTPUT}" | |
1289 | msgfailoutput '' "$OUTPUT" "$@" | |
1290 | fi | |
1291 | } | |
1292 | ||
75954ae2 | 1293 | testfileequal() { |
1501a2c9 | 1294 | msggroup 'testfileequal' |
e6a12ff7 DK |
1295 | local MSG='Test for correctness of file' |
1296 | if [ "$1" = '--nomsg' ]; then | |
1297 | MSG='' | |
1298 | shift | |
1299 | fi | |
75954ae2 DK |
1300 | local FILE="$1" |
1301 | shift | |
e6a12ff7 DK |
1302 | if [ -n "$MSG" ]; then |
1303 | msgtest "$MSG" "$FILE" | |
1304 | fi | |
68042532 | 1305 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output" |
75954ae2 | 1306 | if [ -z "$*" ]; then |
22ac12b2 | 1307 | testoutputequal "$FILE" echo -n '' |
75954ae2 | 1308 | else |
22ac12b2 | 1309 | testoutputequal "$FILE" echo "$*" |
75954ae2 | 1310 | fi |
9beb11aa | 1311 | msggroup |
75954ae2 DK |
1312 | } |
1313 | ||
b855a400 | 1314 | testempty() { |
1501a2c9 | 1315 | msggroup 'testempty' |
b855a400 | 1316 | msgtest "Test for no output of" "$*" |
859093da | 1317 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile" |
63c71412 | 1318 | if ("$@" >"$COMPAREFILE" 2>&1 || true) && test ! -s "$COMPAREFILE"; then |
859093da DK |
1319 | msgpass |
1320 | else | |
22ac12b2 | 1321 | msgfailoutput '' "$COMPAREFILE" "$@" |
859093da | 1322 | fi |
ab25bf1f | 1323 | aptautotest 'testempty' "$@" |
9beb11aa | 1324 | msggroup |
b855a400 | 1325 | } |
63c71412 DK |
1326 | testnotempty() { |
1327 | msggroup 'testnotempty' | |
1328 | msgtest "Test for some output of" "$*" | |
1329 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile" | |
1330 | if ("$@" >"$COMPAREFILE" 2>&1 || true) && test -s "$COMPAREFILE"; then | |
1331 | msgpass | |
1332 | else | |
1333 | msgfailoutput '' "$COMPAREFILE" "$@" | |
1334 | fi | |
1335 | aptautotest 'testnotempty' "$@" | |
1336 | msggroup | |
1337 | } | |
b855a400 | 1338 | |
f74a6fa1 | 1339 | testequal() { |
1501a2c9 | 1340 | msggroup 'testequal' |
f74a6fa1 DK |
1341 | local MSG='Test of equality of' |
1342 | if [ "$1" = '--nomsg' ]; then | |
1343 | MSG='' | |
1344 | shift | |
1345 | fi | |
1346 | ||
03938280 | 1347 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile" |
63c71412 | 1348 | echo "$1" > "$COMPAREFILE" |
8d876415 | 1349 | shift |
d2d68aaf | 1350 | |
f74a6fa1 DK |
1351 | if [ -n "$MSG" ]; then |
1352 | msgtest "$MSG" "$*" | |
1353 | fi | |
22ac12b2 | 1354 | testoutputequal "$COMPAREFILE" "$@" |
ab25bf1f | 1355 | aptautotest 'testequal' "$@" |
9beb11aa | 1356 | msggroup |
8d876415 DK |
1357 | } |
1358 | ||
685625bd | 1359 | testequalor2() { |
1501a2c9 | 1360 | msggroup 'testequalor2' |
03938280 DK |
1361 | local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1" |
1362 | local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2" | |
1363 | local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst" | |
63c71412 DK |
1364 | echo "$1" > "$COMPAREFILE1" |
1365 | echo "$2" > "$COMPAREFILE2" | |
685625bd DK |
1366 | shift 2 |
1367 | msgtest "Test for equality OR of" "$*" | |
63c71412 DK |
1368 | "$@" >"$COMPAREAGAINST" 2>&1 || true |
1369 | if checkdiff "$COMPAREFILE1" "$COMPAREAGAINST" >/dev/null 2>&1 || \ | |
1370 | checkdiff "$COMPAREFILE2" "$COMPAREAGAINST" >/dev/null 2>&1 | |
0d58c26a | 1371 | then |
0caa5a4c DK |
1372 | msgpass |
1373 | else | |
68042532 DK |
1374 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output" |
1375 | echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1 | |
1376 | checkdiff "$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true | |
1377 | echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1 | |
1378 | checkdiff "$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true | |
1379 | msgfailoutput '' "$OUTPUT" | |
0caa5a4c | 1380 | fi |
ab25bf1f | 1381 | aptautotest 'testequalor2' "$@" |
9beb11aa | 1382 | msggroup |
685625bd DK |
1383 | } |
1384 | ||
8d876415 | 1385 | testshowvirtual() { |
1501a2c9 | 1386 | msggroup 'testshowvirtual' |
edc0ef10 | 1387 | local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
1388 | local PACKAGE="$1" |
1389 | shift | |
1390 | while [ -n "$1" ]; do | |
1391 | VIRTUAL="${VIRTUAL} | |
edc0ef10 | 1392 | N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
1393 | PACKAGE="${PACKAGE} $1" |
1394 | shift | |
1395 | done | |
1396 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
1397 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 1398 | N: No packages found" |
03938280 | 1399 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile" |
ea65d079 | 1400 | local ARCH="$(getarchitecture 'native')" |
68042532 DK |
1401 | echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE" |
1402 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output" | |
87d6947d | 1403 | testoutputequal "$COMPAREFILE" aptcache show "$PACKAGE" |
9beb11aa | 1404 | msggroup |
8d876415 DK |
1405 | } |
1406 | ||
1407 | testnopackage() { | |
1501a2c9 | 1408 | msggroup 'testnopackage' |
8d876415 | 1409 | msgtest "Test for non-existent packages" "apt-cache show $*" |
846856f4 | 1410 | local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')" |
8d876415 | 1411 | if [ -n "$SHOWPKG" ]; then |
68042532 DK |
1412 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" |
1413 | echo "$SHOWPKG" >"$OUTPUT" | |
1414 | msgfailoutput '' "$OUTPUT" | |
0d58c26a DK |
1415 | else |
1416 | msgpass | |
8d876415 | 1417 | fi |
9beb11aa | 1418 | msggroup |
8d876415 | 1419 | } |
bd4a8f51 DK |
1420 | testnosrcpackage() { |
1421 | msggroup 'testnosrcpackage' | |
1422 | msgtest "Test for non-existent source packages" "apt-cache showsrc $*" | |
1423 | local SHOWPKG="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')" | |
1424 | if [ -n "$SHOWPKG" ]; then | |
1425 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output" | |
1426 | echo "$SHOWPKG" >"$OUTPUT" | |
1427 | msgfailoutput '' "$OUTPUT" | |
1428 | else | |
1429 | msgpass | |
1430 | fi | |
1431 | msggroup | |
1432 | } | |
01a6e24c | 1433 | |
ecb777dd | 1434 | testdpkgstatus() { |
1501a2c9 | 1435 | msggroup 'testdpkgstatus' |
ecb777dd DK |
1436 | local STATE="$1" |
1437 | local NR="$2" | |
1438 | shift 2 | |
1439 | msgtest "Test that $NR package(s) are in state $STATE with" "dpkg -l $*" | |
1440 | local PKGS="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)" | |
1441 | if [ "$PKGS" != $NR ]; then | |
68042532 DK |
1442 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" |
1443 | echo "$PKGS" >"$OUTPUT" | |
1444 | dpkg -l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true | |
1445 | msgfailoutput '' "$OUTPUT" | |
0d58c26a DK |
1446 | else |
1447 | msgpass | |
01a6e24c | 1448 | fi |
9beb11aa | 1449 | msggroup |
01a6e24c DK |
1450 | } |
1451 | ||
ecb777dd | 1452 | testdpkginstalled() { |
1501a2c9 | 1453 | msggroup 'testdpkginstalled' |
ecb777dd | 1454 | testdpkgstatus 'ii' "$#" "$@" |
9beb11aa | 1455 | msggroup |
ecb777dd DK |
1456 | } |
1457 | ||
5cf733e1 | 1458 | testdpkgnotinstalled() { |
1501a2c9 | 1459 | msggroup 'testdpkgnotinstalled' |
ecb777dd | 1460 | testdpkgstatus 'ii' '0' "$@" |
9beb11aa | 1461 | msggroup |
01a6e24c | 1462 | } |
ec7f904e DK |
1463 | |
1464 | testmarkedauto() { | |
1501a2c9 | 1465 | msggroup 'testmarkedauto' |
03938280 | 1466 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile" |
ec7f904e DK |
1467 | if [ -n "$1" ]; then |
1468 | msgtest 'Test for correctly marked as auto-installed' "$*" | |
63c71412 | 1469 | while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE" |
ec7f904e DK |
1470 | else |
1471 | msgtest 'Test for correctly marked as auto-installed' 'no package' | |
63c71412 | 1472 | echo -n > "$COMPAREFILE" |
ec7f904e | 1473 | fi |
22ac12b2 | 1474 | testoutputequal "$COMPAREFILE" aptmark showauto |
9beb11aa | 1475 | msggroup |
ec7f904e | 1476 | } |
7c2cc4a7 | 1477 | testmarkedmanual() { |
1501a2c9 | 1478 | msggroup 'testmarkedmanual' |
7c2cc4a7 DK |
1479 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile" |
1480 | if [ -n "$1" ]; then | |
1481 | msgtest 'Test for correctly marked as manually installed' "$*" | |
63c71412 | 1482 | while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE" |
7c2cc4a7 DK |
1483 | else |
1484 | msgtest 'Test for correctly marked as manually installed' 'no package' | |
63c71412 | 1485 | echo -n > "$COMPAREFILE" |
7c2cc4a7 | 1486 | fi |
22ac12b2 | 1487 | testoutputequal "$COMPAREFILE" aptmark showmanual |
9beb11aa | 1488 | msggroup |
7c2cc4a7 | 1489 | } |
89a1aa5d | 1490 | |
e52aad52 | 1491 | msgfailoutput() { |
1501a2c9 | 1492 | msgreportheader 'msgfailoutput' |
e52aad52 DK |
1493 | local MSG="$1" |
1494 | local OUTPUT="$2" | |
1495 | shift 2 | |
e52aad52 | 1496 | if [ "$1" = 'grep' ]; then |
68042532 | 1497 | echo >&2 |
e52aad52 DK |
1498 | while [ -n "$2" ]; do shift; done |
1499 | echo "#### Complete file: $1 ####" | |
1500 | cat >&2 "$1" || true | |
1501 | echo '#### grep output ####' | |
1502 | elif [ "$1" = 'test' ]; then | |
68042532 | 1503 | echo >&2 |
e52aad52 DK |
1504 | # doesn't support ! or non-file flags |
1505 | msgfailoutputstatfile() { | |
1506 | local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$' | |
1507 | if expr match "$1" "$FILEFLAGS" >/dev/null; then | |
1508 | echo "#### stat(2) of file: $2 ####" | |
1509 | stat "$2" || true | |
dffc17ba DK |
1510 | if test -d "$2"; then |
1511 | echo "#### The directory contains: $2 ####" | |
1512 | ls >&2 "$2" || true | |
1513 | elif test -e "$2"; then | |
3196dae8 DK |
1514 | echo "#### Complete file: $2 ####" |
1515 | cat >&2 "$2" || true | |
1516 | fi | |
e52aad52 DK |
1517 | fi |
1518 | } | |
1519 | msgfailoutputstatfile "$2" "$3" | |
1520 | while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do | |
1521 | shift 3 | |
1522 | msgfailoutputstatfile "$2" "$3" | |
1523 | done | |
1524 | echo '#### test output ####' | |
1525 | fi | |
63c71412 | 1526 | cat >&2 "$OUTPUT" |
e52aad52 DK |
1527 | msgfail "$MSG" |
1528 | } | |
1529 | ||
671a55ba DK |
1530 | testsuccesswithglobalerror() { |
1531 | local TYPE="$1" | |
1532 | local ERRORS="$2" | |
1533 | shift 2 | |
1534 | msggroup "$TYPE" | |
0440d936 DK |
1535 | if [ "$1" = '--nomsg' ]; then |
1536 | shift | |
1537 | else | |
1538 | msgtest 'Test for successful execution of' "$*" | |
1539 | fi | |
671a55ba | 1540 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output" |
63c71412 | 1541 | if "$@" >"${OUTPUT}" 2>&1; then |
4fa34122 | 1542 | if expr match "$1" '^apt.*' >/dev/null; then |
e52aad52 DK |
1543 | if grep -q -E ' runtime error: ' "$OUTPUT"; then |
1544 | msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@" | |
671a55ba | 1545 | elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then |
3261271e DK |
1546 | if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then |
1547 | if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \ | |
1548 | | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then | |
1549 | msgpass | |
1550 | else | |
1551 | msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@" | |
1552 | fi | |
1553 | else | |
1554 | msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@" | |
1555 | fi | |
671a55ba DK |
1556 | elif [ "$TYPE" = 'testsuccesswithnotice' ]; then |
1557 | if grep -q -E "^N: " "$OUTPUT"; then | |
1558 | msgpass | |
1559 | else | |
1560 | msgfailoutput 'successful run, but output had no notices' "$OUTPUT" "$@" | |
1561 | fi | |
4fa34122 DK |
1562 | else |
1563 | msgpass | |
1564 | fi | |
1565 | else | |
1566 | msgpass | |
1567 | fi | |
1568 | else | |
1569 | local EXITCODE=$? | |
e52aad52 | 1570 | msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@" |
4fa34122 | 1571 | fi |
671a55ba | 1572 | aptautotest "$TYPE" "$@" |
9beb11aa | 1573 | msggroup |
4fa34122 | 1574 | } |
671a55ba DK |
1575 | testsuccesswithnotice() { |
1576 | testsuccesswithglobalerror 'testsuccesswithnotice' 'WE' "$@" | |
1577 | } | |
1578 | testsuccess() { | |
1579 | testsuccesswithglobalerror 'testsuccess' 'NWE' "$@" | |
1580 | } | |
4fa34122 | 1581 | testwarning() { |
1501a2c9 | 1582 | msggroup 'testwarning' |
4fa34122 DK |
1583 | if [ "$1" = '--nomsg' ]; then |
1584 | shift | |
1585 | else | |
1586 | msgtest 'Test for successful execution with warnings of' "$*" | |
1587 | fi | |
25b86db1 | 1588 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" |
63c71412 | 1589 | if "$@" >"${OUTPUT}" 2>&1; then |
1df24acf | 1590 | if expr match "$1" '^apt.*' >/dev/null; then |
e52aad52 DK |
1591 | if grep -q -E ' runtime error: ' "$OUTPUT"; then |
1592 | msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@" | |
1593 | elif grep -q -E '^E: ' "$OUTPUT"; then | |
1594 | msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@" | |
4fa34122 | 1595 | elif ! grep -q -E '^W: ' "$OUTPUT"; then |
e52aad52 | 1596 | msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@" |
1df24acf DK |
1597 | else |
1598 | msgpass | |
1599 | fi | |
1600 | else | |
1601 | msgpass | |
1602 | fi | |
0440d936 | 1603 | else |
07cb47e7 | 1604 | local EXITCODE=$? |
68042532 | 1605 | msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@" |
0440d936 | 1606 | fi |
4fa34122 | 1607 | aptautotest 'testwarning' "$@" |
9beb11aa | 1608 | msggroup |
0440d936 | 1609 | } |
0440d936 | 1610 | testfailure() { |
1501a2c9 | 1611 | msggroup 'testfailure' |
0440d936 DK |
1612 | if [ "$1" = '--nomsg' ]; then |
1613 | shift | |
1614 | else | |
889b0072 | 1615 | msgtest 'Test for failure in execution of' "$*" |
0440d936 | 1616 | fi |
03938280 | 1617 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" |
63c71412 | 1618 | if "$@" >"${OUTPUT}" 2>&1; then |
07cb47e7 | 1619 | local EXITCODE=$? |
e52aad52 | 1620 | msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@" |
0440d936 | 1621 | else |
1df24acf DK |
1622 | local EXITCODE=$? |
1623 | if expr match "$1" '^apt.*' >/dev/null; then | |
b0d40854 DK |
1624 | if [ "$1" = 'aptkey' ]; then |
1625 | if grep -q -E " Can't check signature: " "$OUTPUT" || \ | |
1626 | grep -q -E " BAD signature from " "$OUTPUT"; then | |
1627 | msgpass | |
1628 | else | |
1629 | msgfailoutput "run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@" | |
1630 | fi | |
1df24acf | 1631 | else |
b0d40854 DK |
1632 | if grep -q -E ' runtime error: ' "$OUTPUT"; then |
1633 | msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@" | |
1634 | elif grep -q -E '==ERROR' "$OUTPUT"; then | |
1635 | msgfailoutput 'compiler sanitizers reported errors' "$OUTPUT" "$@" | |
1636 | elif ! grep -q -E '^E: ' "$OUTPUT"; then | |
1637 | msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@" | |
1638 | else | |
1639 | msgpass | |
1640 | fi | |
1df24acf DK |
1641 | fi |
1642 | else | |
1643 | msgpass | |
1644 | fi | |
0440d936 | 1645 | fi |
ab25bf1f | 1646 | aptautotest 'testfailure' "$@" |
9beb11aa | 1647 | msggroup |
0440d936 DK |
1648 | } |
1649 | ||
7414af7f DK |
1650 | testreturnstateequal() { |
1651 | local STATE="$1" | |
671a55ba DK |
1652 | if [ "$STATE" = 'testsuccesswithglobalerror' ]; then |
1653 | local STATE="$2" | |
1654 | local TYPE="$3" | |
7414af7f | 1655 | shift 3 |
671a55ba DK |
1656 | msggroup "${STATE}equal" |
1657 | if [ "$1" != '--nomsg' ]; then | |
1658 | local CMP="$1" | |
1659 | shift | |
1660 | testsuccesswithglobalerror "$STATE" "$TYPE" "$@" | |
1661 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1662 | else | |
1663 | local CMP="$2" | |
1664 | shift 2 | |
1665 | testsuccesswithglobalerror "$STATE" "$TYPE" "$@" | |
1666 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1667 | fi | |
1668 | else | |
1669 | msggroup "${STATE}equal" | |
1670 | if [ "$2" != '--nomsg' ]; then | |
1671 | local CMP="$2" | |
1672 | shift 2 | |
1673 | "$STATE" "$@" | |
1674 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1675 | else | |
1676 | local CMP="$3" | |
1677 | shift 3 | |
1678 | "$STATE" --nomsg "$@" | |
1679 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1680 | fi | |
7414af7f | 1681 | fi |
9beb11aa | 1682 | msggroup |
25b86db1 | 1683 | } |
7414af7f | 1684 | testsuccessequal() { |
671a55ba DK |
1685 | # we compare output, so we know perfectly well about N: |
1686 | testreturnstateequal 'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@" | |
7414af7f | 1687 | } |
25b86db1 | 1688 | testwarningequal() { |
7414af7f | 1689 | testreturnstateequal 'testwarning' "$@" |
25b86db1 DK |
1690 | } |
1691 | testfailureequal() { | |
7414af7f | 1692 | testreturnstateequal 'testfailure' "$@" |
25b86db1 DK |
1693 | } |
1694 | ||
27925d82 | 1695 | testfailuremsg() { |
1501a2c9 | 1696 | msggroup 'testfailuremsg' |
27925d82 DK |
1697 | local CMP="$1" |
1698 | shift | |
1699 | testfailure "$@" | |
1700 | msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings' | |
68042532 | 1701 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile" |
002b1bc4 | 1702 | grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true |
22ac12b2 | 1703 | testoutputequal "$COMPAREFILE" echo "$CMP" |
9beb11aa | 1704 | msggroup |
27925d82 | 1705 | } |
f18f2338 DK |
1706 | testwarningmsg() { |
1707 | msggroup 'testwarningmsg' | |
1708 | local CMP="$1" | |
1709 | shift | |
1710 | testwarning "$@" | |
1711 | msgtest 'Check that the output of the previous warned command has expected' 'warnings' | |
1712 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile" | |
002b1bc4 | 1713 | grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true |
f18f2338 DK |
1714 | testoutputequal "$COMPAREFILE" echo "$CMP" |
1715 | msggroup | |
1716 | } | |
25b86db1 | 1717 | |
de81b2e2 | 1718 | testfilestats() { |
1501a2c9 | 1719 | msggroup 'testfilestats' |
de81b2e2 DK |
1720 | msgtest "Test that file $1 has $2 $3" "$4" |
1721 | if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then | |
5684f71f DK |
1722 | msgpass |
1723 | else | |
68042532 DK |
1724 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output" |
1725 | { | |
1726 | ls -ld "$1" || true | |
1727 | echo -n "stat(1) reports for $2: " | |
1728 | stat --format "$2" "$1" || true | |
1729 | } >"$OUTPUT" 2>&1 | |
1730 | msgfailoutput '' "$OUTPUT" | |
5684f71f | 1731 | fi |
9beb11aa | 1732 | msggroup |
5684f71f | 1733 | } |
de81b2e2 | 1734 | testaccessrights() { |
1501a2c9 | 1735 | msggroup 'testaccessrights' |
de81b2e2 | 1736 | testfilestats "$1" '%a' '=' "$2" |
9beb11aa | 1737 | msggroup |
de81b2e2 | 1738 | } |
5684f71f | 1739 | |
0d58c26a | 1740 | testwebserverlaststatuscode() { |
1501a2c9 | 1741 | msggroup 'testwebserverlaststatuscode' |
0d58c26a | 1742 | local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log' |
03aa0847 | 1743 | local STATUS='downloaded/webserverstatus-statusfile.log' |
0d58c26a DK |
1744 | rm -f "$DOWNLOG" "$STATUS" |
1745 | msgtest 'Test last status code from the webserver was' "$1" | |
6c0765c0 | 1746 | if downloadfile "http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then |
0d58c26a DK |
1747 | msgpass |
1748 | else | |
68042532 DK |
1749 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output" |
1750 | { | |
1751 | if [ -n "$2" ]; then | |
1752 | shift | |
1753 | echo >&2 '#### Additionally provided output files contain:' | |
1754 | cat >&2 "$@" | |
1755 | fi | |
1756 | echo >&2 '#### Download log of the status code:' | |
1757 | cat >&2 "$DOWNLOG" | |
1758 | } >"$OUTPUT" 2>&1 | |
1759 | msgfailoutput "Status was $(cat "$STATUS")" "$OUTPUT" | |
0d58c26a | 1760 | fi |
9beb11aa | 1761 | msggroup |
0d58c26a DK |
1762 | } |
1763 | ||
785cb6fc DK |
1764 | createlistofkeys() { |
1765 | local OUTPUT="$1" | |
1766 | shift | |
1767 | while [ -n "$1" ]; do | |
1768 | # gpg 2.1 has a slightly different output format | |
1769 | if grep -q ' rsa2048/' "$OUTPUT"; then | |
1770 | case "$1" in | |
1771 | *Joe*|*Sixpack*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';; | |
1772 | *Rex*|*Expired*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';; | |
1773 | *Marvin*|*Paranoid*) echo 'pub rsa2048/528144E2 2011-01-16';; | |
1774 | oldarchive) echo 'pub rsa1024/F68C85A3 2013-12-19';; | |
1775 | newarchive) echo 'pub rsa2048/DBAC8DAE 2010-08-18';; | |
1776 | *) echo 'UNKNOWN KEY';; | |
1777 | esac | |
1778 | else | |
1779 | case "$1" in | |
1780 | *Joe*|*Sixpack*) echo 'pub 2048R/DBAC8DAE 2010-08-18';; | |
1781 | *Rex*|*Expired*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';; | |
1782 | *Marvin*|*Paranoid*) echo 'pub 2048R/528144E2 2011-01-16';; | |
1783 | oldarchive) echo 'pub 1024R/F68C85A3 2013-12-19';; | |
1784 | newarchive) echo 'pub 2048R/DBAC8DAE 2010-08-18';; | |
1785 | *) echo 'UNKNOWN KEY';; | |
1786 | esac | |
1787 | fi | |
1788 | shift | |
1789 | done | |
1790 | } | |
1791 | testaptkeys() { | |
1792 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output" | |
1793 | if ! aptkey list | grep '^pub' > "$OUTPUT"; then | |
1794 | echo -n > "$OUTPUT" | |
1795 | fi | |
1796 | testfileequal "$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")" | |
1797 | } | |
1798 | ||
89a1aa5d DK |
1799 | pause() { |
1800 | echo "STOPPED execution. Press enter to continue" | |
1801 | local IGNORE | |
1802 | read IGNORE | |
1803 | } | |
ab25bf1f | 1804 | |
846bc058 | 1805 | listcurrentlistsdirectory() { |
ba6b79bd DK |
1806 | { |
1807 | find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do | |
1808 | stat --format '%U:%G:%a:%n' "$line" | |
1809 | done | |
1810 | find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do | |
1811 | stat --format '%U:%G:%a:%s:%y:%n' "$line" | |
1812 | done | |
1813 | } | sort | |
846bc058 | 1814 | } |
912a6131 DK |
1815 | forallsupportedcompressors() { |
1816 | for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do | |
0179cfa8 | 1817 | if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi |
912a6131 DK |
1818 | "$@" "$COMP" |
1819 | done | |
1820 | } | |
846bc058 | 1821 | |
3a8776a3 | 1822 | ### convenience hacks ### |
8fe964f1 DK |
1823 | mkdir() { |
1824 | # creating some directories by hand is a tedious task, so make it look simple | |
6aef1942 DK |
1825 | local PARAMS="$*" |
1826 | if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then | |
8fe964f1 DK |
1827 | # only the last directory created by mkdir is effected by the -m ! |
1828 | command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" | |
1829 | command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" | |
1830 | command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" | |
1831 | touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock" | |
1832 | if [ "$(id -u)" = '0' ]; then | |
1833 | chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" | |
1834 | fi | |
1835 | else | |
1836 | command mkdir "$@" | |
1837 | fi | |
1838 | } | |
1839 | ||
ab25bf1f DK |
1840 | ### The following tests are run by most test methods automatically to check |
1841 | ### general things about commands executed without writing the test every time. | |
1842 | ||
1843 | aptautotest() { | |
1844 | local TESTCALL="$1" | |
1845 | local CMD="$2" | |
1846 | local FIRSTOPT="$3" | |
896f0ae8 | 1847 | local AUTOTEST="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')" |
ab25bf1f DK |
1848 | if command -v $AUTOTEST >/dev/null; then |
1849 | shift 3 | |
1850 | # save and restore the *.output files from other tests | |
1851 | # as we might otherwise override them in these automatic tests | |
63c71412 DK |
1852 | rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" |
1853 | mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" | |
1854 | mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp" | |
ab25bf1f | 1855 | $AUTOTEST "$TESTCALL" "$@" |
63c71412 DK |
1856 | rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest" |
1857 | mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest" | |
1858 | mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp" | |
ab25bf1f DK |
1859 | fi |
1860 | } | |
1861 | ||
1862 | aptautotest_aptget_update() { | |
59148d96 DK |
1863 | local TESTCALL="$1" |
1864 | while [ -n "$2" ]; do | |
1865 | if [ "$2" = '--print-uris' ]; then return; fi # simulation mode | |
1866 | shift | |
1867 | done | |
ab25bf1f | 1868 | if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi |
4bb006d1 DK |
1869 | testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" |
1870 | testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" | |
ab25bf1f | 1871 | # all copied files are properly chmodded |
63c71412 DK |
1872 | local backupIFS="$IFS" |
1873 | IFS="$(printf "\n\b")" | |
146f7715 | 1874 | for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do |
4bb006d1 | 1875 | testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644" |
ab25bf1f | 1876 | done |
63c71412 | 1877 | IFS="$backupIFS" |
59148d96 | 1878 | if [ "$TESTCALL" = 'testsuccess' ]; then |
146f7715 DK |
1879 | # failure cases can retain partial files and such |
1880 | testempty find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \( -name 'lock' -o -name '*.FAILED' \) | |
1881 | fi | |
ab25bf1f DK |
1882 | } |
1883 | aptautotest_apt_update() { aptautotest_aptget_update "$@"; } | |
d84da499 | 1884 | aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; } |
016bea82 DK |
1885 | |
1886 | testaptautotestnodpkgwarning() { | |
1887 | local TESTCALL="$1" | |
1888 | while [ -n "$2" ]; do | |
6bf93605 DK |
1889 | if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi # simulation mode |
1890 | if expr match "$2" '^-dy\?' >/dev/null 2>&1; then return; fi # download-only mode | |
016bea82 DK |
1891 | shift |
1892 | done | |
1893 | testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output" | |
1894 | } | |
1895 | ||
1896 | aptautotest_aptget_install() { testaptautotestnodpkgwarning "$@"; } | |
1897 | aptautotest_aptget_remove() { testaptautotestnodpkgwarning "$@"; } | |
1898 | aptautotest_aptget_purge() { testaptautotestnodpkgwarning "$@"; } | |
1899 | aptautotest_apt_install() { testaptautotestnodpkgwarning "$@"; } | |
1900 | aptautotest_apt_remove() { testaptautotestnodpkgwarning "$@"; } | |
1901 | aptautotest_apt_purge() { testaptautotestnodpkgwarning "$@"; } |