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