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