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