1 #!/bin/sh -- # no runable script, just for vi 
   6         if [ "$1" = "-q" ]; then 
   8         elif [ "$1" = "-v" ]; then 
  10         elif [ "$1" = '--color=no' ]; then 
  13                 echo >&2 "WARNING: Unknown parameter »$1« will be ignored" 
  17 export MSGLEVEL
="${MSGLEVEL:-3}" 
  19 # we all like colorful messages 
  20 if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; then 
  21         if [ ! -t 1 ]; then # but check that we output to a terminal 
  27 if [ "$MSGCOLOR" != 'NO' ]; then 
  28         CERROR
="\033[1;31m" # red 
  29         CWARNING
="\033[1;33m" # yellow 
  30         CMSG
="\033[1;32m" # green 
  31         CINFO
="\033[1;96m" # light blue 
  32         CDEBUG
="\033[1;94m" # blue 
  33         CNORMAL
="\033[0;39m" # default system console color 
  34         CDONE
="\033[1;32m" # green 
  35         CPASS
="\033[1;32m" # green 
  36         CFAIL
="\033[1;31m" # red 
  37         CCMD
="\033[1;35m" # pink 
  49                         printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')" 
  55 msgdie
() { msgprintf 
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; } 
  56 msgwarn
() { msgprintf 
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; } 
  57 msgmsg
() { msgprintf 
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; } 
  58 msginfo
() { msgprintf 
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; } 
  59 msgdebug
() { msgprintf 
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; } 
  60 msgdone
() { msgprintf 
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; } 
  61 msgnwarn
() { msgprintf 
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; } 
  62 msgnmsg
() { msgprintf 
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; } 
  63 msgninfo
() { msgprintf 
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; } 
  64 msgndebug
() { msgprintf 
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; } 
  65 msgtest
() { msgprintf 
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; } 
  66 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; } 
  68         if [ -n "$MSGTEST_MSG" ]; then 
  69                 test "$1" != 'msgfailoutput' || echo 
  70                 if [ -n "$MSGTEST_MSGMSG" ]; then 
  71                         echo "$MSGTEST_MSGMSG" 
  73                 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then 
  74                         echo "${CFAIL}Part of the test group: $MSGTEST_GRP" 
  76                 echo -n "$MSGTEST_MSG" 
  81         msgreportheader 
'msgskip' 
  82         if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2; 
  83         else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi 
  86         msgreportheader 
'msgfail' 
  87         if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2; 
  88         else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi 
  89         if [ -n "$APT_DEBUG_TESTS" ]; then 
  92         EXIT_CODE
=$((EXIT_CODE+1)); 
  97                 if [ $MSGGROUP_LEVEL = 0 ]; then 
 100                 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1)); 
 102                 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1)); 
 103                 if [ $MSGGROUP_LEVEL = 0 ]; then 
 109 # enable / disable Debugging 
 110 if [ $MSGLEVEL -le 0 ]; then 
 113 if [ $MSGLEVEL -le 1 ]; then 
 117 if [ $MSGLEVEL -le 2 ]; then 
 119                 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")" 
 123                 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")" 
 124                 if [ "$MSGTEST_GRP" = 'NEXT' ]; then 
 125                         MSGTEST_GRP
="$MSGTEST_MSG" 
 128         msgpass
() { printf " ${CPASS}P${CNORMAL}"; } 
 130 if [ $MSGLEVEL -le 3 ]; then 
 134 if [ $MSGLEVEL -le 4 ]; then 
 136         msgndebug
() { true
; } 
 139         if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] || 
 140            [ "$1" = "info" -a $MSGLEVEL -le 3 ] || 
 141            [ "$1" = "msg" -a $MSGLEVEL -le 2 ] || 
 142            [ "$1" = "warn" -a $MSGLEVEL -le 1 ] || 
 143            [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then 
 146                 printf "${CDONE}DONE${CNORMAL}\n"; 
 150         if [ -f .
/aptconfig.conf 
]; then 
 151                 echo "$(readlink -f ./aptconfig.conf)" 
 152         elif [ -f ..
/aptconfig.conf 
]; then 
 153                 echo "$(readlink -f ../aptconfig.conf)" 
 154         elif [ -f ..
/..
/aptconfig.conf 
]; then 
 155                 echo "$(readlink -f ../../aptconfig.conf)" 
 156         elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then 
 157                 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")" 
 161         msgdebug 
"Executing: ${CCMD}$*${CDEBUG} " 
 165         sh
|aptitude
|*/*|command) ;; 
 166         *) CMD
="${BUILDDIRECTORY}/$CMD";; 
 168         MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${LIBRARYPATH} $CMD "$@" 
 170 aptconfig
() { runapt apt
-config "$@"; } 
 171 aptcache
() { runapt apt
-cache "$@"; } 
 172 aptcdrom
() { runapt apt
-cdrom "$@"; } 
 173 aptget
() { runapt apt
-get "$@"; } 
 174 aptftparchive
() { runapt apt
-ftparchive "$@"; } 
 175 aptkey
() { runapt apt
-key "$@"; } 
 176 aptmark
() { runapt apt
-mark "$@"; } 
 177 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; } 
 178 apt
() { runapt apt 
"$@"; } 
 179 apthelper
() { runapt 
"${APTHELPERBINDIR}/apt-helper" "$@"; } 
 180 aptwebserver
() { runapt 
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; } 
 181 aptitude
() { runapt aptitude 
"$@"; } 
 182 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; } 
 183 aptinternalsolver
() { runapt 
"${APTINTERNALSOLVER}" "$@"; } 
 184 aptdumpsolver
() { runapt 
"${APTDUMPSOLVER}" "$@"; } 
 187         "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@" 
 189 dpkgcheckbuilddeps
() { 
 190         command dpkg
-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg 
"$@" 
 195         aptget
) CMD
="apt-get";; 
 196         aptcache
) CMD
="apt-cache";; 
 197         aptcdrom
) CMD
="apt-cdrom";; 
 198         aptconfig
) CMD
="apt-config";; 
 199         aptmark
) CMD
="apt-mark";; 
 200         apthelper
) CMD
="apt-helper";; 
 201         aptftparchive
) CMD
="apt-ftparchive";; 
 202         dpkg
) shift; runapt 
${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg "$@"; return;; 
 206         if [ "${CMD##*/}" = "$CMD" ]; then 
 207                 CMD
="${BUILDDIRECTORY}/${CMD}" 
 209         runapt 
