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