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