1 #!/bin/sh -- # no runable script, just for vi
5 # we all like colorful messages
6 if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; then
7 if [ ! -t 1 ]; then # but check that we output to a terminal
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
35 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')"
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"; }
54 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
55 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
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
63 EXIT_CODE
=$((EXIT_CODE+1));
66 # enable / disable Debugging
67 MSGLEVEL
=${MSGLEVEL:-3}
68 if [ $MSGLEVEL -le 0 ]; then
71 if [ $MSGLEVEL -le 1 ]; then
75 if [ $MSGLEVEL -le 2 ]; then
79 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
81 if [ $MSGLEVEL -le 3 ]; then
85 if [ $MSGLEVEL -le 4 ]; then
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
97 printf "${CDONE}DONE${CNORMAL}\n";
101 if [ -f .
/aptconfig.conf
]; then
102 echo "$(readlink -f ./aptconfig.conf)"
103 elif [ -f ..
/aptconfig.conf
]; then
104 echo "$(readlink -f ../aptconfig.conf)"
105 elif [ -f ..
/..
/aptconfig.conf
]; then
106 echo "$(readlink -f ../../aptconfig.conf)"
107 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
108 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
112 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
116 sh
|aptitude
|*/*|command) ;;
117 *) CMD
="${BUILDDIRECTORY}/$CMD";;
119 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${LIBRARYPATH} $CMD "$@"
121 aptconfig
() { runapt apt
-config "$@"; }
122 aptcache
() { runapt apt
-cache "$@"; }
123 aptcdrom
() { runapt apt
-cdrom "$@"; }
124 aptget
() { runapt apt
-get "$@"; }
125 aptftparchive
() { runapt apt
-ftparchive "$@"; }
126 aptkey
() { runapt apt
-key "$@"; }
127 aptmark
() { runapt apt
-mark "$@"; }
128 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
129 apt
() { runapt apt
"$@"; }
130 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
131 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
132 aptitude
() { runapt aptitude
"$@"; }
133 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
134 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
135 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
138 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
140 dpkgcheckbuilddeps
() {
141 command dpkg
-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
"$@"
146 aptget
) CMD
="apt-get";;
147 aptcache
) CMD
="apt-cache";;
148 aptcdrom
) CMD
="apt-cdrom";;
149 aptconfig
) CMD
="apt-config";;
150 aptmark
) CMD
="apt-mark";;
151 apthelper
) CMD
="apt-helper";;
152 aptftparchive
) CMD
="apt-ftparchive";;
156 runapt
command gdb
--quiet -ex run
"${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
160 # error if we about to overflow, but ...
161 # "255 failures ought to be enough for everybody"
162 if [ $EXIT_CODE -gt 255 ]; then
163 msgdie
"Total failure count $EXIT_CODE too big"
165 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
168 shellsetedetector
() {
170 if [ "$exit_status" != '0' ]; then
171 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
172 if [ "$EXIT_CODE" = '0' ]; then
173 EXIT_CODE
="$exit_status"
179 if [ "$1" = 'prefix' ]; then
180 CURRENTTRAP
="$2 $CURRENTTRAP"
182 CURRENTTRAP
="$CURRENTTRAP $1"
184 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
188 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
189 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
192 TMPWORKINGDIRECTORY
=$(mktemp -d)
193 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
194 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
196 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
197 if [ "$(id -u)" = '0' ]; then
198 # relax permissions so that running as root with user switching works
200 chmod 711 "$TMPWORKINGDIRECTORY"
201 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
204 TESTDIRECTORY
=$(readlink -f $(dirname $0))
205 # allow overriding the default BUILDDIR location
206 SOURCEDIRECTORY
=${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}
207 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
208 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
209 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
210 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
211 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
212 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
213 APTDUMPSOLVER
=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}
214 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
217 cd $TMPWORKINGDIRECTORY
218 mkdir rootdir aptarchive keys
220 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
221 mkdir -p usr
/bin var
/cache var
/lib var
/log tmp
222 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
223 touch var
/lib
/dpkg
/available
225 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
226 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
227 mkdir -p usr
/lib
/apt
/solvers
228 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
229 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
230 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
232 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
234 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
235 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
237 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
240 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
241 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
242 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
244 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
245 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
246 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
248 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
249 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
250 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
252 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
253 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
254 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
255 echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
256 # store apt-key were we can access it, even if we run it as a different user
257 # destroys coverage reporting though, so just do it for root for now
258 if [ "$(id -u)" = '0' ]; then
259 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
260 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
261 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
263 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
266 cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
269 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
270 if [ -n "\$LD_PRELOAD" ]; then
271 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
273 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
276 exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
277 --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
278 --force-not-root --force-bad-path "\$@"
280 chmod +x
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
281 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
284 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
285 echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
287 echo 'quiet::NoUpdate "true";'
288 echo 'quiet::NoStatistic "true";'
289 # too distracting for users, but helpful to detect changes
290 echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
291 echo 'Acquire::Progress::Diffpercent "true";'
292 # in testcases, it can appear as if localhost has a rotation setup,
293 # hide this as we can't really deal with it properly
294 echo 'Acquire::Failure::ShowIP "false";'
297 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
298 if [ "$(id -u)" = '0' ]; then
299 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
301 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
302 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
303 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
305 # create some files in /tmp and look at user/group to get what this means
306 TEST_DEFAULT_USER
="$USER"
307 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
308 TEST_DEFAULT_GROUP
='root'
310 TEST_DEFAULT_GROUP
="$USER"
313 # Acquire::AllowInsecureRepositories=false is not yet the default
314 # but we want it to be the default soon
315 configallowinsecurerepositories
"false";
317 # cleanup the environment a bit
318 # prefer our apt binaries over the system apt binaries
319 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
320 export LC_ALL
=C.UTF
-8
321 unset LANGUAGE APT_CONFIG
322 unset GREP_OPTIONS DEB_BUILD_PROFILES
328 if [ "$1" = "native" -o -z "$1" ]; then
329 eval `aptconfig shell ARCH APT::Architecture`
330 if [ -n "$ARCH" ]; then
333 dpkg
--print-architecture
341 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
344 getarchitecturesfromcommalist
() {
345 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
348 configarchitecture
() {
350 echo "APT::Architecture \"$(getarchitecture $1)\";"
351 while [ -n "$1" ]; do
352 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
355 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
360 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
361 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
362 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
363 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
365 echo -n > rootdir/var/lib/dpkg/status
368 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
369 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
370 local ARCHS="$(getarchitectures)"
371 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
372 DPKGARCH="$(dpkg --print-architecture)"
373 for ARCH in ${ARCHS}; do
374 if [ "${ARCH}" != "${DPKGARCH}" ]; then
375 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
376 # old-style used e.g. in Ubuntu-P – and as it seems travis
377 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
378 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
382 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
383 # dpkg doesn't really check the version as long as it is fully installed,
384 # but just to be sure we choose one above the required version
385 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
391 configdpkgnoopchroot() {
392 # create a library to noop chroot() and rewrite maintainer script executions
393 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
394 # chroot directory dpkg could chroot into to execute the maintainer scripts
395 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
396 cat << EOF > noopchroot.c
403 static char * chrootdir = NULL;
405 int chroot(const char *path) {
406 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
408 chrootdir = strdup(path);
411 int execvp(const char *file, char *const argv[]) {
412 static int (*func_execvp) (const char *, char * const []) = NULL;
413 if (func_execvp == NULL)
414 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
415 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
416 return func_execvp(file, argv);
417 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
418 char newfile[strlen(chrootdir) + strlen(file)];
419 strcpy(newfile, chrootdir);
420 strcat(newfile, file);
421 char const * const baseadmindir = "/var
/lib
/dpkg
";
422 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
423 strcpy(admindir, chrootdir);
424 strcat(admindir, baseadmindir);
425 setenv("DPKG_ADMINDIR
", admindir, 1);
426 return func_execvp(newfile, argv);
429 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
432 configallowinsecurerepositories() {
433 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
437 configcompression() {
438 while [ -n "$1" ]; do
440 '.') printf ".
\t.
\tcat
\n";;
441 'gz') printf "gzip\tgz
\tgzip
\n";;
442 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
443 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
444 'xz') printf "xz
\txz
\txz
\n";;
445 *) printf "$1\t$1\t$1\n";;
448 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
455 gzip) COMPRESS='gz';;
456 bzip2) COMPRESS='bz2';;
457 lzma) COMPRESS='lzma';;
459 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
461 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
462 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
463 Dir::Bin::uncompressed \"/does/not/exist\";
464 Dir::Bin::gzip \"/does/not/exist\";
465 Dir::Bin::bzip2 \"/does/not/exist\";
466 Dir::Bin::lzma \"/does/not/exist\";
467 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
468 if [ -e "/bin/${COMPRESSOR}" ]; then
469 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
470 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
471 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
472 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
473 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
474 COMPRESSOR_CMD='xz
--format=lzma
'
476 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
481 setupsimplenativepackage() {
485 local RELEASE="${4:-unstable}"
486 local DEPENDENCIES="$5"
487 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
488 If you find such a package installed on your system,
489 something went horribly wrong! They are autogenerated
490 und used only by testcases and surf no other propose…"}"
492 local SECTION="${7:-others}"
494 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
497 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
499 local BUILDDIR=incoming/${NAME}-${VERSION}
500 mkdir -p ${BUILDDIR}/debian/source
502 echo "* most suckless software product ever" > FEATURES
503 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
504 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
508 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
509 test -e debian/control || echo "Source: $NAME
512 Maintainer: Joe Sixpack <joe@example.org>
513 Build-Depends: debhelper (>= 7)
514 Standards-Version: 3.9.1
516 Package: $NAME" > debian/control
517 if [ "$ARCH" = 'all
' ]; then
518 echo "Architecture: all" >> debian/control
520 echo "Architecture: any" >> debian/control
522 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
523 echo "Description: $DESCRIPTION" >> debian/control
525 test -e debian/compat || echo "7" > debian/compat
526 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
527 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
531 buildsimplenativepackage() {
534 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib
' ]; then
535 NM="$(echo "$NAME" | cut -c 1-4)"
537 NM="$(echo "$NAME" | cut -c 1)"
541 local RELEASE="${4:-unstable}"
542 local DEPENDENCIES="$5"
543 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
544 If you find such a package installed on your system,
545 something went horribly wrong! They are autogenerated
546 und used only by testcases and surf no other propose…"}"
548 local SECTION="${7:-others}"
549 local PRIORITY="${8:-optional}"
551 local COMPRESS_TYPE="${10:-gzip}"
553 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
556 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
558 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
560 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
561 mkdir -p $BUILDDIR/debian/source
562 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
564 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
566 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
567 echo "$NAME ($VERSION) $RELEASE; urgency=low
571 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
574 Maintainer: Joe Sixpack <joe@example.org>
575 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
576 if [ "$SECTION" != '<none
>' ]; then
577 echo "Section: $SECTION" >> ${BUILDDIR}/debian/control
579 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
580 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
582 Package: $NAME" >> ${BUILDDIR}/debian/control
584 if [ "$ARCH" = 'all
' ]; then
585 echo "Architecture: all" >> ${BUILDDIR}/debian/control
587 echo "Architecture: any" >> ${BUILDDIR}/debian/control
589 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
590 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
591 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
593 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
595 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
597 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
599 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
600 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
601 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
602 # adv --yes --default-key 'Joe Sixpack' \
603 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
604 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
608 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
609 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
610 rm -rf ${BUILDDIR}/debian
/tmp
611 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
612 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
613 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
614 if [ -n "$FILE_TREE" ]; then
615 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
618 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
619 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
620 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
621 # ensure the right permissions as dpkg-deb insists
622 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
623 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
624 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
627 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
629 cp ${BUILDDIR}/debian
/changelog
$CHANGEPATH
638 local ARCH
=$(getarchitecture $4)
639 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
640 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
641 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
643 if [ "$ARCH" = "all" ]; then
644 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
646 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
647 cp ${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
$BUILDLOG
648 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
649 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
652 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
655 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
660 if [ -d incoming
]; then
661 buildaptarchivefromincoming
"$@"
663 buildaptarchivefromfiles
"$@"
667 createaptftparchiveconfig
() {
668 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
669 local COMPRESSORS
="${COMPRESSORS%* }"
670 local ARCHS
="$(getarchitectures)"
672 ArchiveDir "' >> ftparchive.conf
673 echo -n $(readlink -f .) >> ftparchive.conf
675 CacheDir "' >> ftparchive.conf
676 echo -n $(readlink -f ..) >> ftparchive.conf
678 FileListDir "' >> ftparchive.conf
679 echo -n $(readlink -f pool/) >> ftparchive.conf
683 Packages::Compress "'"$COMPRESSORS"'";
684 Sources::Compress "'"$COMPRESSORS"'";
685 Contents::Compress "'"$COMPRESSORS"'";
686 Translation::Compress "'"$COMPRESSORS"'";
687 LongDescription "false";
691 SrcDirectory "pool/";
697 Label "apttestcases";
699 Description "repository with dummy packages";
700 Architectures "' >> ftparchive.conf
701 echo -n "$ARCHS" >> ftparchive.conf
705 };' >> ftparchive.conf
706 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
707 echo -n 'tree "dists/' >> ftparchive.conf
708 echo -n "$DIST" >> ftparchive.conf
710 Architectures "' >> ftparchive.conf
711 echo -n "$ARCHS" >> ftparchive.conf
713 FileList "' >> ftparchive.conf
714 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
716 SourceFileList "' >> ftparchive.conf
717 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
719 Sections "' >> ftparchive.conf
720 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
722 };' >> ftparchive.conf
726 buildaptftparchivedirectorystructure
() {
727 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
728 for DIST
in $DISTS; do
729 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
730 for SECTION
in $SECTIONS; do
731 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
732 for ARCH
in $ARCHS; do
733 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
735 mkdir -p dists
/${DIST}/${SECTION}/source
736 mkdir -p dists
/${DIST}/${SECTION}/i18n
746 local DEPENDENCIES
="$5"
747 local PRIORITY
="${6:-optional}"
748 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
749 If you find such a package installed on your system,
750 something went horribly wrong! They are autogenerated
751 und used only by testcases and surf no other propose…"}"
753 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
754 if [ "$RELEASE" = 'installed' ]; then
755 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
758 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
759 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
760 ARCHS="$(getarchitectures)"
764 for BUILDARCH in $ARCHS; do
765 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
767 local FILE="${PPATH}/Packages
"
772 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
773 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
774 echo "Version
: $VERSION
775 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
776 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
777 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
778 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
782 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
783 touch aptarchive/dists/${RELEASE}/main/source/Sources
785 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
786 Description
-en: $DESCRIPTION
787 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
796 local DEPENDENCIES="$5"
798 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
800 local FILE="${SPATH}/Sources
"
801 local DSCFILE="${NAME}_
${VERSION}.dsc
"
802 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
806 Maintainer
: Joe Sixpack
<joe@example.org
>
807 Architecture
: $ARCH" >> $FILE
808 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
810 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE
811 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE
815 insertinstalledpackage() {
819 local DEPENDENCIES="$4"
820 local PRIORITY="${5:-optional}"
821 local STATUS="${6:-install ok installed}"
822 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
823 If you
find such a package installed on your system
,
824 something went horribly wrong
! They are autogenerated
825 und used only by testcases and surf no other propose…
"}"
827 local FILE
='rootdir/var/lib/dpkg/status'
828 local INFO
='rootdir/var/lib/dpkg/info'
829 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
835 Maintainer: Joe Sixpack <joe@example.org>
836 Version: $VERSION" >> $FILE
837 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
838 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
839 echo "Description: $DESCRIPTION" >> $FILE
841 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
842 echo -n > ${INFO}/${NAME}:${arch}.list
844 echo -n > ${INFO}/${NAME}.list
850 buildaptarchivefromincoming
() {
851 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
853 [ -e pool
] || ln -s ..
/incoming pool
854 [ -e ftparchive.conf
] || createaptftparchiveconfig
855 [ -e dists
] || buildaptftparchivedirectorystructure
856 msgninfo
"\tGenerate Packages, Sources and Contents files… "
857 testsuccess aptftparchive generate ftparchive.conf
860 generatereleasefiles
"$@"
863 buildaptarchivefromfiles
() {
864 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
865 local DIR
='aptarchive'
866 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
867 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
868 msgninfo
"\t${line} file… "
869 compressfile
"$line" "$1"
872 generatereleasefiles
"$@"
876 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
877 if [ "$compressor" = '.' ]; then
883 cat "$1" | $command > "${1}.${extension}"
885 touch -d "$2" "${1}.${extension}"
890 # can be overridden by testcases for their pleasure
891 getcodenamefromsuite
() {
893 unstable
) echo 'sid';;
897 getreleaseversionfromsuite
() { true
; }
898 getlabelfromsuite
() { true
; }
899 getoriginfromsuite
() { true
; }
901 generatereleasefiles
() {
902 # $1 is the Date header and $2 is the ValidUntil header to be set
903 # both should be given in notation date/touch can understand
904 msgninfo
"\tGenerate Release files… "
905 if [ -e aptarchive
/dists
]; then
906 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
907 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
908 local CODENAME
="$(getcodenamefromsuite $SUITE)"
909 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
910 local LABEL
="$(getlabelfromsuite $SUITE)"
911 local ORIGIN
="$(getoriginfromsuite $SUITE)"
912 if [ -n "$VERSION" ]; then
913 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
915 if [ -n "$LABEL" ]; then
916 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
918 if [ -n "$ORIGIN" ]; then
919 ORIGIN
="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
921 aptftparchive
-qq release
$dir \
922 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
923 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
927 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
928 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
930 NotAutomatic: yes' $dir/Release
932 if [ -n "$1" -a "$1" != "now" ]; then
933 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
937 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
941 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
943 if [ -n "$1" -a "$1" != "now" ]; then
944 for release
in $(find ./aptarchive -name 'Release'); do
945 touch -d "$1" $release
951 setupdistsaptarchive
() {
952 local APTARCHIVE
=$(readlink -f ./aptarchive)
953 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
954 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
955 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
956 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
957 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
958 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
959 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
964 setupflataptarchive
() {
965 local APTARCHIVE
=$(readlink -f ./aptarchive)
966 if [ -f ${APTARCHIVE}/Packages
]; then
967 msgninfo
"\tadd deb sources.list line… "
968 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
971 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
973 if [ -f ${APTARCHIVE}/Sources
]; then
974 msgninfo
"\tadd deb-src sources.list line… "
975 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
978 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
984 if [ "$1" = '--no-update' ]; then
989 if [ -e aptarchive
/dists
]; then
994 signreleasefiles
'Joe Sixpack'
995 if [ "1" != "$NOUPDATE" ]; then
996 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1000 signreleasefiles
() {
1001 local SIGNER
="${1:-Joe Sixpack}"
1002 local REPODIR
="${2:-aptarchive}"
1003 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1004 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
1005 msgninfo
"\tSign archive with $SIGNER key $KEY… "
1006 local REXKEY
='keys/rexexpired'
1007 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1008 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1009 if [ "${SIGNER}" = 'Rex Expired' ]; then
1010 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1011 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1012 # therefore we 'temporary' make the key not expired and restore a backup after signing
1013 cp ${REXKEY}.sec
$SECEXPIREBAK
1014 cp ${REXKEY}.pub
$PUBEXPIREBAK
1015 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1016 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1017 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1018 cp $SECUNEXPIRED ${REXKEY}.sec
1019 cp $PUBUNEXPIRED ${REXKEY}.pub
1021 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1025 cp ${REXKEY}.sec
$SECUNEXPIRED
1026 cp ${REXKEY}.pub
$PUBUNEXPIRED
1029 for RELEASE
in $(find ${REPODIR}/ -name Release); do
1030 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
1031 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1032 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
1033 # we might have set a specific date for the Release file, so copy it
1034 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
1036 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1037 mv -f $SECEXPIREBAK ${REXKEY}.sec
1038 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1043 redatereleasefiles
() {
1044 local DATE
="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1045 for release
in $(find aptarchive/ -name 'Release'); do
1046 sed -i "s/^Date: .*$/Date: ${DATE}/" $release
1047 touch -d "$DATE" $release
1049 signreleasefiles
"${2:-Joe Sixpack}"
1053 local WEBSERVER
="${3:-http://localhost:8080}"
1055 if [ "$1" = '--no-check' ]; then
1059 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1060 local STATUS
='downloaded/webserverconfig.status'
1061 rm -f "$STATUS" "$DOWNLOG"
1063 if [ -n "$2" ]; then
1064 msgtest
"Set webserver config option '${1}' to" "$2"
1065 URI
="${WEBSERVER}/_config/set/${1}/${2}"
1067 msgtest
'Clear webserver config option' "${1}"
1068 URI
="${WEBSERVER}/_config/clear/${1}"
1070 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1073 cat "$DOWNLOG" "$STATUS" || true
1076 $NOCHECK || testwebserverlaststatuscode
'200'
1079 rewritesourceslist
() {
1080 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1081 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1082 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
1086 # wait for up to 10s for a pid file to appear to avoid possible race
1087 # when a helper is started and dosn't write the PID quick enough
1090 for i
in $(seq 10); do
1091 if test -s "$PIDFILE"; then
1096 msgdie
"waiting for $PIDFILE failed"
1100 changetowebserver
() {
1101 if [ "$1" != '--no-rewrite' ]; then
1102 rewritesourceslist
'http://localhost:8080/'
1106 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1108 local LOG
="webserver.log"
1109 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1113 waitforpidfile aptwebserver.pid
1114 local PID
="$(cat aptwebserver.pid)"
1115 if [ -z "$PID" ]; then
1116 msgdie
'Could not fork aptwebserver successfully'
1118 addtrap
"kill $PID;"
1121 msgdie
'You have to build aptwerbserver or install a webserver'
1125 changetohttpswebserver
() {
1126 if ! which stunnel4
>/dev
/null
; then
1127 msgdie
'You need to install stunnel4 for https testcases'
1129 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1130 changetowebserver
--no-rewrite "$@"
1132 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1133 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1139 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1140 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1141 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1142 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1143 if [ -z "$PID" ]; then
1144 msgdie
'Could not fork stunnel4 successfully'
1146 addtrap
'prefix' "kill ${PID};"
1147 rewritesourceslist
'https://localhost:4433/'
1151 mkdir -p rootdir
/media
/cdrom
/.disk
1152 local CD
="$(readlink -f rootdir/media/cdrom)"
1153 echo "acquire::cdrom::mount \"${CD}\";
1154 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1155 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1156 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1157 echo -n "$1" > ${CD}/.disk
/info
1158 if [ ! -d aptarchive
/dists
]; then
1159 msgdie
'Flat file archive cdroms can not be created currently'
1162 mv aptarchive
/dists
"$CD"
1163 ln -s "$(readlink -f ./incoming)" $CD/pool
1164 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1165 # start with an unmounted disk
1166 mv "${CD}" "${CD}-unmounted"
1167 # we don't want the disk to be modifiable
1168 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1169 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1173 local PROTO
="${1%%:*}"
1174 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1175 download
-file "$1" "$2" "$3" 2>&1 ; then
1178 # only if the file exists the download was successful
1179 if [ -r "$2" ]; then
1187 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1188 if [ -n "$DIFFTEXT" ]; then
1190 echo >&2 "$DIFFTEXT"
1200 msgtest
"Test for correctness of file" "$FILE"
1201 if [ -z "$*" ]; then
1202 echo -n "" | checkdiff
- $FILE && msgpass
|| msgfail
1204 echo "$*" | checkdiff
- $FILE && msgpass
|| msgfail
1209 msgtest
"Test for no output of" "$*"
1210 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1211 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1218 aptautotest
'testempty' "$@"
1222 local MSG
='Test of equality of'
1223 if [ "$1" = '--nomsg' ]; then
1228 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1229 echo "$1" > $COMPAREFILE
1232 if [ -n "$MSG" ]; then
1235 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1236 aptautotest
'testequal' "$@"
1240 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1241 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1242 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1243 echo "$1" > $COMPAREFILE1
1244 echo "$2" > $COMPAREFILE2
1246 msgtest
"Test for equality OR of" "$*"
1247 "$@" >$COMPAREAGAINST 2>&1 || true
1248 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1249 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1253 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1254 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1255 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1256 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1259 aptautotest
'testequalor2' "$@"
1263 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1266 while [ -n "$1" ]; do
1268 N: Can't select versions from package '$1' as it is purely virtual"
1269 PACKAGE
="${PACKAGE} $1"
1272 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1274 N: No packages found"
1275 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1276 local ARCH
="$(getarchitecture 'native')"
1277 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1278 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1282 msgtest
"Test for non-existent packages" "apt-cache show $*"
1283 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1284 if [ -n "$SHOWPKG" ]; then
1297 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1298 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1299 if [ "$PKGS" != $NR ]; then
1301 dpkg
-l "$@" | grep '^[a-z]' >&2 || true
1308 testdpkginstalled
() {
1309 testdpkgstatus
'ii' "$#" "$@"
1312 testdpkgnotinstalled
() {
1313 testdpkgstatus
'ii' '0' "$@"
1317 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1318 if [ -n "$1" ]; then
1319 msgtest
'Test for correctly marked as auto-installed' "$*"
1320 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1322 msgtest
'Test for correctly marked as auto-installed' 'no package'
1323 echo -n > $COMPAREFILE
1325 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1327 testmarkedmanual
() {
1328 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1329 if [ -n "$1" ]; then
1330 msgtest
'Test for correctly marked as manually installed' "$*"
1331 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1333 msgtest
'Test for correctly marked as manually installed' 'no package'
1334 echo -n > $COMPAREFILE
1336 aptmark showmanual
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1344 if [ "$1" = 'grep' ]; then
1345 while [ -n "$2" ]; do shift; done
1346 echo "#### Complete file: $1 ####"
1347 cat >&2 "$1" || true
1348 echo '#### grep output ####'
1349 elif [ "$1" = 'test' ]; then
1350 # doesn't support ! or non-file flags
1351 msgfailoutputstatfile
() {
1352 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1353 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1354 echo "#### stat(2) of file: $2 ####"
1358 msgfailoutputstatfile
"$2" "$3"
1359 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1361 msgfailoutputstatfile
"$2" "$3"
1363 echo '#### test output ####'
1370 if [ "$1" = '--nomsg' ]; then
1373 msgtest
'Test for successful execution of' "$*"
1375 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1376 if "$@" >${OUTPUT} 2>&1; then
1377 if expr match
"$1" '^apt.*' >/dev
/null
; then
1378 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1379 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1380 elif grep -E '^[WE]: ' "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1381 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1382 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1383 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1386 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1389 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1399 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1401 aptautotest
'testsuccess' "$@"
1404 if [ "$1" = '--nomsg' ]; then
1407 msgtest
'Test for successful execution with warnings of' "$*"
1409 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1410 if "$@" >${OUTPUT} 2>&1; then
1411 if expr match
"$1" '^apt.*' >/dev
/null
; then
1412 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1413 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1414 elif grep -q -E '^E: ' "$OUTPUT"; then
1415 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1416 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1417 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1428 msgfail
"exitcode $EXITCODE"
1430 aptautotest
'testwarning' "$@"
1433 if [ "$1" = '--nomsg' ]; then
1436 msgtest
'Test for failure in execution of' "$*"
1438 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1439 if "$@" >${OUTPUT} 2>&1; then
1441 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1444 if expr match
"$1" '^apt.*' >/dev
/null
; then
1445 if [ "$1" = 'aptkey' ]; then
1446 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1447 grep -q -E " BAD signature from " "$OUTPUT"; then
1450 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1453 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1454 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1455 elif grep -q -E '==ERROR' "$OUTPUT"; then
1456 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1457 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1458 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1467 aptautotest
'testfailure' "$@"
1470 testsuccessequal
() {
1474 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
1476 testwarningequal
() {
1480 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
1482 testfailureequal
() {
1486 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
1493 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1494 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output" 2>&1 || true
1495 if echo "$CMP" | checkdiff
- "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output"; then
1498 echo '### Complete output ###'
1499 cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1505 msgtest
"Test that file $1 has $2 $3" "$4"
1506 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1510 ls -ld >&2 "$1" || true
1511 echo -n >&2 "stat(1) reports for $2: "
1512 stat
--format "$2" "$1" || true
1516 testaccessrights
() {
1517 testfilestats
"$1" '%a' '=' "$2"
1520 testwebserverlaststatuscode
() {
1521 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1522 local STATUS
='downloaded/webserverstatus-statusfile.log'
1523 rm -f "$DOWNLOG" "$STATUS"
1524 msgtest
'Test last status code from the webserver was' "$1"
1525 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1529 if [ -n "$2" ]; then
1531 echo >&2 '#### Additionally provided output files contain:'
1534 echo >&2 '#### Download log of the status code:'
1536 msgfail
"Status was $(cat "$STATUS")"
1541 echo "STOPPED execution. Press enter to continue"
1546 listcurrentlistsdirectory
() {
1548 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1549 stat
--format '%U:%G:%a:%n' "$line"
1551 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1552 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1557 ### convinience hacks ###
1559 # creating some directories by hand is a tedious task, so make it look simple
1560 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1561 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1562 # only the last directory created by mkdir is effected by the -m !
1563 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1564 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1565 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1566 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1567 if [ "$(id -u)" = '0' ]; then
1568 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1575 ### The following tests are run by most test methods automatically to check
1576 ### general things about commands executed without writing the test every time.
1582 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1583 if command -v $AUTOTEST >/dev
/null
; then
1585 # save and restore the *.output files from other tests
1586 # as we might otherwise override them in these automatic tests
1587 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1588 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1589 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1590 $AUTOTEST "$TESTCALL" "$@"
1591 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1592 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1593 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1597 aptautotest_aptget_update
() {
1599 while [ -n "$2" ]; do
1600 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1603 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1604 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1605 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1606 # all copied files are properly chmodded
1607 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1608 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1610 if [ "$TESTCALL" = 'testsuccess' ]; then
1611 # failure cases can retain partial files and such
1612 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1615 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1616 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1618 testaptautotestnodpkgwarning
() {
1620 while [ -n "$2" ]; do
1621 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1622 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1625 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1628 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1629 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1630 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1631 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1632 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1633 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }