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 
  12         elif [ "$1" = '--color=yes' ]; then 
  14         elif [ "$1" = '--color' ]; then 
  15                 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')" 
  17         elif [ "$1" = '--level' ]; then 
  21                 echo >&2 "WARNING: Unknown parameter »$1« will be ignored" 
  25 export MSGLEVEL
="${MSGLEVEL:-3}" 
  27 # we all like colorful messages 
  28 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then 
  29         if [ ! -t 1 ]; then # but check that we output to a terminal 
  35 if [ "$MSGCOLOR" != 'NO' ]; then 
  36         CERROR
="\033[1;31m" # red 
  37         CWARNING
="\033[1;33m" # yellow 
  38         CMSG
="\033[1;32m" # green 
  39         CINFO
="\033[1;96m" # light blue 
  40         CDEBUG
="\033[1;94m" # blue 
  41         CNORMAL
="\033[0;39m" # default system console color 
  42         CDONE
="\033[1;32m" # green 
  43         CPASS
="\033[1;32m" # green 
  44         CFAIL
="\033[1;31m" # red 
  45         CCMD
="\033[1;35m" # pink 
  57                         printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')" 
  63 msgdie
() { msgprintf 
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; } 
  64 msgwarn
() { msgprintf 
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; } 
  65 msgmsg
() { msgprintf 
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; } 
  66 msginfo
() { msgprintf 
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; } 
  67 msgdebug
() { msgprintf 
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; } 
  68 msgdone
() { msgprintf 
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; } 
  69 msgnwarn
() { msgprintf 
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; } 
  70 msgnmsg
() { msgprintf 
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; } 
  71 msgninfo
() { msgprintf 
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; } 
  72 msgndebug
() { msgprintf 
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; } 
  73 msgtest
() { msgprintf 
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; } 
  74 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; } 
  76         if [ -n "$MSGTEST_MSG" ]; then 
  77                 test "$1" != 'msgfailoutput' || echo 
  78                 if [ -n "$MSGTEST_MSGMSG" ]; then 
  79                         echo "$MSGTEST_MSGMSG" 
  81                 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then 
  82                         echo "${CFAIL}Part of the test group: $MSGTEST_GRP" 
  84                 echo -n "$MSGTEST_MSG" 
  89         msgreportheader 
'msgskip' 
  90         if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2; 
  91         else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi 
  94         msgreportheader 
'msgfail' 
  95         if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2; 
  96         else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi 
  97         if [ -n "$APT_DEBUG_TESTS" ]; then 
 100         EXIT_CODE
=$((EXIT_CODE+1)); 
 105                 if [ $MSGGROUP_LEVEL = 0 ]; then 
 108                 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1)); 
 110                 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1)); 
 111                 if [ $MSGGROUP_LEVEL = 0 ]; then 
 117 # enable / disable Debugging 
 118 if [ $MSGLEVEL -le 0 ]; then 
 121 if [ $MSGLEVEL -le 1 ]; then 
 125 if [ $MSGLEVEL -le 2 ]; then 
 127                 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")" 
 131                 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")" 
 132                 if [ "$MSGTEST_GRP" = 'NEXT' ]; then 
 133                         MSGTEST_GRP
="$MSGTEST_MSG" 
 136         msgpass
() { printf " ${CPASS}P${CNORMAL}"; } 
 138 if [ $MSGLEVEL -le 3 ]; then 
 142 if [ $MSGLEVEL -le 4 ]; then 
 144         msgndebug
() { true
; } 
 147         if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] || 
 148            [ "$1" = "info" -a $MSGLEVEL -le 3 ] || 
 149            [ "$1" = "msg" -a $MSGLEVEL -le 2 ] || 
 150            [ "$1" = "warn" -a $MSGLEVEL -le 1 ] || 
 151            [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then 
 154                 printf "${CDONE}DONE${CNORMAL}\n"; 
 158         if [ -f .
/aptconfig.conf 
]; then 
 159                 echo "$(readlink -f ./aptconfig.conf)" 
 160         elif [ -f ..
/aptconfig.conf 
]; then 
 161                 echo "$(readlink -f ../aptconfig.conf)" 
 162         elif [ -f ..
/..
/aptconfig.conf 
]; then 
 163                 echo "$(readlink -f ../../aptconfig.conf)" 
 164         elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then 
 165                 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")" 
 169         msgdebug 
"Executing: ${CCMD}$*${CDEBUG} " 
 173         sh
|aptitude
|*/*|command) ;; 
 174         *) CMD
="${BUILDDIRECTORY}/$CMD";; 
 176         MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@" 
 178 runpython3
() { runapt 
command python3 
"$@"; } 
 179 aptconfig
() { runapt apt
-config "$@"; } 
 180 aptcache
() { runapt apt
-cache "$@"; } 
 181 aptcdrom
() { runapt apt
-cdrom "$@"; } 
 182 aptget
() { runapt apt
-get "$@"; } 
 183 aptftparchive
() { runapt 
"${APTFTPARCHIVEBINDIR}/apt-ftparchive" "$@"; } 
 184 aptkey
() { runapt apt
-key "$@"; } 
 185 aptmark
() { runapt apt
-mark "$@"; } 
 186 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; } 
 187 apt
() { runapt apt 
"$@"; } 
 188 apthelper
() { runapt 
"${APTHELPERBINDIR}/apt-helper" "$@"; } 
 189 aptwebserver
() { runapt 
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; } 
 190 aptitude
() { runapt aptitude 
"$@"; } 
 191 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; } 
 192 aptinternalsolver
() { runapt 
"${APTINTERNALSOLVER}" "$@"; } 
 193 aptdumpsolver
() { runapt 
"${APTDUMPSOLVER}" "$@"; } 
 194 aptinternalplanner
() { runapt 
"${APTINTERNALPLANNER}" "$@"; } 
 197         "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@" 
 199 dpkgcheckbuilddeps
() { 
 200         command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@" 
 205         aptget
) CMD
="apt-get";; 
 206         aptcache
) CMD
="apt-cache";; 
 207         aptcdrom
) CMD
="apt-cdrom";; 
 208         aptconfig
) CMD
="apt-config";; 
 209         aptmark
) CMD
="apt-mark";; 
 210         apthelper
) CMD
="apt-helper";; 
 211         aptftparchive
) CMD
="apt-ftparchive";; 
 212         dpkg
) shift; runapt 
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;; 
 216         if [ "${CMD##*/}" = "$CMD" ]; then 
 217                 CMD
="${BUILDDIRECTORY}/${CMD}" 
 219         runapt 
command gdb 
--quiet -ex "directory '$SOURCEDIRECTORY'" -ex run 
"$CMD" --args "$CMD" "$@" 
 222         date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" -R 
 225         grep "^${2:-Date}:" "$1" | cut 
-d' ' -f 2- 
 229         # error if we about to overflow, but ... 
 230         #   "255 failures ought to be enough for everybody" 
 231         if [ $EXIT_CODE -gt 255 ]; then 
 232             msgdie 
"Total failure count $EXIT_CODE too big" 
 234         exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255)); 
 237 shellsetedetector