command gdb 
--quiet -ex run 
"$CMD" --args "$CMD" "$@" 
 213         # error if we about to overflow, but ... 
 214         #   "255 failures ought to be enough for everybody" 
 215         if [ $EXIT_CODE -gt 255 ]; then 
 216             msgdie 
"Total failure count $EXIT_CODE too big" 
 218         exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255)); 
 221 shellsetedetector
() { 
 223         if [ "$exit_status" != '0' ]; then 
 224                 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n" 
 225                 if [ "$EXIT_CODE" = '0' ]; then 
 226                         EXIT_CODE
="$exit_status" 
 232         if [ "$1" = 'prefix' ]; then 
 233                 CURRENTTRAP
="$2 $CURRENTTRAP" 
 235                 CURRENTTRAP
="$CURRENTTRAP $1" 
 237         trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
 
 241         # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir) 
 242         if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then 
 245         TMPWORKINGDIRECTORY
=$(mktemp -d) 
 246         addtrap 
"cd /; rm -rf $TMPWORKINGDIRECTORY;" 
 247         msgninfo 
"Preparing environment for $(basename $0) in ${TMPWORKINGDIRECTORY}…" 
 249         mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded" 
 250         if [ "$(id -u)" = '0' ]; then 
 251                 # relax permissions so that running as root with user switching works 
 253                 chmod 711 "$TMPWORKINGDIRECTORY" 
 254                 chown _apt
:root 
"${TMPWORKINGDIRECTORY}/downloaded" 
 257         TESTDIRECTORY
=$(readlink -f $(dirname $0)) 
 258         # allow overriding the default BUILDDIR location 
 259         SOURCEDIRECTORY
=${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"} 
 260         BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"} 
 261         LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"} 
 262         METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"} 
 263         APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"} 
 264         APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"} 
 265         APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"} 
 266         APTDUMPSOLVER
=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"} 
 267         test -x "${BUILDDIRECTORY}/apt-get" || msgdie 
"You need to build tree first" 
 270         cd $TMPWORKINGDIRECTORY 
 271         mkdir rootdir aptarchive keys
 
 273         mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
 
 274         mkdir -p usr
/bin var
/cache var
/lib var
/log tmp
 
 275         mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
 
 276         touch var
/lib
/dpkg
/available
 
 278         ln -s ${METHODSDIR} usr
/lib
/apt
/methods
 
 279         if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then 
 280                 mkdir -p usr
/lib
/apt
/solvers
 
 281                 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
 
 282                 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
 
 283                 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
 
 285         # use the autoremove from the BUILDDIRECTORY if its there, otherwise 
 287         if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove 
]; then 
 288             ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
 
 290             ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
 
 293         local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/') 
 294         if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then 
 295                 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages 
 297         local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/') 
 298         if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then 
 299                 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
 
 301         cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/ 
 302         chmod 644 $(find keys -name '*.pub' -o -name '*.sec') 
 303         ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
 
 305         echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
 
 306         echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
 
 307         echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
 
 308         echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
 
 309         # store apt-key were we can access it, even if we run it as a different user 
 310         # destroys coverage reporting though, so just do it for root for now 
 311         if [ "$(id -u)" = '0' ]; then 
 312                 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/" 
 313                 chmod o
+rx 
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key" 
 314                 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
 
 316                 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
 
 319         cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" 
 322 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then 
 323         if [ -n "\$LD_PRELOAD" ]; then 
 324                 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}" 
 326                 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so" 
 329 exec fakeroot ${DPKG:-dpkg} --root="${TMPWORKINGDIRECTORY}/rootdir" \\ 
 330         --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\ 
 331         --force-not-root --force-bad-path "\$@" 
 333         cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" 
 336 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then 
 337         if [ -n "\$LD_PRELOAD" ]; then 
 338                 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}" 
 340                 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so" 
 343 exec fakeroot gdb --quiet -ex run "${DPKG:-dpkg}" --args "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir" \\ 
 344         --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\ 
 345         --force-not-root --force-bad-path "\$@" 
 347         chmod +x 
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" 
 348         echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
 
 351                 if ! command dpkg 
--assert-multi-arch >/dev
/null 
2>&1; then 
 352                         echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it… 
 354                 echo 'quiet::NoUpdate "true";' 
 355                 echo 'quiet::NoStatistic "true";' 
 356                 # too distracting for users, but helpful to detect changes 
 357                 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' 
 358                 echo 'Acquire::Progress::Diffpercent "true";' 
 359                 # in testcases, it can appear as if localhost has a rotation setup, 
 360                 # hide this as we can't really deal with it properly 
 361                 echo 'Acquire::Failure::ShowIP "false";' 
 364         cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" 
 365         if [ "$(id -u)" = '0' ]; then 
 366                 chown _apt
:root 
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" 
 368         echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
 
 369         echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary 
 370         configcompression 
'.' 'gz' #'bz2' 'lzma' 'xz' 
 371         confighashes 
'SHA1' # these are tests, not security best-practices 
 373         # create some files in /tmp and look at user/group to get what this means 
 374         TEST_DEFAULT_USER
="$USER" 
 375         if [ "$(uname)" = 'GNU/kFreeBSD' ]; then 
 376                 TEST_DEFAULT_GROUP
='root' 
 378                 TEST_DEFAULT_GROUP
="$USER" 
 381         # Acquire::AllowInsecureRepositories=false is not yet the default 
 382         # but we want it to be the default soon 
 383         configallowinsecurerepositories 
"false"; 
 385         # cleanup the environment a bit 
 386         # prefer our apt binaries over the system apt binaries 
 387         export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin" 
 388         export LC_ALL
=C.UTF
-8 
 389         unset LANGUAGE APT_CONFIG
 
 390         unset GREP_OPTIONS DEB_BUILD_PROFILES
 
 395         if [ "$1" = "native" -o -z "$1" ]; then 
 396                 eval `aptconfig shell ARCH APT::Architecture` 
 397                 if [ -n "$ARCH" ]; then 
 400                         dpkg 
--print-architecture 
 408         aptconfig dump 
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures 
| sort -u | tr '\n' ' ' 
 411 getarchitecturesfromcommalist
