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