() { 
 239         if [ "$exit_status" != '0' ]; then 
 240                 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n" 
 241                 if [ "$EXIT_CODE" = '0' ]; then 
 242                         EXIT_CODE
="$exit_status" 
 248         if [ "$1" = 'prefix' ]; then 
 249                 CURRENTTRAP
="$2 $CURRENTTRAP" 
 251                 CURRENTTRAP
="$CURRENTTRAP $1" 
 253         trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
 
 257     echo "$@" | sed -e "s#'#'\"'\"'#g" 
 260 find_project_binary_dir
() { 
 261         local TESTDIRECTORY
="$(readlink -f "$(dirname $0)")" 
 262         if [ -z "$PROJECT_BINARY_DIR" ]; then 
 264                 for dir in ${TESTDIRECTORY}/../../ ${TESTDIRECTORY}/../../*; do 
 265                         test -e "$dir/CMakeCache.txt
"  || continue 
 266                         if [ -z "$PROJECT_BINARY_DIR" ] || 
 267                            [ "$dir/CMakeCache.txt
" -nt "$PROJECT_BINARY_DIR/CMakeCache.txt
" ]; then 
 268                                 PROJECT_BINARY_DIR="$dir" 
 271                 if [ -z "$PROJECT_BINARY_DIR" ]; then 
 272                         echo "Cannot 
find build directory
, you might want to 
set PROJECT_BINARY_DIR
" >&2 
 275                 export PROJECT_BINARY_DIR 
 279         # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir) 
 280         if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then 
 283         TMPWORKINGDIRECTORY="$(mktemp -d)" 
 284         addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';" 
 285         if [ -n "$TMPDIR_ADD" ]; then 
 286                 TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}" 
 287                 mkdir -p "$TMPWORKINGDIRECTORY" 
 289                 export TMPDIR="$TMPWORKINGDIRECTORY" 
 291         msgninfo "Preparing environment 
for ${0##*/} in ${TMPWORKINGDIRECTORY}…
" 
 293         mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded
" 
 294         if [ "$(id -u)" = '0' ]; then 
 295                 # relax permissions so that running as root with user switching works 
 297                 chmod 711 "$TMPWORKINGDIRECTORY" 
 298                 chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded
" 
 301         TESTDIRECTORY="$(readlink -f "$(dirname $0)")" 
 302         # Find the newest build directory (sets PROJECT_BINARY_DIR) 
 303         find_project_binary_dir
 
 304         # allow overriding the default BUILDDIR location 
 305         SOURCEDIRECTORY
="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}" 
 306         BUILDDIRECTORY
="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}" 
 307         LIBRARYPATH
="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}" 
 308         METHODSDIR
="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}" 
 309         APTHELPERBINDIR
="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}" 
 310         APTWEBSERVERBINDIR
="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}/../test/interactive-helper"}" 
 311         APTFTPARCHIVEBINDIR
="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/../ftparchive"}" 
 312         APTINTERNALSOLVER
="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}" 
 313         APTDUMPSOLVER
="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}" 
 314         APTINTERNALPLANNER
="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}" 
 315         test -x "${BUILDDIRECTORY}/apt-get" || msgdie 
"You need to build tree first" 
 318         cd "$TMPWORKINGDIRECTORY" 
 319         mkdir rootdir aptarchive keys
 
 321         mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
 
 322         mkdir -p usr
/bin var
/cache var
/lib var
/log var
/crash tmp
 
 323         mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
 
 324         mkdir -p usr
/lib
/apt
/solvers usr
/lib
/apt
/planners
 
 325         touch var
/lib
/dpkg
/available
 
 326         ln -s "${METHODSDIR}" usr
/lib
/apt
/methods
 
 327         ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/solvers
/dump
 
 328         ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/planners
/dump
 
 329         ln -s "${APTINTERNALSOLVER}" usr
/lib
/apt
/solvers
/apt
 
 330         ln -s "${APTINTERNALPLANNER}" usr
/lib
/apt
/planners
/apt
 
 331         echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" >> ..
/aptconfig.conf
 
 332         echo "Dir::Bin::Planners \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/planners\";" >> ..
/aptconfig.conf
 
 333         # use the autoremove from the BUILDDIRECTORY if its there, otherwise 
 335         if [ -z "${APT_INTEGRATION_TESTS_SOURCE_DIR}" ]; then 
 336             ln -s "${SOURCEDIRECTORY}/debian/apt.conf.autoremove" etc
/apt
/apt.conf.d
/01autoremove
 
 338             ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
 
 341         local BASENAME
="${0##*/}" 
 342         local PACKAGESFILE
="Packages-${BASENAME#*-}" 
 343         if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then 
 344                 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive
/Packages
 
 346         local SOURCESSFILE
="Sources-${BASENAME#*-}" 
 347         if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then 
 348                 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
 
 350         find "$TESTDIRECTORY" \
( -name '*.pub' -o -name '*.sec' \
) -exec cp '{}' keys
/ \
; 
 352         ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
 
 354         echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
 
 355         echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
 
 356         echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
 
 357         # either store apt-key were we can access it, even if we run it as a different user 
 358         #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/" 
 359         #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key" 
 360         #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf 
 361         # destroys coverage reporting though, so we disable changing user for the calling gpgv 
 362         echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
 
 363         if [ "$(id -u)" = '0' ]; then 
 364                 echo 'Binary::gpgv::APT::Sandbox::User "root";' >> aptconfig.conf
 
 365                 # same for the solver executables 
 366                 echo 'APT::Solver::RunAsUser "root";' >> aptconfig.conf
 
 367                 echo 'APT::Planner::RunAsUser "root";' >> aptconfig.conf
 
 370         cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF 
 373 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then 
 374         if [ -n "\$LD_LIBRARY_PATH" ]; then 
 375                 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\${LD_LIBRARY_PATH}" 
 377                 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}' 
 379         if [ -n "\$LD_PRELOAD" ]; then 
 380                 export LD_PRELOAD="noopchroot.so \${LD_PRELOAD}" 
 382                 export LD_PRELOAD="noopchroot.so" 
 386         cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" 
 387         cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF 
 388 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\ 
 389         --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\ 
 390         --force-not-root --force-bad-path "\$@" 
 392         cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF 
 393 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\ 
 394         --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\ 
 395         --force-not-root --force-bad-path "\$@" 
 397         chmod +x 
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" 
 398         echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
 
 401                 if ! command dpkg 
--assert-multi-arch >/dev
/null 
2>&1; then 
 402                         echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it… 
 405                 echo 'quiet::NoUpdate "true";' 
 406                 echo 'quiet::NoStatistic "true";' 
 407                 # too distracting for users, but helpful to detect changes 
 408                 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' 
 409                 echo 'Acquire::Progress::Diffpercent "true";' 
 410                 # in testcases, it can appear as if localhost has a rotation setup, 
 411                 # hide this as we can't really deal with it properly 
 412                 echo 'Acquire::Failure::ShowIP "false";' 
 413                 # fakeroot can't fake everything, so disabled in production but good for tests 
 414                 echo 'APT::Sandbox::Verify "true";' 
 417         cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" 
 418         if [ "$(id -u)" = '0' ]; then 
 419                 chown _apt
:root 
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" 
 421         echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
 
 422         echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary 
 423         export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE
=no
 
 424         echo 'Acquire::Connect::AddrConfig "false";' > rootdir
/etc
/apt
/apt.conf.d
/connect
-addrconfig 
 426         configcompression 
'.' 'gz' #'bz2' 'lzma' 'xz' 
 427         confighashes 
'SHA256' # these are tests, not security best-practices 
 429         # create some files in /tmp and look at user/group to get what this means 
 430         TEST_DEFAULT_USER
="$(id -un)" 
 431         if [ "$(uname)" = 'GNU/kFreeBSD' ]; then 
 432                 TEST_DEFAULT_GROUP
='root' 
 434                 TEST_DEFAULT_GROUP
="$(id -gn)" 
 437         # cleanup the environment a bit 
 438         # prefer our apt binaries over the system apt binaries 
 439         export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin" 
 440         export LC_ALL
=C.UTF
-8 
 441         unset LANGUAGE APT_CONFIG
 
 442         unset GREP_OPTIONS DEB_BUILD_PROFILES
 
 443         unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
 
 445         # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1 
 446         if aptkey verify 
--weak-digest SHA1 
--help 2>/dev
/null 
>/dev
/null
; then 
 447                 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1"; };' > rootdir
/etc
/apt
/apt.conf.d
/no
-sha1 
 450         # most tests just need one signed Release file, not both 
 451         export APT_DONT_SIGN
='Release.gpg' 
 453         if [ -r "${TESTDIRECTORY}/extra-environment" ]; then 
 454                 . 
"${TESTDIRECTORY}/extra-environment" 
 461         if [ "$1" = "native" -o -z "$1" ]; then 
 462                 eval `aptconfig shell ARCH APT::Architecture` 
 463                 if [ -n "$ARCH" ]; then 
 466                         dpkg 
--print-architecture 
 474         aptconfig dump 
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures 
| sort -u | tr '\n' ' ' 
 477 getarchitecturesfromcommalist
() { 
 478         echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/" 
 481 configarchitecture
() { 
 483                 echo "APT::Architecture \"$(getarchitecture $1)\";" 
 484                 while [ -n "$1" ]; do 
 485                         echo "APT::Architectures:: \"$(getarchitecture $1)\";" 
 488         } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
 
 493         if [ ! -e rootdir
/var
/lib
/dpkg
/status 
]; then 
 494                 local BASENAME
="${0##*/}" 
 495                 local STATUSFILE
="status-${BASENAME#*-}" 
 496                 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then 
 497                         cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir
/var
/lib
/dpkg
/status
 
 499                         echo -n > rootdir
/var
/lib
/dpkg
/status
 
 502         rm -f rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
 
 503         if command dpkg 
--assert-multi-arch >/dev
/null 
2>&1 ; then 
 504                 local ARCHS
="$(getarchitectures)" 
 505                 local DPKGARCH
="$(dpkg --print-architecture)" 
 506                 # this ensures that even if multi-arch isn't active in the view 
 507                 # of apt, given that dpkg can't be told which arch is native 
 508                 # the arch apt treats as native might be foreign for dpkg 
 509                 for ARCH 
in ${ARCHS}; do 
 510                         if [ "${ARCH}" != "${DPKGARCH}" ]; then 
 511                                 if ! dpkg 
--add-architecture ${ARCH} >/dev
/null 
2>&1; then 
 512                                         # old-style used e.g. in Ubuntu-P – and as it seems travis 
 513                                         echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
 
 514                                         echo "DPKG::options:: \"${ARCH}\";"  >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
 
 518                 # if multi-arch make sure dpkg can detect itself as capable of it 
 519                 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then 
 520                         if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then 
 521                                 # dpkg doesn't really check the version as long as it is fully installed, 
 522                                 # but just to be sure we choose one above the required version 
 523                                 insertinstalledpackage 
'dpkg' "all" '1.16.2+fake' 
 529 configdpkgnoopchroot
() { 
 530         # create a library to noop chroot() and rewrite maintainer script executions 
 531         # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown 
 532         # chroot directory dpkg could chroot into to execute the maintainer scripts 
 533         msgtest 
'Building library to preload to make maintainerscript work in' 'dpkg' 
 534         cat > noopchroot.c 
<< EOF 
 541 static char * chrootdir = NULL; 
 543 int chroot(const char *path) { 
 544         printf("WARNING: CHROOTing to %s was ignored!\n", path); 
 546         chrootdir = strdup(path); 
 549 int execvp(const char *file, char *const argv[]) { 
 550         static int (*func_execvp) (const char *, char * const []) = NULL; 
 551         if (func_execvp == NULL) 
 552                 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp"); 
 553         if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0) 
 554                 return func_execvp(file, argv); 
 555         printf("REWRITE execvp call %s into %s\n", file, chrootdir); 
 557         if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) { 
 561         char const * const baseadmindir = "/var/lib/dpkg"; 
 563         if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) { 
 567         setenv("DPKG_ADMINDIR", admindir, 1); 
 568         return func_execvp(newfile, argv); 
 571         testempty 
--nomsg gcc 
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c 
-ldl 
 573 configcompression
() { 
 574         if [ "$1" = 'ALL' ]; then 
 575                 configcompression 
'.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\
1#p') 
 578         local CMD
='apthelper cat-file -C' 
 579         while [ -n "$1" ]; do 
 581                 '.') printf ".\t.\tcat\n";; 
 582                 'gz') printf "gzip\tgz\t$CMD $1\n";; 
 583                 'bz2') printf "bzip2\tbz2\t$CMD $1\n";; 
 584                 *) printf "$1\t$1\t$CMD $1\n";; 
 587         done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" 
 591                 echo 'APT::FTPArchive {' 
 593                         while [ -n "$1" ]; do 
 594                                 printf "$1" | tr 'a-z' 'A-Z' 
 595                                 printf "\t\"true\";\n" 
 598                         for h 
in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do 
 599                                 printf "$h\t\"false\";\n" 
 603         } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf" 
 608         COMPRESSOR_CMD
="apthelper cat-file -C $1" 
 610         gzip) COMPRESS
='gz';; 
 611         bzip2) COMPRESS
='bz2';; 
 613         local CONFFILE
="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor" 
 614         echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; }; 
 615 Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE" 
 616         for COMP 
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do 
 617                 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi 
 618                 echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE" 
 619                 echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE" 
 623 _setupsimplenativepackage
() { 
 627         local RELEASE
="${4:-unstable}" 
 628         local DEPENDENCIES
="$5" 
 629         local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} 
 630  If you find such a package installed on your system, 
 631  something went horribly wrong! They are autogenerated 
 632  und used only by testcases and serve no other purpose…"}" 
 634         local SECTION="${7:-others}" 
 635         local PRIORITY="${8:-optional}" 
 637         local COMPRESS_TYPE="${10:-gzip}" 
 639         if [ "$SECTION" = "${SECTION#*/}" ]; then 
 642                 DISTSECTION="${SECTION%/*}" 
 644         local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}" 
 646         mkdir -p "$BUILDDIR/debian
/source" 
 647         echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
" 
 649 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}" 
 651         echo "Copyleft by Joe Sixpack 
$(date -u +%Y)" > "${BUILDDIR}/debian
/copyright
" 
 652         echo "$NAME ($VERSION) $RELEASE; urgency
=low
 
 656  -- Joe Sixpack 
<joe@example.org
>  $(date -u -R)" > "${BUILDDIR}/debian
/changelog
" 
 660 Maintainer
: Joe Sixpack 
<joe@example.org
> 
 661 Standards
-Version: 3.9.3" 
 662                 if [ "$SECTION" != '<none>' ]; then 
 663                         echo "Section
: $SECTION" 
 665                 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')" 
 666                 test -z "$BUILDDEPS" || echo "$BUILDDEPS" 
 670                 if [ "$ARCH" = 'all' ]; then 
 671                         echo "Architecture
: all
" 
 673                         echo "Architecture
: any
" 
 675                 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')" 
 676                 test -z "$DEPS" || echo "$DEPS" 
 677                 echo "Description
: $DESCRIPTION" 
 678         } > "${BUILDDIR}/debian
/control
" 
 680         echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
" 
 683 setupsimplenativepackage() { 
 684         _setupsimplenativepackage "$@
" 
 687         local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}" 
 688         test -e "${BUILDDIR}/debian
/compat
" || echo '7' > "${BUILDDIR}/debian
/compat
" 
 689         test -e  "${BUILDDIR}/debian
/rules
" || cp /usr/share/doc/debhelper/examples/rules.tiny "${BUILDDIR}/debian
/rules
" 
 692 buildsimplenativepackage() { 
 696         local RELEASE="${4:-unstable}" 
 697         local DEPENDENCIES="$5" 
 698         local DESCRIPTION="$6" 
 699         local SECTION="${7:-others}" 
 700         local PRIORITY="${8:-optional}" 
 702         local COMPRESS_TYPE="${10:-gzip}" 
 704         if [ "$SECTION" = "${SECTION#*/}" ]; then 
 707                 DISTSECTION="${SECTION%/*}" 
 709         local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}" 
 710         msgtest "Build 
source package 
in version 
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME" 
 711         _setupsimplenativepackage "$@
" 
 713         testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION} 
 715         sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \ 
 717                 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
" 
 718 #               if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then 
 719 #                       aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \ 
 720 #                               adv --yes --default-key 'Joe Sixpack' \ 
 721 #                               --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC" 
 722 #                       mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC" 
 726         for arch in $(getarchitecturesfromcommalist "$ARCH"); do 
 727                 msgtest "Build binary package 
for ${RELEASE} in ${SECTION}" "$NAME" 
 728                 rm -rf "${BUILDDIR}/debian
/tmp
" 
 729                 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
" 
 730                 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" 
 731                 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}" 
 732                 if [ -n "$FILE_TREE" ]; then 
 733                     cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
" 
 736                 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch) 
 737                 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums) 
 738                 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
" 
 739                 # ensure the right permissions as dpkg-deb insists 
 740                 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
" 
 741                 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
" 
 742                 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
" 
 746         if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then 
 747                 NM="$(echo "$NAME" | cut -c 1-4)" 
 749                 NM="$(echo "$NAME" | cut -c 1)" 
 751         local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}" 
 752         mkdir -p "$CHANGEPATH" 
 753         cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH" 
 762         local ARCH=$(getarchitecture $4) 
 763         local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')" 
 764         local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")" 
 765         msgtest "Build package 
for ${RELEASE} in ${SECTION}" "$PKGNAME" 
 767         if [ "$ARCH" = "all
" ]; then 
 768                 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" 
 770         testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH 
 771         cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG" 
 772         local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")" 
 773         local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')" 
 776                 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
" 
 779                 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
" 
 784         if [ -d incoming ]; then 
 785                 buildaptarchivefromincoming "$@
" 
 787                 buildaptarchivefromfiles "$@
" 
 791 createaptftparchiveconfig() { 
 792         local COMPRESSORS="$(cut -d'    ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')" 
 793         local COMPRESSORS="${COMPRESSORS%* }" 
 794         local ARCHS="$(getarchitectures)" 
 795         cat > ftparchive.conf <<EOF 
 797         ArchiveDir "$(readlink -f .)"; 
 798         CacheDir "$(readlink -f ..)"; 
 799         FileListDir "$(readlink -f pool/)"; 
 802         Packages::Compress "$COMPRESSORS"; 
 803         Sources::Compress "$COMPRESSORS"; 
 804         Contents::Compress "$COMPRESSORS"; 
 805         Translation::Compress "$COMPRESSORS"; 
 806         LongDescription "false
"; 
 810         SrcDirectory "pool
/"; 
 813         for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do 
 816         Architectures "$ARCHS all 
source"; 
 817         FileList "${DIST}.\
$(SECTION).pkglist
"; 
 818         SourceFileList "${DIST}.\
$(SECTION).srclist
"; 
 819         Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')"; 
 822         done >> ftparchive.conf 
 825 buildaptftparchivedirectorystructure() { 
 826         local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')" 
 827         for DIST in $DISTS; do 
 828                 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)" 
 829                 for SECTION in $SECTIONS; do 
 830                         local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')" 
 831                         for ARCH in $ARCHS; do 
 832                                 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}" 
 834                         mkdir -p "dists
/${DIST}/${SECTION}/source" 
 835                         mkdir -p "dists
/${DIST}/${SECTION}/i18n
" 
 845         local DEPENDENCIES="$5" 
 846         local PRIORITY="${6:-optional}" 
 847         local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES} 
 848  If you 
find such a package installed on your system
, 
 849  something went horribly wrong
! They are autogenerated
 
 850  und used only by testcases and serve no other purpose…
"}" 
 852         for RELEASE 
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do 
 853                 if [ "$RELEASE" = 'installed' ]; then 
 854                         insertinstalledpackage 
"$2" "$3" "$4" "$5" "$6" "$7" 
 857                 for arch 
in $(getarchitecturesfromcommalist "$ARCH"); do 
 858                         if [ "$arch" = 'none' ]; then 
 859                                 ARCHS
="$(getarchitectures)" 
 863                         for BUILDARCH 
in $ARCHS; do 
 864                                 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}" 
 871 Maintainer: Joe Sixpack <joe@example.org>" 
 872                                         test "$arch" = 'none' || echo "Architecture: $arch" 
 873                                         echo "Version: $VERSION 
 874 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" 
 875                                         test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" 
 876                                         echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" 
 877                                         echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" 
 878                                         echo "SHA256: 0000000000000000000000000000000000000000000000000000000000000000" 
 880                                 } >> "${PPATH}/Packages" 
 883                 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n" 
 884                 touch "aptarchive/dists/${RELEASE}/main/source/Sources" 
 886 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1) 
 887 Description-en: $DESCRIPTION 
 888 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en" 
 897         local DEPENDENCIES
="$5" 
 898         local BINARY
="${6:-$NAME}" 
 900         for RELEASE 
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do 
 901                 local SPATH
="aptarchive/dists/${RELEASE}/main/source" 
 903                 local FILE
="${SPATH}/Sources" 
 904                 local DSCFILE
="${NAME}_${VERSION}.dsc" 
 905                 local TARFILE
="${NAME}_${VERSION}.tar.gz" 
 909 Maintainer: Joe Sixpack <joe@example.org> 
 910 Architecture: $ARCH" >> $FILE 
 911                 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE" 
 913  $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE" 
 914  $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE" 
 916  $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE" 
 917  $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE" 
 922 insertinstalledpackage
() { 
 926         local DEPENDENCIES
="$4" 
 927         local PRIORITY
="${5:-optional}" 
 928         local STATUS
="${6:-install ok installed}" 
 929         local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed 
 930  If you find such a package installed on your system, 
 931  something went horribly wrong! They are autogenerated 
 932  und used only by testcases and serve no other purpose…"}" 
 934         local FILE='rootdir/var/lib/dpkg/status' 
 935         local INFO='rootdir/var/lib/dpkg/info' 
 936         for arch in $(getarchitecturesfromcommalist "$ARCH"); do 
 942 Maintainer
: Joe Sixpack 
<joe@example.org
> 
 943 Version
: $VERSION" >> "$FILE" 
 944                 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE" 
 945                 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE" 
 946                 echo "Description
: $DESCRIPTION" >> "$FILE" 
 948                 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then 
 949                         echo -n > "${INFO}/${NAME}:${arch}.list
" 
 951                         echo -n > "${INFO}/${NAME}.list
" 
 957 buildaptarchivefromincoming() { 
 958         msginfo "Build APT archive 
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
" 
 960         [ -e pool ] || ln -s ../incoming pool 
 961         [ -e ftparchive.conf ] || createaptftparchiveconfig 
 962         [ -e dists ] || buildaptftparchivedirectorystructure 
 963         msgninfo "\tGenerate Packages
, Sources and Contents files… 
" 
 964         testsuccess aptftparchive generate ftparchive.conf 
 967         generatereleasefiles "$@
" 
 970 buildaptarchivefromfiles() { 
 971         msginfo "Build APT archive 
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
" 
 972         local DIR='aptarchive' 
 973         if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi 
 974         find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do 
 975                 msgninfo "\t${line} file… 
" 
 976                 compressfile "$line" "$1" 
 979         generatereleasefiles "$@
" 
 983         while read compressor extension command; do 
 984                 if [ "$compressor" = '.' ]; then 
 990                 cat "$1" | $command > "${1}.
${extension}" 
 992                         touch -d "$2" "${1}.
${extension}" 
 994         done < "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
" 
 997 # can be overridden by testcases for their pleasure 
 998 getcodenamefromsuite() { 
1000         unstable) echo 'sid';; 
1004 getreleaseversionfromsuite() { true; } 
1005 getlabelfromsuite() { true; } 
1006 getoriginfromsuite() { true; } 
1007 getarchitecturesfromreleasefile() { echo "all 
$(getarchitectures)"; } 
1009 aptftparchiverelease() { 
1010         aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference 
1012 generatereleasefiles() { 
1013         # $1 is the Date header and $2 is the ValidUntil header to be set 
1014         # both should be given in notation date/touch can understand 
1016         local VALIDUNTIL="$2" 
1017         if [ -e aptarchive/dists ]; then 
1018                 msgninfo "\tGenerate Release files 
for dists… 
" 
1019                 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do 
1020                         local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")" 
1021                         local SUITE="$(echo "$dir" | cut -d'/' -f 4)" 
1022                         local CODENAME="$(getcodenamefromsuite $SUITE)" 
1023                         local VERSION="$(getreleaseversionfromsuite $SUITE)" 
1024                         local LABEL="$(getlabelfromsuite $SUITE)" 
1025                         local ORIGIN="$(getoriginfromsuite $SUITE)" 
1026                         aptftparchiverelease "$dir" \ 
1027                                 -o APT::FTPArchive::Release::Suite="${SUITE}" \ 
1028                                 -o APT::FTPArchive::Release::Codename="${CODENAME}" \ 
1029                                 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \ 
1030                                 -o APT::FTPArchive::Release::Label="${LABEL}" \ 
1031                                 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \ 
1032                                 -o APT::FTPArchive::Release::Version="${VERSION}" \ 
1034                         if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then 
1035                                 sed -i '/^Date: / a\ 
1036 NotAutomatic: yes' "$dir/Release
" 
1040                 msgninfo "\tGenerate Release files 
for flat… 
" 
1041                 aptftparchiverelease ./aptarchive > aptarchive/Release 
1043         if [ -n "$DATE" -a "$DATE" != "now
" ]; then 
1044                 for release in $(find ./aptarchive -name 'Release'); do 
1045                         sed -i "s
/^Date
: .
*$
/Date
: $(date -u -d "$DATE" -R)/" "$release" 
1046                         touch -d "$DATE" "$release" 
1049         if [ -n "$VALIDUNTIL" ]; then 
1050                 sed -i "/^Date
: / a\
 
1051 Valid
-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release') 
1056 setupdistsaptarchive() { 
1057         local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')" 
1058         rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list 
1059         rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list 
1060         for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do 
1061                 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ') 
1062                 msgninfo "\tadd deb and deb
-src sources.list lines 
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… 
" 
1063                 echo "deb 
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
" 
1064                 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
" 
1069 setupflataptarchive() { 
1070         local APTARCHIVE="$(readlink -f ./aptarchive)" 
1071         local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')" 
1072         if [ -f "${APTARCHIVE}/Packages
" ]; then 
1073                 msgninfo "\tadd deb sources.list line… 
" 
1074                 echo "deb 
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list' 
1077                 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list' 
1079         if [ -f "${APTARCHIVE}/Sources
" ]; then 
1080                 msgninfo "\tadd deb
-src sources.list line… 
" 
1081                 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list' 
1084                 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list' 
1090         if [ "$1" = '--no-update' ]; then 
1094         buildaptarchive "$@
" 
1095         if [ -e aptarchive/dists ]; then 
1096                 setupdistsaptarchive 
1100         signreleasefiles 'Joe Sixpack' 
1101         if [ "1" != "$NOUPDATE" ]; then 
1102                 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true 
1106 signreleasefiles() { 
1107         local SIGNERS="${1:-Joe Sixpack}" 
1108         local REPODIR="${2:-aptarchive}" 
1109         if [ -n "$1" ]; then shift; fi 
1110         if [ -n "$1" ]; then shift; fi 
1111         local KEY="keys
/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')" 
1112         msgninfo "\tSign archive with 
$SIGNERS key 
$KEY… 
" 
1113         local REXKEY='keys/rexexpired' 
1114         local SECEXPIREBAK="${REXKEY}.sec.bak
" 
1115         local PUBEXPIREBAK="${REXKEY}.pub.bak
" 
1117         while [ -n "${SIGNERS%%,*}" ]; do 
1118                 local SIGNER="${SIGNERS%%,*}" 
1119                 if [ "${SIGNERS}" = "${SIGNER}" ]; then 
1122                 SIGNERS="${SIGNERS#*,}" 
1123                 # FIXME: This should be the full name, but we can't encode the space properly currently 
1124                 SIGUSERS="${SIGUSERS} -u ${SIGNER#* }" 
1125                 if [ "${SIGNER}" = 'Rex Expired' ]; then 
1126                         # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time 
1127                         # option doesn't exist anymore (and using faketime would add a new obscure dependency) 
1128                         # therefore we 'temporary' make the key not expired and restore a backup after signing 
1129                         cp "${REXKEY}.sec
" "$SECEXPIREBAK" 
1130                         cp "${REXKEY}.pub
" "$PUBEXPIREBAK" 
1131                         local SECUNEXPIRED="${REXKEY}.sec.unexpired
" 
1132                         local PUBUNEXPIRED="${REXKEY}.pub.unexpired
" 
1133                         if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then 
1134                                 cp "$SECUNEXPIRED" "${REXKEY}.sec
" 
1135                                 cp "$PUBUNEXPIRED" "${REXKEY}.pub
" 
1137                                 if ! printf "expire
\n1w
\nsave
\n" | aptkey --quiet --keyring "${REXKEY}.pub
" --secret-keyring "${REXKEY}.sec
" \ 
1138                                         --readonly adv --batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \ 
1139                                         --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then 
1143                                 cp "${REXKEY}.sec
" "$SECUNEXPIRED" 
1144                                 cp "${REXKEY}.pub
" "$PUBUNEXPIRED" 
1147                 if [ ! -e "${KEY}.pub
" ]; then 
1148                         local K="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')" 
1149                         cat "${K}.pub
" >> "${KEY}.new.pub
" 
1150                         cat "${K}.sec
" >> "${KEY}.new.sec
" 
1153         if [ ! -e "${KEY}.pub
" ]; then 
1154                 mv "${KEY}.new.pub
" "${KEY}.pub
" 
1155                 mv "${KEY}.new.sec
" "${KEY}.sec
" 
1157         local GPG="aptkey 
--quiet --keyring ${KEY}.pub 
--secret-keyring ${KEY}.sec 
--readonly adv 
--batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}" 
1158         for RELEASE in $(find "${REPODIR}/" -name Release); do 
1159                 # we might have set a specific date for the Release file, so copy it 
1160                 local DATE="$(stat --format "%y" "${RELEASE}")" 
1161                 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then 
1162                         rm -f "${RELEASE}.gpg
" 
1164                         testsuccess $GPG "$@
" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}" 
1165                         touch -d "$DATE" "${RELEASE}.gpg
" 
1167                 local INRELEASE="${RELEASE%/*}/InRelease
" 
1168                 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then 
1171                         testsuccess $GPG "$@
" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE" 
1172                         touch -d "$DATE" "${INRELEASE}" 
1175         if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then 
1176                 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
" 
1177                 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
" 
1182 redatereleasefiles() { 
1183         local DATE="$(date -u -d "$1" -R)" 
1184         for release in $(find aptarchive/ -name 'Release'); do 
1185                 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release" 
1186                 touch -d "$DATE" "$release" 
1188         signreleasefiles "${2:-Joe Sixpack}" 
1192         local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}" 
1194         if [ "$1" = '--no-check' ]; then 
1198         local DOWNLOG='rootdir/tmp/download-testfile.log' 
1199         local STATUS='downloaded/webserverconfig.status' 
1200         rm -f "$STATUS" "$DOWNLOG" 
1201         # very very basic URI encoding 
1203         if [ -n "$2" ]; then 
1204                 msgtest "Set webserver config option 
'${1}' to
" "$2" 
1205                 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')" 
1207                 msgtest 'Clear webserver config option' "${1}" 
1208                 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')" 
1210         if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then 
1213                 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
" 
1214                 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true 
1215                 msgfailoutput '' "$OUTPUT" 
1217         $NOCHECK || testwebserverlaststatuscode '200' 
1220 rewritesourceslist() { 
1221         local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')" 
1222         local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')" 
1223         for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do 
1224                 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \ 
1225                         -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
 
1226                         -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#" 
1230 # wait for up to 10s for a pid file to appear to avoid possible race 
1231 # when a helper is started and dosn't write the PID quick enough 
1234         for i 
in $(seq 10); do 
1235                 if test -s "$PIDFILE"; then 
1240         msgdie 
"waiting for $PIDFILE failed" 
1244 changetowebserver
() { 
1246         if [ "$1" != '--no-rewrite' ]; then 
1251         if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then 
1253                 local LOG
="webserver.log" 
1254                 if ! aptwebserver 
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then 
1258                 waitforpidfile aptwebserver.pid
 
1259                 local PID
="$(cat aptwebserver.pid)" 
1260                 if [ -z "$PID" ]; then 
1261                         msgdie 
'Could not fork aptwebserver successfully' 
1263                 addtrap 
"kill $PID;" 
1264                 waitforpidfile aptwebserver.port
 
1265                 APTHTTPPORT
="$(cat aptwebserver.port)" 
1266                 if [ -z "$APTHTTPPORT" ]; then 
1267                         msgdie 
'Could not get port for aptwebserver successfully' 
1271                 msgdie 
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver' 
1273         if [ "$REWRTE" != 'yes' ]; then 
1274                 rewritesourceslist 
"http://localhost:${APTHTTPPORT}/" 
1278 changetohttpswebserver
() { 
1279         if ! command -v stunnel4 
>/dev
/null 
2>&1; then 
1280                 msgdie 
'You need to install stunnel4 for https testcases' 
1282         if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then 
1283                 changetowebserver 
--no-rewrite "$@" 
1285         echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid 
1286 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem 
1291 connect = $APTHTTPPORT 
1292 " > "${TMPWORKINGDIRECTORY}/stunnel.conf" 
1293         stunnel4 
"${TMPWORKINGDIRECTORY}/stunnel.conf" 
1294         waitforpidfile 
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid" 
1295         local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")" 
1296         if [ -z "$PID" ]; then 
1297                 msgdie 
'Could not fork stunnel4 successfully' 
1299         addtrap 
'prefix' "kill ${PID};" 
1300         APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)" 
1301         webserverconfig 
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}" 
1302         rewritesourceslist 
"https://localhost:${APTHTTPSPORT}/" 
1306         mkdir -p rootdir
/media
/cdrom
/.disk
 
1307         local CD
="$(readlink -f rootdir/media/cdrom)" 
1308         cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom 
<<EOF 
1309 acquire::cdrom::mount "${CD}"; 
1310 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}"; 
1311 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted"; 
1312 acquire::cdrom::autodetect 0; 
1314         echo -n "$1" > "${CD}/.disk/info" 
1315         if [ ! -d aptarchive
/dists 
]; then 
1316                 msgdie 
'Flat file archive cdroms can not be created currently' 
1319         mv aptarchive
/dists 
"$CD" 
1320         ln -s "$(readlink -f ./incoming)" "$CD/pool" 
1321         find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete 
1322         # start with an unmounted disk 
1323         mv "${CD}" "${CD}-unmounted" 
1324         # we don't want the disk to be modifiable 
1325         addtrap 
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;" 
1326         chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
 
1330         local PROTO
="${1%%:*}" 
1331         if ! apthelper 
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
 
1332                 download
-file "$1" "$2" "$3" 2>&1 ; then 
1335         # only if the file exists the download was successful 
1336         if [ -r "$2" ]; then 
1344         local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" 
1345         if [ -n "$DIFFTEXT" ]; then 
1347                 echo >&2 "$DIFFTEXT" 
1355         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output" 
1356         local COMPAREFILE
="$1" 
1358         if "$@" 2>&1 | checkdiff 
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then 
1361                 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}" 
1362                 cat "$COMPAREFILE" >>"${OUTPUT}" 
1363                 msgfailoutput 
'' "$OUTPUT" "$@" 
1368         msggroup 
'testfileequal' 
1369         local MSG
='Test for correctness of file' 
1370         if [ "$1" = '--nomsg' ]; then 
1376         if [ -n "$MSG" ]; then 
1377                 msgtest 
"$MSG" "$FILE" 
1379         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output" 
1380         if [ -z "$*" ]; then 
1381                 testoutputequal 
"$FILE" echo -n '' 
1383                 testoutputequal 
"$FILE" echo "$*" 
1389         msggroup 
'testempty' 
1390         if [ "$1" = '--nomsg' ]; then 
1393                 msgtest 
"Test for no output of" "$*" 
1395         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile" 
1396         if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then 
1399                 msgfailoutput 
'' "$COMPAREFILE" "$@" 
1401         aptautotest 
'testempty' "$@" 
1405         msggroup 
'testnotempty' 
1406         msgtest 
"Test for some output of" "$*" 
1407         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile" 
1408         if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then 
1411                 msgfailoutput 
'' "$COMPAREFILE" "$@" 
1413         aptautotest 
'testnotempty' "$@" 
1418         msggroup 
'testequal' 
1419         local MSG
='Test of equality of' 
1420         if [ "$1" = '--nomsg' ]; then 
1425         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile" 
1426         echo "$1" > "$COMPAREFILE" 
1429         if [ -n "$MSG" ]; then 
1432         testoutputequal 
"$COMPAREFILE" "$@" 
1433         aptautotest 
'testequal' "$@" 
1438         msggroup 
'testequalor2' 
1439         local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1" 
1440         local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2" 
1441         local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst" 
1442         echo "$1" > "$COMPAREFILE1" 
1443         echo "$2" > "$COMPAREFILE2" 
1445         msgtest 
"Test for equality OR of" "$*" 
1446         "$@" >"$COMPAREAGAINST" 2>&1 || true
 
1447         if checkdiff 
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null 
2>&1 || \
 
1448                 checkdiff 
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null 
2>&1 
1452                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output" 
1453                 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1 
1454                 checkdiff 
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
 
1455                 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1 
1456                 checkdiff 
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
 
1457                 msgfailoutput 
'' "$OUTPUT" 
1459         aptautotest 
'testequalor2' "$@" 
1464         msggroup 
'testshowvirtual' 
1465         local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual" 
1468         while [ -n "$1" ]; do 
1470 N: Can't select versions from package '$1' as it is purely virtual" 
1471                 PACKAGE
="${PACKAGE} $1" 
1474         msgtest 
"Test for virtual packages" "apt-cache show $PACKAGE" 
1476 N: No packages found" 
1477         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile" 
1478         local ARCH
="$(getarchitecture 'native')" 
1479         echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE" 
1480         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output" 
1481         testoutputequal 
"$COMPAREFILE" aptcache show 
"$PACKAGE" 
1486         msggroup 
'testnopackage' 
1487         msgtest 
"Test for non-existent packages" "apt-cache show $*" 
1488         local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')" 
1489         if [ -n "$SHOWPKG" ]; then 
1490                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" 
1491                 echo "$SHOWPKG" >"$OUTPUT" 
1492                 msgfailoutput 
'' "$OUTPUT" 
1498 testnosrcpackage
() { 
1499         msggroup 
'testnosrcpackage' 
1500         msgtest 
"Test for non-existent source packages" "apt-cache showsrc $*" 
1501         local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')" 
1502         if [ -n "$SHOWPKG" ]; then 
1503                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output" 
1504                 echo "$SHOWPKG" >"$OUTPUT" 
1505                 msgfailoutput 
'' "$OUTPUT" 
1513         msggroup 
'testdpkgstatus' 
1517         msgtest 
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*" 
1518         local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)" 
1519         if [ "$PKGS" != $NR ]; then 
1520                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" 
1521                 echo "$PKGS" >"$OUTPUT" 
1522                 dpkg 
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
 
1523                 msgfailoutput 
'' "$OUTPUT" 
1530 testdpkginstalled
() { 
1531         msggroup 
'testdpkginstalled' 
1532         testdpkgstatus 
'ii' "$#" "$@" 
1536 testdpkgnotinstalled
() { 
1537         msggroup 
'testdpkgnotinstalled' 
1538         testdpkgstatus 
'ii' '0' "$@" 
1543         msggroup 
'testmarkedauto' 
1544         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile" 
1545         if [ -n "$1" ]; then 
1546                 msgtest 
'Test for correctly marked as auto-installed' "$*" 
1547                 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE" 
1549                 msgtest 
'Test for correctly marked as auto-installed' 'no package' 
1550                 echo -n > "$COMPAREFILE" 
1552         testoutputequal 
"$COMPAREFILE" aptmark showauto
 
1555 testmarkedmanual
() { 
1556         msggroup 
'testmarkedmanual' 
1557         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile" 
1558         if [ -n "$1" ]; then 
1559                 msgtest 
'Test for correctly marked as manually installed' "$*" 
1560                 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE" 
1562                 msgtest 
'Test for correctly marked as manually installed' 'no package' 
1563                 echo -n > "$COMPAREFILE" 
1565         testoutputequal 
"$COMPAREFILE" aptmark showmanual
 
1570         if [ "${1##*.}" = 'deb' ]; then 
1571                 stat 
>&2 "$1" || true
 
1572                 file >&2 "$1" || true
 
1574                 cat >&2 "$1" || true
 
1578         msgreportheader 
'msgfailoutput' 
1583         if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then 
1585                 while [ -n "$2" ]; do shift; done 
1586                 echo "#### Complete file: $1 ####" 
1588                 echo "#### $CMD output ####" 
1589         elif [ "$1" = 'test' ]; then 
1591                 # doesn't support ! or non-file flags 
1592                 msgfailoutputstatfile
() { 
1593                         local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$' 
1594                         if expr match 
"$1" "$FILEFLAGS" >/dev
/null
; then 
1595                                 echo "#### stat(2) of file: $2 ####" 
1597                                 if test -d "$2"; then 
1598                                         echo "#### The directory contains: $2 ####" 
1600                                 elif test -e "$2"; then 
1601                                         echo "#### Complete file: $2 ####" 
1606                 msgfailoutputstatfile 
"$2" "$3" 
1607                 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do 
1609                         msgfailoutputstatfile 
"$2" "$3" 
1611                 echo '#### test output ####' 
1612         elif [ "$1" = 'cmp' ]; then 
1614                 while [ -n "$2" ]; do 
1615                         echo "#### Complete file: $2 ####" 
1619                 echo '#### cmp output ####' 
1625 testsuccesswithglobalerror
() { 
1630         if [ "$1" = '--nomsg' ]; then 
1633                 msgtest 
'Test for successful execution of' "$*" 
1635         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output" 
1636         if "$@" >"${OUTPUT}" 2>&1; then 
1637                 if expr match 
"$1" '^apt.*' >/dev
/null
; then 
1638                         if grep -q -E ' runtime error: ' "$OUTPUT"; then 
1639                                 msgfailoutput 
'compiler detected undefined behavior' "$OUTPUT" "$@" 
1640                         elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then 
1641                                 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then 
1642                                         if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
 
1643                                                 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null 
2>&1; then 
1646                                                 msgfailoutput 
'successful run, but output contains warnings/errors' "$OUTPUT" "$@" 
1649                                         msgfailoutput 
'successful run, but output contains warnings/errors' "$OUTPUT" "$@" 
1651                         elif [ "$TYPE" = 'testsuccesswithnotice' ]; then 
1652                                 if grep -q -E "^N: " "$OUTPUT"; then 
1655                                         msgfailoutput 
'successful run, but output had no notices' "$OUTPUT" "$@" 
1665                 msgfailoutput 
"exitcode $EXITCODE" "$OUTPUT" "$@" 
1667         aptautotest 
"$TYPE" "$@" 
1670 testsuccesswithnotice
() { 
1671         testsuccesswithglobalerror 
'testsuccesswithnotice' 'WE' "$@" 
1674         testsuccesswithglobalerror 
'testsuccess' 'NWE' "$@" 
1677         msggroup 
'testwarning' 
1678         if [ "$1" = '--nomsg' ]; then 
1681                 msgtest 
'Test for successful execution with warnings of' "$*" 
1683         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" 
1684         if "$@" >"${OUTPUT}" 2>&1; then 
1685                 if expr match 
"$1" '^apt.*' >/dev
/null
; then 
1686                         if grep -q -E ' runtime error: ' "$OUTPUT"; then 
1687                                 msgfailoutput 
'compiler detected undefined behavior' "$OUTPUT" "$@" 
1688                         elif grep -q -E '^E: ' "$OUTPUT"; then 
1689                                 msgfailoutput 
'successful run, but output contains errors' "$OUTPUT" "$@" 
1690                         elif ! grep -q -E '^W: ' "$OUTPUT"; then 
1691                                 msgfailoutput 
'successful run, but output contains no warnings' "$OUTPUT" "$@" 
1700                 msgfailoutput 
"exitcode $EXITCODE" "$OUTPUT" "$@" 
1702         aptautotest 
'testwarning' "$@" 
1706         msggroup 
'testfailure' 
1707         if [ "$1" = '--nomsg' ]; then 
1710                 msgtest 
'Test for failure in execution of' "$*" 
1712         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" 
1713         if "$@" >"${OUTPUT}" 2>&1; then 
1715                 msgfailoutput 
"exitcode $EXITCODE" "$OUTPUT" "$@" 
1718                 if expr match 
"$1" '^apt.*' >/dev
/null
; then 
1719                         if [ "$1" = 'aptkey' ]; then 
1720                                 if grep -q " Can't check signature:  
1722  signature could not be verified" "$OUTPUT"; then 
1725                                         msgfailoutput 
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@" 
1728                                 if grep -q -E ' runtime error: ' "$OUTPUT"; then 
1729                                         msgfailoutput 
'compiler detected undefined behavior' "$OUTPUT" "$@" 
1730                                 elif grep -q -E '==ERROR' "$OUTPUT"; then 
1731                                         msgfailoutput 
'compiler sanitizers reported errors' "$OUTPUT" "$@" 
1732                                 elif ! grep -q -E '^E: ' "$OUTPUT"; then 
1733                                         msgfailoutput 
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@" 
1742         aptautotest 
'testfailure' "$@" 
1746 testreturnstateequal
() { 
1748         if [ "$STATE" = 'testsuccesswithglobalerror' ]; then 
1752                 msggroup 
"${STATE}equal" 
1753                 if [ "$1" != '--nomsg' ]; then 
1756                         testsuccesswithglobalerror 
"$STATE" "$TYPE" "$@" 
1757                         testfileequal 
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" 
1761                         testsuccesswithglobalerror 
"$STATE" "$TYPE" "$@" 
1762                         testfileequal 
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" 
1765                 msggroup 
"${STATE}equal" 
1766                 if [ "$2" != '--nomsg' ]; then 
1770                         testfileequal 
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" 
1774                         "$STATE" --nomsg "$@" 
1775                         testfileequal 
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" 
1780 testsuccessequal
() { 
1781         # we compare output, so we know perfectly well about N: 
1782         testreturnstateequal 
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@" 
1784 testwarningequal
() { 
1785         testreturnstateequal 
'testwarning' "$@" 
1787 testfailureequal
() { 
1788         testreturnstateequal 
'testfailure' "$@" 
1792         msggroup 
'testfailuremsg' 
1796         msgtest 
'Check that the output of the previous failed command has expected' 'failures and warnings' 
1797         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile" 
1798         grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
 
1799         testoutputequal 
"$COMPAREFILE" echo "$CMP" 
1803         msggroup 
'testwarningmsg' 
1807         msgtest 
'Check that the output of the previous warned command has expected' 'warnings' 
1808         local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile" 
1809         grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
 
1810         testoutputequal 
"$COMPAREFILE" echo "$CMP" 
1815         msggroup 
'testfilestats' 
1816         msgtest 
"Test that file $1 has $2 $3" "$4" 
1817         if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then 
1820                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output" 
1823                         echo -n "stat(1) reports for $2: " 
1824                         stat 
--format "$2" "$1" || true
 
1826                 msgfailoutput 
'' "$OUTPUT" 
1830 testaccessrights
() { 
1831         msggroup 
'testaccessrights' 
1832         testfilestats 
"$1" '%a' '=' "$2" 
1836 testwebserverlaststatuscode
() { 
1837         msggroup 
'testwebserverlaststatuscode' 
1838         local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log' 
1839         local STATUS
='downloaded/webserverstatus-statusfile.log' 
1840         rm -f "$DOWNLOG" "$STATUS" 
1841         msgtest 
'Test last status code from the webserver was' "$1" 
1842         if downloadfile 
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then 
1845                 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output" 
1847                         if [ -n "$2" ]; then 
1849                                 echo >&2 '#### Additionally provided output files contain:' 
1852                         echo >&2 '#### Download log of the status code:' 
1855                 msgfailoutput 
"Status was $(cat "$STATUS")" "$OUTPUT" 
1860 mapkeynametokeyid
() { 
1861         while [ -n "$1" ]; do 
1863                         *Joe
*|*Sixpack
*|newarchive
) echo '5A90D141DBAC8DAE';; 
1864                         *Rex
*|*Expired
*) echo '4BC0A39C27CE74F9';; 
1865                         *Marvin
*|*Paranoid
*) echo 'E8525D47528144E2';; 
1866                         oldarchive
) echo 'FDD2DB85F68C85A3';; 
1867                         *) echo 'UNKNOWN KEY';; 
1873         local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output" 
1874         if ! aptkey list 
--with-colon | grep '^pub' | cut 
-d':' -f 5 > "$OUTPUT"; then 
1877         testfileequal 
"$OUTPUT" "$(mapkeynametokeyid "$@")" 
1881         echo "STOPPED execution. Press enter to continue" 
1886 logcurrentarchivedirectory
() { 
1887         find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f 
| while read line
; do 
1888                 stat 
--format '%U:%G:%a:%n' "$line" 
1889         done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" 
1891 listcurrentlistsdirectory
() { 
1893                 find rootdir
/var
/lib
/apt
/lists 
-maxdepth 1 -type d 
| while read line
; do 
1894                         stat 
--format '%U:%G:%a:%n' "$line" 
1896                 find rootdir
/var
/lib
/apt
/lists 
-maxdepth 1 \
! -type d 
| while read line
; do 
1897                         stat 
--format '%U:%G:%a:%s:%y:%n' "$line" 
1901 forallsupportedcompressors
() { 
1902         rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor" 
1903         for COMP 
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do 
1904                 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi 
1909 ### convenience hacks ### 
1911         # creating some directories by hand is a tedious task, so make it look simple 
1913         if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then 
1914                 # only the last directory created by mkdir is effected by the -m ! 
1915                 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" 
1916                 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" 
1917                 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" 
1918                 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock" 
1919                 if [ "$(id -u)" = '0' ]; then 
1920                         chown _apt
:root 
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" 
1927 ### The following tests are run by most test methods automatically to check 
1928 ### general things about commands executed without writing the test every time. 
1931         if [ $# -lt 3 ]; then return; fi 
1937                 if ! expr match 
"$i" '^-' >/dev
/null 
2>&1; then 
1943         local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')" 
1944         if command -v $AUTOTEST >/dev
/null
; then 
1945                 # save and restore the *.output files from other tests 
1946                 # as we might otherwise override them in these automatic tests 
1947                 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" 
1948                 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" 
1949                 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp" 
1950                 $AUTOTEST "$TESTCALL" "$@" 
1951                 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest" 
1952                 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest" 
1953                 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp" 
1957 aptautotest_aptget_update
() { 
1959         while [ -n "$2" ]; do 
1960                 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode 
1963         if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi 
1964         testfilestats 
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" 
1965         testfilestats 
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" 
1966         # all copied files are properly chmodded 
1967         local backupIFS
="$IFS" 
1968         IFS
="$(printf "\n\b")" 
1969         for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do 
1970                 testfilestats 
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644" 
1973         if [ "$TESTCALL" = 'testsuccess' ]; then 
1974                 # failure cases can retain partial files and such 
1975                 testempty 
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
) 
1977         if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then 
1978                 testfileequal 
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
 
1979                         "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)" 
1982 aptautotest_apt_update
() { aptautotest_aptget_update 
"$@"; } 
1983 aptautotest_aptcdrom_add
() { aptautotest_aptget_update 
"$@"; } 
1985 testaptautotestnodpkgwarning
() { 
1987         while [ -n "$2" ]; do 
1988                 if expr match 
"$2" '^-[a-z]*s' >/dev
/null 
2>&1; then return; fi # simulation mode 
1989                 if expr match 
"$2" '^-dy\?' >/dev
/null 
2>&1; then return; fi # download-only mode 
1992         testfailure 
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output" 
1995 aptautotest_aptget_install
() { testaptautotestnodpkgwarning 
"$@"; } 
1996 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning 
"$@"; } 
1997 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning 
"$@"; } 
1998 aptautotest_apt_install
() { testaptautotestnodpkgwarning 
"$@"; } 
1999 aptautotest_apt_remove
() { testaptautotestnodpkgwarning 
"$@"; } 
2000 aptautotest_apt_purge
() { testaptautotestnodpkgwarning 
"$@"; } 
2002 testaptmarknodefaultsections
() { 
2003         testfailure 
grep '^Auto-Installed: 0$' "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/extended_states" 
2005 aptautotest_aptmark_auto
() { testaptmarknodefaultsections 
"$@"; } 
2006 aptautotest_aptmark_manual
() { testaptmarknodefaultsections 
"$@"; } 
2007 aptautotest_aptget_markauto
() { testaptmarknodefaultsections 
"$@"; } 
2008 aptautotest_aptget_markmanual
() { testaptmarknodefaultsections 
"$@"; }