() { 
 412         echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/" 
 415 configarchitecture
() { 
 417                 echo "APT::Architecture \"$(getarchitecture $1)\";" 
 418                 while [ -n "$1" ]; do 
 419                         echo "APT::Architectures:: \"$(getarchitecture $1)\";" 
 422         } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
 
 427         if [ ! -e rootdir
/var
/lib
/dpkg
/status 
]; then 
 428                 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/') 
 429                 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then 
 430                         cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status 
 432                         echo -n > rootdir/var/lib/dpkg/status 
 435         rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg 
 436         if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then 
 437                 local ARCHS="$(getarchitectures)" 
 438                 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then 
 439                         DPKGARCH="$(dpkg --print-architecture)" 
 440                         for ARCH in ${ARCHS}; do 
 441                                 if [ "${ARCH}" != "${DPKGARCH}" ]; then 
 442                                         if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then 
 443                                                 # old-style used e.g. in Ubuntu-P – and as it seems travis 
 444                                                 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg 
 445                                                 echo "DPKG
::options
:: \"${ARCH}\";"  >> rootdir/etc/apt/apt.conf.d/00foreigndpkg 
 449                         if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then 
 450                                 # dpkg doesn't really check the version as long as it is fully installed, 
 451                                 # but just to be sure we choose one above the required version 
 452                                 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake' 
 458 configdpkgnoopchroot() { 
 459         # create a library to noop chroot() and rewrite maintainer script executions 
 460         # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown 
 461         # chroot directory dpkg could chroot into to execute the maintainer scripts 
 462         msgtest 'Building library to preload to make maintainerscript work in' 'dpkg' 
 463         cat << EOF > noopchroot.c 
 470 static char * chrootdir = NULL; 
 472 int chroot(const char *path) { 
 473         printf("WARNING
: CHROOTing to 
%s was ignored
!\n", path); 
 475         chrootdir = strdup(path); 
 478 int execvp(const char *file, char *const argv[]) { 
 479         static int (*func_execvp) (const char *, char * const []) = NULL; 
 480         if (func_execvp == NULL) 
 481                 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
"); 
 482         if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0) 
 483                 return func_execvp(file, argv); 
 484         printf("REWRITE execvp call 
%s into 
%s
\n", file, chrootdir); 
 485         char newfile[strlen(chrootdir) + strlen(file)]; 
 486         strcpy(newfile, chrootdir); 
 487         strcat(newfile, file); 
 488         char const * const baseadmindir = "/var
/lib
/dpkg
"; 
 489         char admindir[strlen(chrootdir) + strlen(baseadmindir)]; 
 490         strcpy(admindir, chrootdir); 
 491         strcat(admindir, baseadmindir); 
 492         setenv("DPKG_ADMINDIR
", admindir, 1); 
 493         return func_execvp(newfile, argv); 
 496         testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl 
 499 configallowinsecurerepositories() { 
 500     echo "Acquire
::AllowInsecureRepositories 
\"$1\";" >  rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf 
 504 configcompression() { 
 505         while [ -n "$1" ]; do 
 507                 '.') printf ".
\t.
\tcat
\n";; 
 508                 'gz') printf "gzip\tgz
\tgzip
\n";; 
 509                 'bz2') printf "bzip2\tbz
2\tbzip
2\n";; 
 510                 'lzma') printf "lzma
\tlzma
\txz 
--format=lzma
\n";; 
 511                 'xz') printf "xz
\txz
\txz
\n";; 
 512                 *) printf "$1\t$1\t$1\n";; 
 515         done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf 
 519                 echo 'APT::FTPArchive {' 
 521                         while [ -n "$1" ]; do 
 522                                 printf "$1" | tr 'a-z' 'A-Z' 
 523                                 printf "\t\"true
\";\n" 
 526                         for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do 
 527                                 printf "$h\t\"false
\";\n" 
 531         } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
" 
 537         gzip) COMPRESS='gz';; 
 538         bzip2) COMPRESS='bz2';; 
 539         lzma) COMPRESS='lzma';; 
 541         *) msgdie "Compressor 
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";; 
 543         local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor" 
 544         echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; }; 
 545 Dir::Bin::uncompressed \"/does/not/exist\"; 
 546 Dir::Bin::gzip \"/does/not/exist\"; 
 547 Dir::Bin::bzip2 \"/does/not/exist\"; 
 548 Dir::Bin::lzma \"/does/not/exist\"; 
 549 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE" 
 550         if [ -e "/bin/${COMPRESSOR}" ]; then 
 551                 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE" 
 552         elif [ -e "/usr/bin/${COMPRESSOR}" ]; then 
 553                 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE" 
 554         elif [ "${COMPRESSOR}" = 'lzma
' ]; then 
 555                 echo 'Dir
::Bin
::xz 
"/usr/bin/xz";' >> "$CONFFILE" 
 556                 COMPRESSOR_CMD='xz 
--format=lzma
' 
 558                 msgtest 'Test 
for availability of compressor
' "${COMPRESSOR}" 
 559                 msgfail "${COMPRESSOR} not available" 
 563 setupsimplenativepackage() { 
 567         local RELEASE="${4:-unstable}" 
 568         local DEPENDENCIES="$5" 
 569         local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} 
 570  If you find such a package installed on your system, 
 571  something went horribly wrong! They are autogenerated 
 572  und used only by testcases and surf no other propose…"}" 
 574         local SECTION="${7:-others}" 
 576         if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then 
 579                 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" 
 581         local BUILDDIR=incoming/${NAME}-${VERSION} 
 582         mkdir -p ${BUILDDIR}/debian/source 
 584         echo "* most suckless software product ever" > FEATURES 
 585         test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright 
 586         test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low 
 590  -- Joe Sixpack <joe@example.org>  $(date -R)" > debian/changelog 
 591         test -e debian/control || echo "Source: $NAME 
 594 Maintainer: Joe Sixpack <joe@example.org> 
 595 Build-Depends: debhelper (>= 7) 
 596 Standards-Version: 3.9.1 
 598 Package: $NAME" > debian/control 
 599         if [ "$ARCH" = 'all
' ]; then 
 600                 echo "Architecture: all" >> debian/control 
 602                 echo "Architecture: any" >> debian/control 
 604         test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control 
 605         echo "Description: $DESCRIPTION" >> debian/control 
 607         test -e debian/compat || echo "7" > debian/compat 
 608         test -e debian/source/format || echo "3.0 (native)" > debian/source/format 
 609         test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules 
 613 buildsimplenativepackage() { 
 616         if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib
' ]; then 
 617                 NM="$(echo "$NAME" | cut -c 1-4)" 
 619                 NM="$(echo "$NAME" | cut -c 1)" 
 623         local RELEASE="${4:-unstable}" 
 624         local DEPENDENCIES="$5" 
 625         local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} 
 626  If you find such a package installed on your system, 
 627  something went horribly wrong! They are autogenerated 
 628  und used only by testcases and surf no other propose…"}" 
 630         local SECTION="${7:-others}" 
 631         local PRIORITY="${8:-optional}" 
 633         local COMPRESS_TYPE="${10:-gzip}" 
 635         if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then 
 638                 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" 
 640         local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION} 
 642         msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME" 
 643         mkdir -p $BUILDDIR/debian/source 
 644         echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES 
 646 echo '$NAME says 
\"Hello
!\"'" > ${BUILDDIR}/${NAME} 
 648         echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright 
 649         echo "$NAME ($VERSION) $RELEASE; urgency=low 
 653  -- Joe Sixpack <joe@example.org>  $(date -R)" > ${BUILDDIR}/debian/changelog 
 656 Maintainer: Joe Sixpack <joe@example.org> 
 657 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control 
 658         if [ "$SECTION" != '<none
>' ]; then 
 659                 echo "Section: $SECTION" >> ${BUILDDIR}/debian/control 
 661         local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')" 
 662         test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control 
 664 Package: $NAME" >> ${BUILDDIR}/debian/control 
 666         if [ "$ARCH" = 'all
' ]; then 
 667                 echo "Architecture: all" >> ${BUILDDIR}/debian/control 
 669                 echo "Architecture: any" >> ${BUILDDIR}/debian/control 
 671         local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')" 
 672         test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control 
 673         echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control 
 675         echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format 
 677         testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION} 
 679         sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \ 
 681                 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
 
 682 #               if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then 
 683 #                       aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \ 
 684 #                               adv --yes --default-key 'Joe Sixpack' \ 
 685 #                               --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC" 
 686 #                       mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC" 
 690         for arch 
in $(getarchitecturesfromcommalist "$ARCH"); do 
 691                 msgtest 
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME" 
 692                 rm -rf ${BUILDDIR}/debian
/tmp
 
 693                 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN 
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
 
 694                 cp ${BUILDDIR}/debian
/copyright 
${BUILDDIR}/debian
/changelog 
${BUILDDIR}/FEATURES 
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} 
 695                 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch} 
 696                 if [ -n "$FILE_TREE" ]; then 
 697                     cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
 
 700                 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch) 
 701                 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
) 
 702                 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log" 
 703                 # ensure the right permissions as dpkg-deb insists 
 704                 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
 
 705                 testsuccess 
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp 
${BUILDDIR}/..
 
 706                 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
 
 709         local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}" 
 711         cp ${BUILDDIR}/debian
