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