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