1 #!/bin/sh -- # no runable script, just for vi
5 # we all like colorful messages
6 if [ "$MSGCOLOR" != 'NO' ]; then
7 if [ ! -t 1 ]; then # but check that we output to a terminal
13 if [ "$MSGCOLOR" != 'NO' ]; then
14 CERROR
="\033[1;31m" # red
15 CWARNING
="\033[1;33m" # yellow
16 CMSG
="\033[1;32m" # green
17 CINFO
="\033[1;96m" # light blue
18 CDEBUG
="\033[1;94m" # blue
19 CNORMAL
="\033[0;39m" # default system console color
20 CDONE
="\033[1;32m" # green
21 CPASS
="\033[1;32m" # green
22 CFAIL
="\033[1;31m" # red
23 CCMD
="\033[1;35m" # pink
35 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cgfs]\)#apt-\1#')"
41 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
42 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
43 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
44 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
45 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
46 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
47 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
48 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
49 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
50 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
51 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
52 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
54 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
55 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
58 if [ $# -gt 0 ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
59 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
60 if [ -n "$APT_DEBUG_TESTS" ]; then
63 EXIT_CODE
=$((EXIT_CODE+1));
66 # enable / disable Debugging
67 MSGLEVEL
=${MSGLEVEL:-3}
68 if [ $MSGLEVEL -le 0 ]; then
71 if [ $MSGLEVEL -le 1 ]; then
75 if [ $MSGLEVEL -le 2 ]; then
79 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
80 msgskip
() { printf " ${CWARNING}S${CNORMAL}" >&2; }
81 if [ -n "$CFAIL" ]; then
82 msgfail
() { printf " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
84 msgfail
() { printf " ###FAILED###" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
87 if [ $MSGLEVEL -le 3 ]; then
91 if [ $MSGLEVEL -le 4 ]; then
96 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
97 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
98 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
99 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
100 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
103 printf "${CDONE}DONE${CNORMAL}\n";
107 if [ -f .
/aptconfig.conf
]; then
108 echo "./aptconfig.conf"
109 elif [ -f ..
/aptconfig.conf
]; then
110 echo "../aptconfig.conf"
114 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
118 sh
|aptitude
|*/*|command) ;;
119 *) CMD
="${BUILDDIRECTORY}/$CMD";;
121 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${LIBRARYPATH} $CMD "$@"
123 aptconfig
() { runapt apt
-config "$@"; }
124 aptcache
() { runapt apt
-cache "$@"; }
125 aptcdrom
() { runapt apt
-cdrom "$@"; }
126 aptget
() { runapt apt
-get "$@"; }
127 aptftparchive
() { runapt apt
-ftparchive "$@"; }
128 aptkey
() { runapt apt
-key "$@"; }
129 aptmark
() { runapt apt
-mark "$@"; }
130 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
131 apt
() { runapt apt
"$@"; }
132 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
133 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
134 aptitude
() { runapt aptitude
"$@"; }
135 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
136 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
139 command dpkg
--root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
"$@"
141 dpkgcheckbuilddeps
() {
142 command dpkg
-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
"$@"
147 runapt
command gdb
--quiet -ex run
"${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
151 # error if we about to overflow, but ...
152 # "255 failures ought to be enough for everybody"
153 if [ $EXIT_CODE -gt 255 ]; then
154 msgdie
"Total failure count $EXIT_CODE too big"
156 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
159 shellsetedetector
() {
161 if [ "$exit_status" != '0' ]; then
162 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
163 if [ "$EXIT_CODE" = '0' ]; then
164 EXIT_CODE
="$exit_status"
170 if [ "$1" = 'prefix' ]; then
171 CURRENTTRAP
="$2 $CURRENTTRAP"
173 CURRENTTRAP
="$CURRENTTRAP $1"
175 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
179 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
180 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
183 TMPWORKINGDIRECTORY
=$(mktemp -d)
184 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
185 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
187 if [ "$(id -u)" = '0' ]; then
188 # relax permissions so that running as root with user switching works
190 chmod o
+rx
"$TMPWORKINGDIRECTORY"
193 TESTDIRECTORY
=$(readlink -f $(dirname $0))
194 # allow overriding the default BUILDDIR location
195 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
196 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
197 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
198 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
199 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
200 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
201 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
204 cd $TMPWORKINGDIRECTORY
205 mkdir rootdir aptarchive keys
207 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
208 mkdir -p usr
/bin var
/cache var
/lib
/apt var
/log tmp
209 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
210 touch var
/lib
/dpkg
/available
212 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
213 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
214 mkdir -p usr
/lib
/apt
/solvers
215 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
216 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
217 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
219 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
221 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
222 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
224 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
227 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
228 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
229 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
231 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
232 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
233 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
235 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
236 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
237 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
239 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
240 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
241 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
242 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
243 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
244 # store apt-key were we can access it, even if we run it as a different user
245 # destroys coverage reporting though, so just do it for root for now
246 if [ "$(id -u)" = '0' ]; then
247 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
248 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
249 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
251 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
253 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
254 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
255 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
256 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
257 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
258 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
259 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
261 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
262 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
263 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
264 # too distracting for users, but helpful to detect changes
265 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
266 # in testcases, it can appear as if localhost has a rotation setup,
267 # hide this as we can't really deal with it properly
268 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
270 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
271 if [ "$(id -u)" = '0' ]; then
272 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
274 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
275 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
276 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
278 # Acquire::AllowInsecureRepositories=false is not yet the default
279 # but we want it to be the default soon
280 configallowinsecurerepositories
"false";
282 # cleanup the environment a bit
283 # prefer our apt binaries over the system apt binaries
284 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
285 export LC_ALL
=C.UTF
-8
286 unset LANGUAGE APT_CONFIG
287 unset GREP_OPTIONS DEB_BUILD_PROFILES
293 if [ "$1" = "native" -o -z "$1" ]; then
294 eval `aptconfig shell ARCH APT::Architecture`
295 if [ -n "$ARCH" ]; then
298 dpkg
--print-architecture
306 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
309 getarchitecturesfromcommalist
() {
310 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
313 configarchitecture
() {
315 echo "APT::Architecture \"$(getarchitecture $1)\";"
316 while [ -n "$1" ]; do
317 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
320 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
325 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
326 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
327 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
328 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
330 echo -n > rootdir/var/lib/dpkg/status
333 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
334 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
335 local ARCHS="$(getarchitectures)"
336 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
337 DPKGARCH="$(dpkg --print-architecture)"
338 for ARCH in ${ARCHS}; do
339 if [ "${ARCH}" != "${DPKGARCH}" ]; then
340 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
341 # old-style used e.g. in Ubuntu-P – and as it seems travis
342 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
343 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
347 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
348 # dpkg doesn't really check the version as long as it is fully installed,
349 # but just to be sure we choose one above the required version
350 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
356 configallowinsecurerepositories() {
357 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
361 configcompression() {
362 while [ -n "$1" ]; do
364 '.') printf ".
\t.
\tcat
\n";;
365 'gz') printf "gzip\tgz
\tgzip
\n";;
366 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
367 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
368 'xz') printf "xz
\txz
\txz
\n";;
369 *) printf "$1\t$1\t$1\n";;
372 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
379 gzip) COMPRESS='gz';;
380 bzip2) COMPRESS='bz2';;
381 lzma) COMPRESS='lzma';;
383 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
385 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
386 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
387 Dir::Bin::uncompressed \"/does/not/exist\";
388 Dir::Bin::gzip \"/does/not/exist\";
389 Dir::Bin::bzip2 \"/does/not/exist\";
390 Dir::Bin::lzma \"/does/not/exist\";
391 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
392 if [ -e "/bin/${COMPRESSOR}" ]; then
393 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
394 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
395 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
396 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
397 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
398 COMPRESSOR_CMD='xz
--format=lzma
'
400 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
405 setupsimplenativepackage() {
409 local RELEASE="${4:-unstable}"
410 local DEPENDENCIES="$5"
411 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
412 If you find such a package installed on your system,
413 something went horribly wrong! They are autogenerated
414 und used only by testcases and surf no other propose…"}"
416 local SECTION="${7:-others}"
418 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
421 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
423 local BUILDDIR=incoming/${NAME}-${VERSION}
424 mkdir -p ${BUILDDIR}/debian/source
426 echo "* most suckless software product ever" > FEATURES
427 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
428 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
432 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
433 test -e debian/control || echo "Source: $NAME
436 Maintainer: Joe Sixpack <joe@example.org>
437 Build-Depends: debhelper (>= 7)
438 Standards-Version: 3.9.1
440 Package: $NAME" > debian/control
441 if [ "$ARCH" = 'all
' ]; then
442 echo "Architecture: all" >> debian/control
444 echo "Architecture: any" >> debian/control
446 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
447 echo "Description: $DESCRIPTION" >> debian/control
449 test -e debian/compat || echo "7" > debian/compat
450 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
451 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
455 buildsimplenativepackage() {
459 local RELEASE="${4:-unstable}"
460 local DEPENDENCIES="$5"
461 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
462 If you find such a package installed on your system,
463 something went horribly wrong! They are autogenerated
464 und used only by testcases and surf no other propose…"}"
466 local SECTION="${7:-others}"
467 local PRIORITY="${8:-optional}"
469 local COMPRESS_TYPE="${10:-gzip}"
471 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
474 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
476 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
478 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
479 mkdir -p $BUILDDIR/debian/source
480 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
482 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
484 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
485 echo "$NAME ($VERSION) $RELEASE; urgency=low
489 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
493 Maintainer: Joe Sixpack <joe@example.org>
494 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
495 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
496 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
498 Package: $NAME" >> ${BUILDDIR}/debian/control
500 if [ "$ARCH" = 'all
' ]; then
501 echo "Architecture: all" >> ${BUILDDIR}/debian/control
503 echo "Architecture: any" >> ${BUILDDIR}/debian/control
505 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
506 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
507 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
509 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
510 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' \
512 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
513 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
514 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
515 # adv --yes --default-key 'Joe Sixpack' \
516 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
517 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
521 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
522 rm -rf ${BUILDDIR}/debian
/tmp
523 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
524 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
525 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
526 if [ -n "$FILE_TREE" ]; then
527 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
530 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
531 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
532 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
533 # ensure the right permissions as dpkg-deb ensists
534 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
535 if ! dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
540 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
543 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
544 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
545 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
554 local ARCH
=$(getarchitecture $4)
555 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
556 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
557 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
559 if [ "$ARCH" = "all" ]; then
560 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
562 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
566 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
567 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
570 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
573 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
579 if [ -d incoming
]; then
580 buildaptarchivefromincoming
"$@"
582 buildaptarchivefromfiles
"$@"
586 createaptftparchiveconfig
() {
587 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
588 COMPRESSORS
="${COMPRESSORS%* }"
589 local ARCHS
="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
590 if [ -z "$ARCHS" ]; then
591 # the pool is empty, so we will operate on faked packages - let us use the configured archs
592 ARCHS
="$(getarchitectures)"
595 ArchiveDir "' >> ftparchive.conf
596 echo -n $(readlink -f .) >> ftparchive.conf
598 CacheDir "' >> ftparchive.conf
599 echo -n $(readlink -f ..) >> ftparchive.conf
601 FileListDir "' >> ftparchive.conf
602 echo -n $(readlink -f pool/) >> ftparchive.conf
606 Packages::Compress "'"$COMPRESSORS"'";
607 Sources::Compress "'"$COMPRESSORS"'";
608 Contents::Compress "'"$COMPRESSORS"'";
609 Translation::Compress "'"$COMPRESSORS"'";
610 LongDescription "false";
614 SrcDirectory "pool/";
620 Label "apttestcases";
622 Description "repository with dummy packages";
623 Architectures "' >> ftparchive.conf
624 echo -n "$ARCHS" >> ftparchive.conf
628 };' >> ftparchive.conf
629 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
630 echo -n 'tree "dists/' >> ftparchive.conf
631 echo -n "$DIST" >> ftparchive.conf
633 Architectures "' >> ftparchive.conf
634 echo -n "$ARCHS" >> ftparchive.conf
636 FileList "' >> ftparchive.conf
637 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
639 SourceFileList "' >> ftparchive.conf
640 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
642 Sections "' >> ftparchive.conf
643 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
645 };' >> ftparchive.conf
649 buildaptftparchivedirectorystructure
() {
650 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
651 for DIST
in $DISTS; do
652 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
653 for SECTION
in $SECTIONS; do
654 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
655 for ARCH
in $ARCHS; do
656 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
658 mkdir -p dists
/${DIST}/${SECTION}/source
659 mkdir -p dists
/${DIST}/${SECTION}/i18n
669 local DEPENDENCIES
="$5"
670 local PRIORITY
="${6:-optional}"
671 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
672 If you find such a package installed on your system,
673 something went horribly wrong! They are autogenerated
674 und used only by testcases and surf no other propose…"}"
676 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
677 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
678 ARCHS="$(getarchitectures)"
682 for BUILDARCH in $ARCHS; do
683 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
684 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
685 touch aptarchive/dists/${RELEASE}/main/source/Sources
686 local FILE="${PPATH}/Packages
"
691 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
692 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
693 echo "Version
: $VERSION
694 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
695 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
696 echo "Description
: $DESCRIPTION" >> $FILE
707 local DEPENDENCIES="$5"
709 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
711 local FILE="${SPATH}/Sources
"
715 Maintainer
: Joe Sixpack
<joe@example.org
>
716 Architecture
: $ARCH" >> $FILE
717 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
719 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
720 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
724 insertinstalledpackage() {
728 local DEPENDENCIES="$4"
729 local PRIORITY="${5:-optional}"
730 local STATUS="${6:-install ok installed}"
731 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
732 If you
find such a package installed on your system
,
733 something went horribly wrong
! They are autogenerated
734 und used only by testcases and surf no other propose…
"}"
736 local FILE
='rootdir/var/lib/dpkg/status'
737 local INFO
='rootdir/var/lib/dpkg/info'
738 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
744 Maintainer: Joe Sixpack <joe@example.org>
745 Version: $VERSION" >> $FILE
746 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
747 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
748 echo "Description: $DESCRIPTION" >> $FILE
750 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
751 echo -n > ${INFO}/${NAME}:${arch}.list
753 echo -n > ${INFO}/${NAME}.list
759 buildaptarchivefromincoming
() {
760 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
762 [ -e pool
] || ln -s ..
/incoming pool
763 [ -e ftparchive.conf
] || createaptftparchiveconfig
764 [ -e dists
] || buildaptftparchivedirectorystructure
765 msgninfo
"\tGenerate Packages, Sources and Contents files… "
766 aptftparchive
-qq generate ftparchive.conf
769 generatereleasefiles
"$@"
772 buildaptarchivefromfiles
() {
773 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
774 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
775 msgninfo
"\t${line} file… "
776 compressfile
"$line" "$1"
779 generatereleasefiles
"$@"
783 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
784 if [ "$compressor" = '.' ]; then
790 cat "$1" | $command > "${1}.${extension}"
792 touch -d "$2" "${1}.${extension}"
797 # can be overridden by testcases for their pleasure
798 getcodenamefromsuite
() {
800 unstable
) echo 'sid';;
804 getreleaseversionfromsuite
() { true
; }
805 getlabelfromsuite
() { true
; }
807 generatereleasefiles
() {
808 # $1 is the Date header and $2 is the ValidUntil header to be set
809 # both should be given in notation date/touch can understand
810 msgninfo
"\tGenerate Release files… "
811 if [ -e aptarchive
/dists
]; then
812 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
813 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
814 local CODENAME
="$(getcodenamefromsuite $SUITE)"
815 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
816 local LABEL
="$(getlabelfromsuite $SUITE)"
817 if [ -n "$VERSION" ]; then
818 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
820 if [ -n "$LABEL" ]; then
821 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
823 aptftparchive
-qq release
$dir \
824 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
825 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
828 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
829 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
831 NotAutomatic: yes' $dir/Release
833 if [ -n "$1" -a "$1" != "now" ]; then
834 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
838 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
842 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
844 if [ -n "$1" -a "$1" != "now" ]; then
845 for release
in $(find ./aptarchive -name 'Release'); do
846 touch -d "$1" $release
852 setupdistsaptarchive
() {
853 local APTARCHIVE
=$(readlink -f ./aptarchive)
854 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
855 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
856 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
857 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
858 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
859 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
860 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
865 setupflataptarchive
() {
866 local APTARCHIVE
=$(readlink -f ./aptarchive)
867 if [ -f ${APTARCHIVE}/Packages
]; then
868 msgninfo
"\tadd deb sources.list line… "
869 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
872 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
874 if [ -f ${APTARCHIVE}/Sources
]; then
875 msgninfo
"\tadd deb-src sources.list line… "
876 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
879 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
885 if [ "$1" = '--no-update' ]; then
890 if [ -e aptarchive
/dists
]; then
895 signreleasefiles
'Joe Sixpack'
896 if [ "1" != "$NOUPDATE" ]; then
897 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
902 local SIGNER
="${1:-Joe Sixpack}"
903 local REPODIR
="${2:-aptarchive}"
904 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
905 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
906 msgninfo
"\tSign archive with $SIGNER key $KEY… "
907 local REXKEY
='keys/rexexpired'
908 local SECEXPIREBAK
="${REXKEY}.sec.bak"
909 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
910 if [ "${SIGNER}" = 'Rex Expired' ]; then
911 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
912 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
913 # therefore we 'temporary' make the key not expired and restore a backup after signing
914 cp ${REXKEY}.sec
$SECEXPIREBAK
915 cp ${REXKEY}.pub
$PUBEXPIREBAK
916 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
917 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
918 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
919 cp $SECUNEXPIRED ${REXKEY}.sec
920 cp $PUBUNEXPIRED ${REXKEY}.pub
922 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
926 cp ${REXKEY}.sec
$SECUNEXPIRED
927 cp ${REXKEY}.pub
$PUBUNEXPIRED
930 for RELEASE
in $(find ${REPODIR}/ -name Release); do
931 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
932 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
933 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
934 # we might have set a specific date for the Release file, so copy it
935 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
937 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
938 mv -f $SECEXPIREBAK ${REXKEY}.sec
939 mv -f $PUBEXPIREBAK ${REXKEY}.pub
945 msgtest
"Set webserver config option '${1}' to" "$2"
946 local DOWNLOG
='rootdir/tmp/download-testfile.log'
947 local STATUS
='rootdir/tmp/webserverconfig.status'
948 rm -f "$STATUS" "$DOWNLOG"
949 if downloadfile
"http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then
952 cat "$DOWNLOG" "$STATUS"
955 testwebserverlaststatuscode
'200'
958 rewritesourceslist
() {
959 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
960 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
961 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
965 # wait for up to 10s for a pid file to appear to avoid possible race
966 # when a helper is started and dosn't write the PID quick enough
969 for i
in $(seq 10); do
970 if test -s "$PIDFILE"; then
975 msgdie
"waiting for $PIDFILE failed"
979 changetowebserver
() {
980 if [ "$1" != '--no-rewrite' ]; then
981 rewritesourceslist
'http://localhost:8080/'
985 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
987 local LOG
="webserver.log"
988 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
992 waitforpidfile aptwebserver.pid
993 local PID
="$(cat aptwebserver.pid)"
994 if [ -z "$PID" ]; then
995 msgdie
'Could not fork aptwebserver successfully'
1000 msgdie
'You have to build aptwerbserver or install a webserver'
1004 changetohttpswebserver
() {
1005 if ! which stunnel4
>/dev
/null
; then
1006 msgdie
'You need to install stunnel4 for https testcases'
1008 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1009 changetowebserver
--no-rewrite "$@"
1011 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1012 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1018 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1019 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1020 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1021 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1022 if [ -z "$PID" ]; then
1023 msgdie
'Could not fork stunnel4 successfully'
1025 addtrap
'prefix' "kill ${PID};"
1026 rewritesourceslist
'https://localhost:4433/'
1030 mkdir -p rootdir
/media
/cdrom
/.disk
1031 local CD
="$(readlink -f rootdir/media/cdrom)"
1032 echo "acquire::cdrom::mount \"${CD}\";
1033 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1034 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1035 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1036 echo -n "$1" > ${CD}/.disk
/info
1037 if [ ! -d aptarchive
/dists
]; then
1038 msgdie
'Flat file archive cdroms can not be created currently'
1041 mv aptarchive
/dists
"$CD"
1042 ln -s "$(readlink -f ./incoming)" $CD/pool
1043 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1044 # start with an unmounted disk
1045 mv "${CD}" "${CD}-unmounted"
1046 # we don't want the disk to be modifiable
1047 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1048 chmod -R -w rootdir
/media
/cdrom
-unmounted/dists
1052 local PROTO
="$(echo "$1" | cut -d':' -f 1 )"
1053 apthelper
-o Debug
::Acquire
::${PROTO}=1 \
1054 download
-file "$1" "$2" 2>&1 || true
1055 # only if the file exists the download was successful
1056 if [ -e "$2" ]; then
1064 local DIFFTEXT
="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1065 if [ -n "$DIFFTEXT" ]; then
1067 echo >&2 "$DIFFTEXT"
1077 msgtest
"Test for correctness of file" "$FILE"
1078 if [ -z "$*" ]; then
1079 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1081 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1086 msgtest
"Test for no output of" "$*"
1087 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1088 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1094 aptautotest
'testempty' "$@"
1098 local MSG
='Test of equality of'
1099 if [ "$1" = '--nomsg' ]; then
1104 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1105 echo "$1" > $COMPAREFILE
1108 if [ -n "$MSG" ]; then
1111 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1112 aptautotest
'testequal' "$@"
1116 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1117 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1118 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1119 echo "$1" > $COMPAREFILE1
1120 echo "$2" > $COMPAREFILE2
1122 msgtest
"Test for equality OR of" "$*"
1123 "$@" >$COMPAREAGAINST 2>&1 || true
1124 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1125 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1129 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1130 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1131 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1132 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1135 aptautotest
'testequalor2' "$@"
1139 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1142 while [ -n "$1" ]; do
1144 N: Can't select versions from package '$1' as it is purely virtual"
1145 PACKAGE
="${PACKAGE} $1"
1148 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1150 N: No packages found"
1151 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1152 local ARCH
="$(getarchitecture 'native')"
1153 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1154 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1158 msgtest
"Test for non-existent packages" "apt-cache show $*"
1159 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1160 if [ -n "$SHOWPKG" ]; then
1169 testdpkginstalled
() {
1170 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1171 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1172 if [ "$PKGS" != $# ]; then
1174 dpkg
-l "$@" | grep '^[a-z]' >&2
1181 testdpkgnotinstalled
() {
1182 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1183 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1184 if [ "$PKGS" != 0 ]; then
1186 dpkg
-l "$@" | grep '^[a-z]' >&2
1194 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1195 if [ -n "$1" ]; then
1196 msgtest
'Test for correctly marked as auto-installed' "$*"
1197 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1199 msgtest
'Test for correctly marked as auto-installed' 'no package'
1200 echo -n > $COMPAREFILE
1202 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1206 if [ "$1" = '--nomsg' ]; then
1209 msgtest
'Test for successful execution of' "$*"
1211 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1212 if "$@" >${OUTPUT} 2>&1; then
1213 if expr match
"$1" '^apt.*' >/dev
/null
; then
1214 if grep -q -E '^[WE]: ' "$OUTPUT"; then
1217 msgfail
'successful run, but output contains warnings/errors'
1228 msgfail
"exitcode $EXITCODE"
1230 aptautotest
'testsuccess' "$@"
1233 if [ "$1" = '--nomsg' ]; then
1236 msgtest
'Test for successful execution with warnings of' "$*"
1238 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1239 if "$@" >${OUTPUT} 2>&1; then
1240 if expr match
"$1" '^apt.*' >/dev
/null
; then
1241 if grep -q -E '^E: ' "$OUTPUT"; then
1244 msgfail
'successful run, but output contains errors'
1245 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1248 msgfail
'successful run, but output contains no warnings'
1259 msgfail
"exitcode $EXITCODE"
1261 aptautotest
'testwarning' "$@"
1264 if [ "$1" = '--nomsg' ]; then
1267 msgtest
'Test for failure in execution of' "$*"
1269 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1270 if "$@" >${OUTPUT} 2>&1; then
1274 msgfail
"exitcode $EXITCODE"
1277 if expr match
"$1" '^apt.*' >/dev
/null
; then
1278 if ! grep -q -E '^E: ' "$OUTPUT"; then
1281 msgfail
"run failed with exitcode ${EXITCODE}, but with no errors"
1289 aptautotest
'testfailure' "$@"
1293 msgtest
"Test that file $1 has $2 $3" "$4"
1294 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1299 echo -n >&2 "stat(1) reports for $2: "
1300 stat
--format "$2" "$1"
1304 testaccessrights
() {
1305 testfilestats
"$1" '%a' '=' "$2"
1308 testwebserverlaststatuscode
() {
1309 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1310 local STATUS
='rootdir/tmp/webserverstatus-statusfile.log'
1311 rm -f "$DOWNLOG" "$STATUS"
1312 msgtest
'Test last status code from the webserver was' "$1"
1313 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
1314 if [ "$(cat "$STATUS")" = "$1" ]; then
1318 if [ -n "$2" ]; then
1320 echo >&2 '#### Additionally provided output files contain:'
1323 echo >&2 '#### Download log of the status code:'
1325 msgfail
"Status was $(cat "$STATUS")"
1330 echo "STOPPED execution. Press enter to continue"
1335 listcurrentlistsdirectory
() {
1336 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1337 stat
--format '%U:%G:%a:%n' "$line"
1339 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1340 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1344 ### The following tests are run by most test methods automatically to check
1345 ### general things about commands executed without writing the test every time.
1351 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1352 if command -v $AUTOTEST >/dev
/null
; then
1354 # save and restore the *.output files from other tests
1355 # as we might otherwise override them in these automatic tests
1356 rm -rf rootdir
/tmp
-before
1357 mv rootdir
/tmp rootdir
/tmp
-before
1359 $AUTOTEST "$TESTCALL" "$@"
1360 rm -rf rootdir
/tmp
-aptautotest
1361 mv rootdir
/tmp rootdir
/tmp
-aptautotest
1362 mv rootdir
/tmp
-before rootdir
/tmp
1366 aptautotest_aptget_update
() {
1367 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1368 # all copied files are properly chmodded
1369 find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f
| while read file; do
1370 testfilestats
"$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
1373 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }