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