/changelog 
$CHANGEPATH 
 720         local ARCH
=$(getarchitecture $4) 
 721         local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')" 
 722         local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")" 
 723         msgtest 
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME" 
 725         if [ "$ARCH" = "all" ]; then 
 726                 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" 
 728         testsuccess 
--nomsg dpkg
-buildpackage -uc -us -a$ARCH 
 729         cp ${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output 
$BUILDLOG 
 730         local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")" 
 731         local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')" 
 734                 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
 
 737                 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
 
 742         if [ -d incoming 
]; then 
 743                 buildaptarchivefromincoming 
"$@" 
 745                 buildaptarchivefromfiles 
"$@" 
 749 createaptftparchiveconfig
() { 
 750         local COMPRESSORS
="$(cut -d'    ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')" 
 751         local COMPRESSORS
="${COMPRESSORS%* }" 
 752         local ARCHS
="$(getarchitectures)" 
 753         cat > ftparchive.conf 
<<EOF 
 755         ArchiveDir "$(readlink -f .)"; 
 756         CacheDir "$(readlink -f ..)"; 
 757         FileListDir "$(readlink -f pool/)"; 
 760         Packages::Compress "$COMPRESSORS"; 
 761         Sources::Compress "$COMPRESSORS"; 
 762         Contents::Compress "$COMPRESSORS"; 
 763         Translation::Compress "$COMPRESSORS"; 
 764         LongDescription "false"; 
 768         SrcDirectory "pool/"; 
 771         for DIST 
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do 
 772                 echo -n 'tree "dists/' >> ftparchive.conf
 
 773                 echo -n "$DIST" >> ftparchive.conf
 
 775         Architectures "' >> ftparchive.conf
 
 776                 echo -n "$ARCHS" >> ftparchive.conf
 
 778         FileList "' >> ftparchive.conf
 
 779                 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
 
 781         SourceFileList "' >> ftparchive.conf
 
 782                 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
 
 784         Sections "' >> ftparchive.conf
 
 785                 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
 
 787 };' >> ftparchive.conf
 
 791 buildaptftparchivedirectorystructure
() { 
 792         local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')" 
 793         for DIST 
in $DISTS; do 
 794                 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)" 
 795                 for SECTION 
in $SECTIONS; do 
 796                         local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')" 
 797                         for ARCH 
in $ARCHS; do 
 798                                 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH} 
 800                         mkdir -p dists
/${DIST}/${SECTION}/source 
 801                         mkdir -p dists
/${DIST}/${SECTION}/i18n
 
 811         local DEPENDENCIES
="$5" 
 812         local PRIORITY
="${6:-optional}" 
 813         local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES} 
 814  If you find such a package installed on your system, 
 815  something went horribly wrong! They are autogenerated 
 816  und used only by testcases and surf no other propose…"}" 
 818         for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do 
 819                 if [ "$RELEASE" = 'installed' ]; then 
 820                         insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7" 
 823                 for arch in $(getarchitecturesfromcommalist "$ARCH"); do 
 824                         if [ "$arch" = 'all' -o "$arch" = 'none' ]; then 
 825                                 ARCHS="$(getarchitectures)" 
 829                         for BUILDARCH in $ARCHS; do 
 830                                 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}" 
 832                                 local FILE="${PPATH}/Packages
" 
 837 Maintainer
: Joe Sixpack 
<joe@example.org
>" >> $FILE 
 838                                 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE 
 839                                 echo "Version
: $VERSION 
 840 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE 
 841                                 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE 
 842                                 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE 
 843                                 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE 
 847                 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n 
 848                 touch aptarchive/dists/${RELEASE}/main/source/Sources 
 850 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1) 
 851 Description
-en: $DESCRIPTION 
 852 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en 
 861         local DEPENDENCIES="$5" 
 862         local BINARY="${6:-$NAME}" 
 864         local SPATH="aptarchive
/dists
/${RELEASE}/main
/source" 
 866         local FILE="${SPATH}/Sources
" 
 867         local DSCFILE="${NAME}_
${VERSION}.dsc
" 
 868         local TARFILE="${NAME}_
${VERSION}.
tar.gz
" 
 872 Maintainer
