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