: Joe Sixpack 
<joe@example.org
> 
 873 Architecture
: $ARCH" >> $FILE 
 874         test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE 
 876  $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE 
 877  $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE 
 879  $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE 
 880  $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE 
 884 insertinstalledpackage() { 
 888         local DEPENDENCIES="$4" 
 889         local PRIORITY="${5:-optional}" 
 890         local STATUS="${6:-install ok installed}" 
 891         local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
 
 892  If you 
find such a package installed on your system
, 
 893  something went horribly wrong
! They are autogenerated
 
 894  und used only by testcases and surf no other propose…
"}" 
 896         local FILE
='rootdir/var/lib/dpkg/status' 
 897         local INFO
='rootdir/var/lib/dpkg/info' 
 898         for arch 
in $(getarchitecturesfromcommalist "$ARCH"); do 
 904 Maintainer: Joe Sixpack <joe@example.org> 
 905 Version: $VERSION" >> $FILE 
 906                 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE 
 907                 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE 
 908                 echo "Description: $DESCRIPTION" >> $FILE 
 910                 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then 
 911                         echo -n > ${INFO}/${NAME}:${arch}.list
 
 913                         echo -n > ${INFO}/${NAME}.list
 
 919 buildaptarchivefromincoming
() { 
 920         msginfo 
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…" 
 922         [ -e pool 
] || ln -s ..
/incoming pool
 
 923         [ -e ftparchive.conf 
] || createaptftparchiveconfig
 
 924         [ -e dists 
] || buildaptftparchivedirectorystructure
 
 925         msgninfo 
"\tGenerate Packages, Sources and Contents files… " 
 926         testsuccess aptftparchive generate ftparchive.conf
 
 929         generatereleasefiles 
"$@" 
 932 buildaptarchivefromfiles
() { 
 933         msginfo 
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…" 
 934         local DIR
='aptarchive' 
 935         if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi 
 936         find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do 
 937                 msgninfo 
"\t${line} file… " 
 938                 compressfile 
"$line" "$1" 
 941         generatereleasefiles 
"$@" 
 945         cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf 
| while read compressor extension 
command; do 
 946                 if [ "$compressor" = '.' ]; then 
 952                 cat "$1" | $command > "${1}.${extension}" 
 954                         touch -d "$2" "${1}.${extension}" 
 959 # can be overridden by testcases for their pleasure 
 960 getcodenamefromsuite
() { 
 962         unstable
) echo 'sid';; 
 966 getreleaseversionfromsuite
() { true
; } 
 967 getlabelfromsuite
() { true
; } 
 968 getoriginfromsuite
() { true
; } 
 970 aptftparchiverelease
() { 
 971         aptftparchive 
-qq release 
"$@" | sed -e '/0 Release$/ d' # remove the self reference 
 973 generatereleasefiles
() { 
 974         # $1 is the Date header and $2 is the ValidUntil header to be set 
 975         # both should be given in notation date/touch can understand 
 976         msgninfo 
"\tGenerate Release files… " 
 977         if [ -e aptarchive
/dists 
]; then 
 978                 for dir 
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do 
 979                         local SUITE
="$(echo "$dir" | cut -d'/' -f 4)" 
 980                         local CODENAME
="$(getcodenamefromsuite $SUITE)" 
 981                         local VERSION
="$(getreleaseversionfromsuite $SUITE)" 
 982                         local LABEL
="$(getlabelfromsuite $SUITE)" 
 983                         local ORIGIN
="$(getoriginfromsuite $SUITE)" 
 984                         if [ -n "$VERSION" ]; then 
 985                                 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}" 
 987                         if [ -n "$LABEL" ]; then 
 988                                 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}" 
 990                         if [ -n "$ORIGIN" ]; then 
 991                                 ORIGIN
="-o APT::FTPArchive::Release::Origin=${ORIGIN}" 
 993                         aptftparchiverelease 
$dir \
 
 994                                 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
 
 995                                 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
 
1000                         if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then 
1001                                 sed -i '/^Date: / a\ 
1002 NotAutomatic: yes' $dir/Release
 
1006                 aptftparchiverelease .
/aptarchive 
> aptarchive
/Release
 
1008         if [ -n "$1" -a "$1" != "now" ]; then 
1009                 for release 
in $(find ./aptarchive -name 'Release'); do 
1010                         sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $release 
1011                         touch -d "$1" $release 
1014         if [ -n "$2" ]; then 
1015                 sed -i "/^Date: / a\ 
1016 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release') 
1021 setupdistsaptarchive
() { 
1022         local APTARCHIVE
=$(readlink -f ./aptarchive) 
1023         rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
 
1024         rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
 
1025         for DISTS 
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do 
1026                 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ') 
1027                 msgninfo 
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… " 
1028                 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
 
1029                 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
 
1034 setupflataptarchive
() { 
1035         local APTARCHIVE
=$(readlink -f ./aptarchive) 
1036         if [ -f ${APTARCHIVE}/Packages 
]; then 
1037                 msgninfo 
"\tadd deb sources.list line… " 
1038                 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
 
1041                 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
 
1043         if [ -f ${APTARCHIVE}/Sources 
]; then 
1044                 msgninfo 
"\tadd deb-src sources.list line… " 
1045                 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
 
1048                 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
 
1054         if [ "$1" = '--no-update' ]; then 
1058         buildaptarchive 
"$@" 
1059         if [ -e aptarchive
/dists 
]; then 
1060                 setupdistsaptarchive
 
1064         signreleasefiles 
'Joe Sixpack' 
1065         if [ "1" != "$NOUPDATE" ]; then 
1066                 testsuccess aptget update 
-o Debug
::pkgAcquire
::Worker
=true 
-o Debug
::Acquire
::gpgv
=true
 
1070 signreleasefiles
() { 
1071         local SIGNER
="${1:-Joe Sixpack}" 
1072         local REPODIR
="${2:-aptarchive}" 
1073         local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')" 
1074         local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes" 
1075         msgninfo 
"\tSign archive with $SIGNER key $KEY… " 
1076         local REXKEY
='keys/rexexpired' 
1077         local SECEXPIREBAK
="${REXKEY}.sec.bak" 
1078         local PUBEXPIREBAK
="${REXKEY}.pub.bak" 
1079         if [ "${SIGNER}" = 'Rex Expired' ]; then 
1080                 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time 
1081                 # option doesn't exist anymore (and using faketime would add a new obscure dependency) 
1082                 # therefore we 'temporary' make the key not expired and restore a backup after signing 
1083                 cp ${REXKEY}.sec 
$SECEXPIREBAK 
1084                 cp ${REXKEY}.pub 
$PUBEXPIREBAK 
1085                 local SECUNEXPIRED
="${REXKEY}.sec.unexpired" 
1086                 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired" 
1087                 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then 
1088                         cp $SECUNEXPIRED ${REXKEY}.sec
 
1089                         cp $PUBUNEXPIRED ${REXKEY}.pub
 
1091                         if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 
2>&1; then 
1095                         cp ${REXKEY}.sec 
$SECUNEXPIRED 
1096                         cp ${REXKEY}.pub 
$PUBUNEXPIRED 
1099         for RELEASE 
in $(find ${REPODIR}/ -name Release); do 
1100                 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg 
${RELEASE} 
1101                 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" 
1102                 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE 
1103                 # we might have set a specific date for the Release file, so copy it 
1104                 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg 
${INRELEASE} 
1106         if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then 
1107                 mv -f $SECEXPIREBAK ${REXKEY}.sec
 
1108                 mv -f $PUBEXPIREBAK ${REXKEY}.pub
 
1113 redatereleasefiles
() { 
1114         local DATE
="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')" 
1115         for release 
in $(find aptarchive/ -name 'Release'); do 
1116                 sed -i "s/^Date: .*$/Date: ${DATE}/" $release 
1117                 touch -d "$DATE" $release 
1119         signreleasefiles 
"${2:-Joe Sixpack}" 
1123         local WEBSERVER
="${3:-http://localhost:8080}" 
1125         if [ "$1" = '--no-check' ]; then 
1129         local DOWNLOG
='rootdir/tmp/download-testfile.log' 
1130         local STATUS
='downloaded/webserverconfig.status' 
1131         rm -f "$STATUS" "$DOWNLOG" 
1133         if [ -n "$2" ]; then 
1134                 msgtest 
"Set webserver config option '${1}' to" "$2" 
1135                 URI
="${WEBSERVER}/_config/set/${1}/${2}" 
1137                 msgtest 
'Clear webserver config option' "${1}" 
1138                 URI
="${WEBSERVER}/_config/clear/${1}" 
1140         if downloadfile 
"$URI" "$STATUS" > "$DOWNLOG"; then 
1143                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output" 
1144                 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
 
1145                 msgfailoutput 
'' "$OUTPUT" 
1147         $NOCHECK || testwebserverlaststatuscode 
'200' 
1150 rewritesourceslist
() { 
1151         local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")" 
1152         for LIST 
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do 
1153                 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#" 
1157 # wait for up to 10s for a pid file to appear to avoid possible race 
1158 # when a helper is started and dosn't write the PID quick enough 
1161         for i 
in $(seq 10); do 
1162                 if test -s "$PIDFILE"; then 
1167         msgdie 
"waiting for $PIDFILE failed" 
1171 changetowebserver
() { 
1172         if [ "$1" != '--no-rewrite' ]; then 
1173                 rewritesourceslist 
'http://localhost:8080/' 
1177         if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then 
1179                 local LOG
="webserver.log" 
1180                 if ! aptwebserver 
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then 
1184                 waitforpidfile aptwebserver.pid
 
1185                 local PID
="$(cat aptwebserver.pid)" 
1186                 if [ -z "$PID" ]; then 
1187                         msgdie 
'Could not fork aptwebserver successfully' 
1189                 addtrap 
"kill $PID;" 
1192                 msgdie 
'You have to build aptwerbserver or install a webserver' 
1196 changetohttpswebserver
() { 
1197         if ! which stunnel4 
>/dev
/null
; then 
1198                 msgdie 
'You need to install stunnel4 for https testcases' 
1200         if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then 
1201                 changetowebserver 
--no-rewrite "$@" 
1203         echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid 
1204 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem 
1210 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
 
1211         stunnel4 
"${TMPWORKINGDIRECTORY}/stunnel.conf" 
1212         waitforpidfile 
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid" 
1213         local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)" 
1214         if [ -z "$PID" ]; then 
1215                 msgdie 
'Could not fork stunnel4 successfully' 
1217         addtrap 
'prefix' "kill ${PID};" 
1218         rewritesourceslist 
'https://localhost:4433/' 
1222         mkdir -p rootdir
/media
/cdrom
/.disk
 
1223         local CD
="$(readlink -f rootdir/media/cdrom)" 
1224         echo "acquire::cdrom::mount \"${CD}\"; 
1225 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\"; 
1226 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\"; 
1227 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
 
1228         echo -n "$1" > ${CD}/.disk
/info
 
1229         if [ ! -d aptarchive
/dists 
]; then 
1230                 msgdie 
'Flat file archive cdroms can not be created currently' 
1233         mv aptarchive
/dists 
"$CD" 
1234         ln -s "$(readlink -f ./incoming)" $CD/pool
 
1235         find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete 
1236         # start with an unmounted disk 
1237         mv "${CD}" "${CD}-unmounted" 
1238         # we don't want the disk to be modifiable 
1239         addtrap 
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;" 
1240         chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
 
1244         local PROTO
="${1%%:*}" 
1245         if ! apthelper 
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
 
1246                 download
-file "$1" "$2" "$3" 2>&1 ; then 
1249         # only if the file exists the download was successful 
1250         if [ -r "$2" ]; then 
1258         local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" 
1259         if [ -n "$DIFFTEXT" ]; then 
1261                 echo >&2 "$DIFFTEXT" 
1269         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output" 
1270         local COMPAREFILE
="$1" 
1272         if "$@" 2>&1 | checkdiff 
$COMPAREFILE - >"$OUTPUT" 2>&1; then 
1275                 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}" 
1276                 cat "$COMPAREFILE" >>"${OUTPUT}" 
1277                 msgfailoutput 
'' "$OUTPUT" "$@" 
1282         msggroup 
'testfileequal' 
1283         local MSG
='Test for correctness of file' 
1284         if [ "$1" = '--nomsg' ]; then 
1290         if [ -n "$MSG" ]; then 
1291                 msgtest 
"$MSG" "$FILE" 
1293         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output" 
1294         if [ -z "$*" ]; then 
1295                 testoutputequal 
"$FILE" echo -n '' 
1297                 testoutputequal 
"$FILE" echo "$*" 
1303         msggroup 
'testempty' 
1304         msgtest 
"Test for no output of" "$*" 
1305         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile" 
1306         if ("$@" >$COMPAREFILE 2>&1 || true
) && test ! -s $COMPAREFILE; then 
1309                 msgfailoutput 
'' "$COMPAREFILE" "$@" 
1311         aptautotest 
'testempty' "$@" 
1316         msggroup 
'testequal' 
1317         local MSG
='Test of equality of' 
1318         if [ "$1" = '--nomsg' ]; then 
1323         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile" 
1324         echo "$1" > $COMPAREFILE 
1327         if [ -n "$MSG" ]; then 
1330         testoutputequal 
"$COMPAREFILE" "$@" 
1331         aptautotest 
'testequal' "$@" 
1336         msggroup 
'testequalor2' 
1337         local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1" 
1338         local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2" 
1339         local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst" 
1340         echo "$1" > $COMPAREFILE1 
1341         echo "$2" > $COMPAREFILE2 
1343         msgtest 
"Test for equality OR of" "$*" 
1344         "$@" >$COMPAREAGAINST 2>&1 || true
 
1345         if checkdiff 
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null 
2>&1 || \
 
1346                 checkdiff 
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null 
2>&1 
1350                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output" 
1351                 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1 
1352                 checkdiff 
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
 
1353                 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1 
1354                 checkdiff 
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
 
1355                 msgfailoutput 
'' "$OUTPUT" 
1357         aptautotest 
'testequalor2' "$@" 
1362         msggroup 
'testshowvirtual' 
1363         local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual" 
1366         while [ -n "$1" ]; do 
1368 N: Can't select versions from package '$1' as it is purely virtual" 
1369                 PACKAGE
="${PACKAGE} $1" 
1372         msgtest 
"Test for virtual packages" "apt-cache show $PACKAGE" 
1374 N: No packages found" 
1375         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile" 
1376         local ARCH
="$(getarchitecture 'native')" 
1377         echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE" 
1378         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output" 
1379         testoutputequal 
"$COMPAREFILE" aptcache show 
-q=0 "$PACKAGE" 
1384         msggroup 
'testnopackage' 
1385         msgtest 
"Test for non-existent packages" "apt-cache show $*" 
1386         local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')" 
1387         if [ -n "$SHOWPKG" ]; then 
1388                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" 
1389                 echo "$SHOWPKG" >"$OUTPUT" 
1390                 msgfailoutput 
'' "$OUTPUT" 
1398         msggroup 
'testdpkgstatus' 
1402         msgtest 
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*" 
1403         local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)" 
1404         if [ "$PKGS" != $NR ]; then 
1405                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" 
1406                 echo "$PKGS" >"$OUTPUT" 
1407                 dpkg 
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
 
1408                 msgfailoutput 
'' "$OUTPUT" 
1415 testdpkginstalled
() { 
1416         msggroup 
'testdpkginstalled' 
1417         testdpkgstatus 
'ii' "$#" "$@" 
1421 testdpkgnotinstalled
() { 
1422         msggroup 
'testdpkgnotinstalled' 
1423         testdpkgstatus 
'ii' '0' "$@" 
1428         msggroup 
'testmarkedauto' 
1429         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile" 
1430         if [ -n "$1" ]; then 
1431                 msgtest 
'Test for correctly marked as auto-installed' "$*" 
1432                 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE 
1434                 msgtest 
'Test for correctly marked as auto-installed' 'no package' 
1435                 echo -n > $COMPAREFILE 
1437         testoutputequal 
"$COMPAREFILE" aptmark showauto
 
1440 testmarkedmanual
() { 
1441         msggroup 
'testmarkedmanual' 
1442         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile" 
1443         if [ -n "$1" ]; then 
1444                 msgtest 
'Test for correctly marked as manually installed' "$*" 
1445                 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE 
1447                 msgtest 
'Test for correctly marked as manually installed' 'no package' 
1448                 echo -n > $COMPAREFILE 
1450         testoutputequal 
"$COMPAREFILE" aptmark showmanual
 
1455         msgreportheader 
'msgfailoutput' 
1459         if [ "$1" = 'grep' ]; then 
1461                 while [ -n "$2" ]; do shift; done 
1462                 echo "#### Complete file: $1 ####" 
1463                 cat >&2 "$1" || true
 
1464                 echo '#### grep output ####' 
1465         elif [ "$1" = 'test' ]; then 
1467                 # doesn't support ! or non-file flags 
1468                 msgfailoutputstatfile
() { 
1469                         local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$' 
1470                         if expr match 
"$1" "$FILEFLAGS" >/dev
/null
; then 
1471                                 echo "#### stat(2) of file: $2 ####" 
1473                                 if test -e "$2"; then 
1474                                         echo "#### Complete file: $2 ####" 
1475                                         cat >&2 "$2" || true
 
1479                 msgfailoutputstatfile 
"$2" "$3" 
1480                 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do 
1482                         msgfailoutputstatfile 
"$2" "$3" 
1484                 echo '#### test output ####' 
1491         msggroup 
'testsuccess' 
1492         if [ "$1" = '--nomsg' ]; then 
1495                 msgtest 
'Test for successful execution of' "$*" 
1497         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" 
1498         if "$@" >${OUTPUT} 2>&1; then 
1499                 if expr match 
"$1" '^apt.*' >/dev
/null
; then 
1500                         if grep -q -E ' runtime error: ' "$OUTPUT"; then 
1501                                 msgfailoutput 
'compiler detected undefined behavior' "$OUTPUT" "$@" 
1502                         elif grep -E '^[WE]: ' "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then 
1503                                 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then 
1504                                         if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
 
1505                                                 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null 
2>&1; then 
1508                                                 msgfailoutput 
'successful run, but output contains warnings/errors' "$OUTPUT" "$@" 
1511                                         msgfailoutput 
'successful run, but output contains warnings/errors' "$OUTPUT" "$@" 
1521                 msgfailoutput 
"exitcode $EXITCODE" "$OUTPUT" "$@" 
1523         aptautotest 
'testsuccess' "$@" 
1527         msggroup 
'testwarning' 
1528         if [ "$1" = '--nomsg' ]; then 
1531                 msgtest 
'Test for successful execution with warnings of' "$*" 
1533         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" 
1534         if "$@" >${OUTPUT} 2>&1; then 
1535                 if expr match 
"$1" '^apt.*' >/dev
/null
; then 
1536                         if grep -q -E ' runtime error: ' "$OUTPUT"; then 
1537                                 msgfailoutput 
'compiler detected undefined behavior' "$OUTPUT" "$@" 
1538                         elif grep -q -E '^E: ' "$OUTPUT"; then 
1539                                 msgfailoutput 
'successful run, but output contains errors' "$OUTPUT" "$@" 
1540                         elif ! grep -q -E '^W: ' "$OUTPUT"; then 
1541                                 msgfailoutput 
'successful run, but output contains no warnings' "$OUTPUT" "$@" 
1550                 msgfailoutput 
"exitcode $EXITCODE" "$OUTPUT" "$@" 
1552         aptautotest 
'testwarning' "$@" 
1556         msggroup 
'testfailure' 
1557         if [ "$1" = '--nomsg' ]; then 
1560                 msgtest 
'Test for failure in execution of' "$*" 
1562         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" 
1563         if "$@" >${OUTPUT} 2>&1; then 
1565                 msgfailoutput 
"exitcode $EXITCODE" "$OUTPUT" "$@" 
1568                 if expr match 
"$1" '^apt.*' >/dev
/null
; then 
1569                         if [ "$1" = 'aptkey' ]; then 
1570                                 if grep -q -E " Can't check signature: " "$OUTPUT" || \
 
1571                                         grep -q -E " BAD signature from " "$OUTPUT"; then 
1574                                         msgfailoutput 
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@" 
1577                                 if grep -q -E ' runtime error: ' "$OUTPUT"; then 
1578                                         msgfailoutput 
'compiler detected undefined behavior' "$OUTPUT" "$@" 
1579                                 elif grep -q -E '==ERROR' "$OUTPUT"; then 
1580                                         msgfailoutput 
'compiler sanitizers reported errors' "$OUTPUT" "$@" 
1581                                 elif ! grep -q -E '^E: ' "$OUTPUT"; then 
1582                                         msgfailoutput 
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@" 
1591         aptautotest 
'testfailure' "$@" 
1595 testreturnstateequal
() { 
1597         msggroup 
"${STATE}equal" 
1598         if [ "$2" != '--nomsg' ]; then 
1602                 testfileequal 
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" 
1606                 "$STATE" --nomsg "$@" 
1607                 testfileequal 
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" 
1611 testsuccessequal
() { 
1612         testreturnstateequal 
'testsuccess' "$@" 
1614 testwarningequal
() { 
1615         testreturnstateequal 
'testwarning' "$@" 
1617 testfailureequal
() { 
1618         testreturnstateequal 
'testfailure' "$@" 
1622         msggroup 
'testfailuremsg' 
1626         msgtest 
'Check that the output of the previous failed command has expected' 'failures and warnings' 
1627         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile" 
1628         grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
 
1629         testoutputequal 
"$COMPAREFILE" echo "$CMP" 
1634         msggroup 
'testfilestats' 
1635         msgtest 
"Test that file $1 has $2 $3" "$4" 
1636         if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then 
1639                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output" 
1642                         echo -n "stat(1) reports for $2: " 
1643                         stat 
--format "$2" "$1" || true
 
1645                 msgfailoutput 
'' "$OUTPUT" 
1649 testaccessrights
() { 
1650         msggroup 
'testaccessrights' 
1651         testfilestats 
"$1" '%a' '=' "$2" 
1655 testwebserverlaststatuscode
() { 
1656         msggroup 
'testwebserverlaststatuscode' 
1657         local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log' 
1658         local STATUS
='downloaded/webserverstatus-statusfile.log' 
1659         rm -f "$DOWNLOG" "$STATUS" 
1660         msgtest 
'Test last status code from the webserver was' "$1" 
1661         if downloadfile 
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then 
1664                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output" 
1666                         if [ -n "$2" ]; then 
1668                                 echo >&2 '#### Additionally provided output files contain:' 
1671                         echo >&2 '#### Download log of the status code:' 
1674                 msgfailoutput 
"Status was $(cat "$STATUS")" "$OUTPUT" 
1680         echo "STOPPED execution. Press enter to continue" 
1685 listcurrentlistsdirectory
() { 
1687                 find rootdir
/var
/lib
/apt
/lists 
-maxdepth 1 -type d 
| while read line
; do 
1688                         stat 
--format '%U:%G:%a:%n' "$line" 
1690                 find rootdir
/var
/lib
/apt
/lists 
-maxdepth 1 \
! -type d 
| while read line
; do 
1691                         stat 
--format '%U:%G:%a:%s:%y:%n' "$line" 
1696 ### convenience hacks ### 
1698         # creating some directories by hand is a tedious task, so make it look simple 
1699         if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] || 
1700            [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then 
1701                 # only the last directory created by mkdir is effected by the -m ! 
1702                 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" 
1703                 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" 
1704                 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" 
1705                 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock" 
1706                 if [ "$(id -u)" = '0' ]; then 
1707                         chown _apt
:root 
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" 
1714 ### The following tests are run by most test methods automatically to check 
1715 ### general things about commands executed without writing the test every time. 
1721         local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')" 
1722         if command -v $AUTOTEST >/dev
/null
; then 
1724                 # save and restore the *.output files from other tests 
1725                 # as we might otherwise override them in these automatic tests 
1726                 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before 
1727                 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp 
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before 
1728                 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
 
1729                 $AUTOTEST "$TESTCALL" "$@" 
1730                 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest 
1731                 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp 
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest 
1732                 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
 
1736 aptautotest_aptget_update
() { 
1738         while [ -n "$2" ]; do 
1739                 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode 
1742         if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi 
1743         testfilestats 
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" 
1744         testfilestats 
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" 
1745         # all copied files are properly chmodded 
1746         for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do 
1747                 testfilestats 
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644" 
1749         if [ "$TESTCALL" = 'testsuccess' ]; then 
1750                 # failure cases can retain partial files and such 
1751                 testempty 
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
) 
1754 aptautotest_apt_update
() { aptautotest_aptget_update 
"$@"; } 
1755 aptautotest_aptcdrom_add
() { aptautotest_aptget_update 
"$@"; } 
1757 testaptautotestnodpkgwarning
() { 
1759         while [ -n "$2" ]; do 
1760                 if expr match 
"$2" '^-[a-z]*s' >/dev
/null 
2>&1; then return; fi # simulation mode 
1761                 if expr match 
"$2" '^-dy\?' >/dev
/null 
2>&1; then return; fi # download-only mode 
1764         testfailure 
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output" 
1767 aptautotest_aptget_install
() { testaptautotestnodpkgwarning 
"$@"; } 
1768 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning 
"$@"; } 
1769 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning 
"$@"; } 
1770 aptautotest_apt_install
() { testaptautotestnodpkgwarning 
"$@"; } 
1771 aptautotest_apt_remove
() { testaptautotestnodpkgwarning 
"$@"; } 
1772 aptautotest_apt_purge
() { testaptautotestnodpkgwarning 
"$@"; }