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 TMPWORKINGDIRECTORY
=$(mktemp -d)
180 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
181 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
183 if [ "$(id -u)" = '0' ]; then
184 # relax permissions so that running as root with user switching works
186 chmod o
+rx
"$TMPWORKINGDIRECTORY"
189 TESTDIRECTORY
=$(readlink -f $(dirname $0))
190 # allow overriding the default BUILDDIR location
191 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
192 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
193 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
194 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
195 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
196 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
197 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
200 cd $TMPWORKINGDIRECTORY
201 mkdir rootdir aptarchive keys
203 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
204 mkdir -p usr
/bin var
/cache var
/lib
/apt var
/log tmp
205 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
206 touch var
/lib
/dpkg
/available
208 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
209 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
210 mkdir -p usr
/lib
/apt
/solvers
211 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
212 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
213 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
215 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
217 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
218 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
220 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
223 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
224 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
225 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
227 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
228 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
229 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
231 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
232 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
233 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
235 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
236 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
237 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
238 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
239 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
240 # store apt-key were we can access it, even if we run it as a different user
241 # destroys coverage reporting though, so just do it for root for now
242 if [ "$(id -u)" = '0' ]; then
243 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
244 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
245 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
247 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
249 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
250 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
251 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
252 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
253 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
254 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
255 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
257 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
258 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
259 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
260 # too distracting for users, but helpful to detect changes
261 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
262 # in testcases, it can appear as if localhost has a rotation setup,
263 # hide this as we can't really deal with it properly
264 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
266 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
267 if [ "$(id -u)" = '0' ]; then
268 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
270 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
271 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
272 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
274 # Acquire::AllowInsecureRepositories=false is not yet the default
275 # but we want it to be the default soon
276 configallowinsecurerepositories
"false";
278 # cleanup the environment a bit
279 # prefer our apt binaries over the system apt binaries
280 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
281 export LC_ALL
=C.UTF
-8
282 unset LANGUAGE APT_CONFIG
283 unset GREP_OPTIONS DEB_BUILD_PROFILES
289 if [ "$1" = "native" -o -z "$1" ]; then
290 eval `aptconfig shell ARCH APT::Architecture`
291 if [ -n "$ARCH" ]; then
294 dpkg
--print-architecture
302 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
305 getarchitecturesfromcommalist
() {
306 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
309 configarchitecture
() {
311 echo "APT::Architecture \"$(getarchitecture $1)\";"
312 while [ -n "$1" ]; do
313 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
316 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
321 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
322 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
323 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
324 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
326 echo -n > rootdir/var/lib/dpkg/status
329 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
330 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
331 local ARCHS="$(getarchitectures)"
332 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
333 DPKGARCH="$(dpkg --print-architecture)"
334 for ARCH in ${ARCHS}; do
335 if [ "${ARCH}" != "${DPKGARCH}" ]; then
336 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
337 # old-style used e.g. in Ubuntu-P – and as it seems travis
338 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
339 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
343 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
344 # dpkg doesn't really check the version as long as it is fully installed,
345 # but just to be sure we choose one above the required version
346 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
352 configallowinsecurerepositories() {
353 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
357 configcompression() {
358 while [ -n "$1" ]; do
360 '.') printf ".
\t.
\tcat
\n";;
361 'gz') printf "gzip\tgz
\tgzip
\n";;
362 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
363 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
364 'xz') printf "xz
\txz
\txz
\n";;
365 *) printf "$1\t$1\t$1\n";;
368 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
375 gzip) COMPRESS='gz';;
376 bzip2) COMPRESS='bz2';;
377 lzma) COMPRESS='lzma';;
379 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
381 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
382 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
383 Dir::Bin::uncompressed \"/does/not/exist\";
384 Dir::Bin::gzip \"/does/not/exist\";
385 Dir::Bin::bzip2 \"/does/not/exist\";
386 Dir::Bin::lzma \"/does/not/exist\";
387 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
388 if [ -e "/bin/${COMPRESSOR}" ]; then
389 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
390 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
391 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
392 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
393 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
394 COMPRESSOR_CMD='xz
--format=lzma
'
396 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
401 setupsimplenativepackage() {
405 local RELEASE="${4:-unstable}"
406 local DEPENDENCIES="$5"
407 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
408 If you find such a package installed on your system,
409 something went horribly wrong! They are autogenerated
410 und used only by testcases and surf no other propose…"}"
412 local SECTION="${7:-others}"
414 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
417 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
419 local BUILDDIR=incoming/${NAME}-${VERSION}
420 mkdir -p ${BUILDDIR}/debian/source
422 echo "* most suckless software product ever" > FEATURES
423 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
424 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
428 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
429 test -e debian/control || echo "Source: $NAME
432 Maintainer: Joe Sixpack <joe@example.org>
433 Build-Depends: debhelper (>= 7)
434 Standards-Version: 3.9.1
436 Package: $NAME" > debian/control
437 if [ "$ARCH" = 'all
' ]; then
438 echo "Architecture: all" >> debian/control
440 echo "Architecture: any" >> debian/control
442 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
443 echo "Description: $DESCRIPTION" >> debian/control
445 test -e debian/compat || echo "7" > debian/compat
446 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
447 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
451 buildsimplenativepackage() {
455 local RELEASE="${4:-unstable}"
456 local DEPENDENCIES="$5"
457 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
458 If you find such a package installed on your system,
459 something went horribly wrong! They are autogenerated
460 und used only by testcases and surf no other propose…"}"
462 local SECTION="${7:-others}"
463 local PRIORITY="${8:-optional}"
465 local COMPRESS_TYPE="${10:-gzip}"
467 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
470 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
472 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
474 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
475 mkdir -p $BUILDDIR/debian/source
476 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
478 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
480 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
481 echo "$NAME ($VERSION) $RELEASE; urgency=low
485 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
489 Maintainer: Joe Sixpack <joe@example.org>
490 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
491 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
492 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
494 Package: $NAME" >> ${BUILDDIR}/debian/control
496 if [ "$ARCH" = 'all
' ]; then
497 echo "Architecture: all" >> ${BUILDDIR}/debian/control
499 echo "Architecture: any" >> ${BUILDDIR}/debian/control
501 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
502 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
503 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
505 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
506 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' \
508 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
509 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
510 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
511 # adv --yes --default-key 'Joe Sixpack' \
512 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
513 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
517 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
518 rm -rf ${BUILDDIR}/debian
/tmp
519 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
520 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
521 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
522 if [ -n "$FILE_TREE" ]; then
523 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
526 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
527 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
528 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
529 # ensure the right permissions as dpkg-deb ensists
530 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
531 if ! dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
536 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
539 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
540 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
541 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
550 local ARCH
=$(getarchitecture $4)
551 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
552 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
553 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
555 if [ "$ARCH" = "all" ]; then
556 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
558 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
562 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
563 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
566 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
569 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
575 if [ -d incoming
]; then
576 buildaptarchivefromincoming
"$@"
578 buildaptarchivefromfiles
"$@"
582 createaptftparchiveconfig
() {
583 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
584 COMPRESSORS
="${COMPRESSORS%* }"
585 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' ' ')"
586 if [ -z "$ARCHS" ]; then
587 # the pool is empty, so we will operate on faked packages - let us use the configured archs
588 ARCHS
="$(getarchitectures)"
591 ArchiveDir "' >> ftparchive.conf
592 echo -n $(readlink -f .) >> ftparchive.conf
594 CacheDir "' >> ftparchive.conf
595 echo -n $(readlink -f ..) >> ftparchive.conf
597 FileListDir "' >> ftparchive.conf
598 echo -n $(readlink -f pool/) >> ftparchive.conf
602 Packages::Compress "'"$COMPRESSORS"'";
603 Sources::Compress "'"$COMPRESSORS"'";
604 Contents::Compress "'"$COMPRESSORS"'";
605 Translation::Compress "'"$COMPRESSORS"'";
606 LongDescription "false";
610 SrcDirectory "pool/";
616 Label "apttestcases";
618 Description "repository with dummy packages";
619 Architectures "' >> ftparchive.conf
620 echo -n "$ARCHS" >> ftparchive.conf
624 };' >> ftparchive.conf
625 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
626 echo -n 'tree "dists/' >> ftparchive.conf
627 echo -n "$DIST" >> ftparchive.conf
629 Architectures "' >> ftparchive.conf
630 echo -n "$ARCHS" >> ftparchive.conf
632 FileList "' >> ftparchive.conf
633 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
635 SourceFileList "' >> ftparchive.conf
636 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
638 Sections "' >> ftparchive.conf
639 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
641 };' >> ftparchive.conf
645 buildaptftparchivedirectorystructure
() {
646 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
647 for DIST
in $DISTS; do
648 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
649 for SECTION
in $SECTIONS; do
650 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
651 for ARCH
in $ARCHS; do
652 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
654 mkdir -p dists
/${DIST}/${SECTION}/source
655 mkdir -p dists
/${DIST}/${SECTION}/i18n
665 local DEPENDENCIES
="$5"
666 local PRIORITY
="${6:-optional}"
667 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
668 If you find such a package installed on your system,
669 something went horribly wrong! They are autogenerated
670 und used only by testcases and surf no other propose…"}"
672 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
673 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
674 ARCHS="$(getarchitectures)"
678 for BUILDARCH in $ARCHS; do
679 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
680 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
681 touch aptarchive/dists/${RELEASE}/main/source/Sources
682 local FILE="${PPATH}/Packages
"
687 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
688 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
689 echo "Version
: $VERSION
690 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
691 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
692 echo "Description
: $DESCRIPTION" >> $FILE
703 local DEPENDENCIES="$5"
705 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
707 local FILE="${SPATH}/Sources
"
711 Maintainer
: Joe Sixpack
<joe@example.org
>
712 Architecture
: $ARCH" >> $FILE
713 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
715 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
716 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
720 insertinstalledpackage() {
724 local DEPENDENCIES="$4"
725 local PRIORITY="${5:-optional}"
726 local STATUS="${6:-install ok installed}"
727 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
728 If you
find such a package installed on your system
,
729 something went horribly wrong
! They are autogenerated
730 und used only by testcases and surf no other propose…
"}"
732 local FILE
='rootdir/var/lib/dpkg/status'
733 local INFO
='rootdir/var/lib/dpkg/info'
734 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
740 Maintainer: Joe Sixpack <joe@example.org>
741 Version: $VERSION" >> $FILE
742 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
743 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
744 echo "Description: $DESCRIPTION" >> $FILE
746 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
747 echo -n > ${INFO}/${NAME}:${arch}.list
749 echo -n > ${INFO}/${NAME}.list
755 buildaptarchivefromincoming
() {
756 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
758 [ -e pool
] || ln -s ..
/incoming pool
759 [ -e ftparchive.conf
] || createaptftparchiveconfig
760 [ -e dists
] || buildaptftparchivedirectorystructure
761 msgninfo
"\tGenerate Packages, Sources and Contents files… "
762 aptftparchive
-qq generate ftparchive.conf
765 generatereleasefiles
"$@"
768 buildaptarchivefromfiles
() {
769 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
770 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
771 msgninfo
"\t${line} file… "
772 compressfile
"$line" "$1"
775 generatereleasefiles
"$@"
779 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
780 if [ "$compressor" = '.' ]; then
786 cat "$1" | $command > "${1}.${extension}"
788 touch -d "$2" "${1}.${extension}"
793 # can be overridden by testcases for their pleasure
794 getcodenamefromsuite
() {
796 unstable
) echo 'sid';;
800 getreleaseversionfromsuite
() { true
; }
801 getlabelfromsuite
() { true
; }
803 generatereleasefiles
() {
804 # $1 is the Date header and $2 is the ValidUntil header to be set
805 # both should be given in notation date/touch can understand
806 msgninfo
"\tGenerate Release files… "
807 if [ -e aptarchive
/dists
]; then
808 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
809 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
810 local CODENAME
="$(getcodenamefromsuite $SUITE)"
811 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
812 local LABEL
="$(getlabelfromsuite $SUITE)"
813 if [ -n "$VERSION" ]; then
814 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
816 if [ -n "$LABEL" ]; then
817 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
819 aptftparchive
-qq release
$dir \
820 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
821 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
824 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
825 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
827 NotAutomatic: yes' $dir/Release
829 if [ -n "$1" -a "$1" != "now" ]; then
830 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
834 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
838 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
840 if [ -n "$1" -a "$1" != "now" ]; then
841 for release
in $(find ./aptarchive -name 'Release'); do
842 touch -d "$1" $release
848 setupdistsaptarchive
() {
849 local APTARCHIVE
=$(readlink -f ./aptarchive)
850 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
851 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
852 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
853 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
854 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
855 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
856 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
861 setupflataptarchive
() {
862 local APTARCHIVE
=$(readlink -f ./aptarchive)
863 if [ -f ${APTARCHIVE}/Packages
]; then
864 msgninfo
"\tadd deb sources.list line… "
865 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
868 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
870 if [ -f ${APTARCHIVE}/Sources
]; then
871 msgninfo
"\tadd deb-src sources.list line… "
872 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
875 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
881 if [ "$1" = '--no-update' ]; then
886 if [ -e aptarchive
/dists
]; then
891 signreleasefiles
'Joe Sixpack'
892 if [ "1" != "$NOUPDATE" ]; then
893 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
898 local SIGNER
="${1:-Joe Sixpack}"
899 local REPODIR
="${2:-aptarchive}"
900 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
901 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
902 msgninfo
"\tSign archive with $SIGNER key $KEY… "
903 local REXKEY
='keys/rexexpired'
904 local SECEXPIREBAK
="${REXKEY}.sec.bak"
905 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
906 if [ "${SIGNER}" = 'Rex Expired' ]; then
907 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
908 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
909 # therefore we 'temporary' make the key not expired and restore a backup after signing
910 cp ${REXKEY}.sec
$SECEXPIREBAK
911 cp ${REXKEY}.pub
$PUBEXPIREBAK
912 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
913 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
914 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
915 cp $SECUNEXPIRED ${REXKEY}.sec
916 cp $PUBUNEXPIRED ${REXKEY}.pub
918 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
922 cp ${REXKEY}.sec
$SECUNEXPIRED
923 cp ${REXKEY}.pub
$PUBUNEXPIRED
926 for RELEASE
in $(find ${REPODIR}/ -name Release); do
927 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
928 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
929 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
930 # we might have set a specific date for the Release file, so copy it
931 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
933 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
934 mv -f $SECEXPIREBAK ${REXKEY}.sec
935 mv -f $PUBEXPIREBAK ${REXKEY}.pub
941 msgtest
"Set webserver config option '${1}' to" "$2"
942 local DOWNLOG
='rootdir/tmp/download-testfile.log'
943 local STATUS
='rootdir/tmp/webserverconfig.status'
944 rm -f "$STATUS" "$DOWNLOG"
945 if downloadfile
"http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then
948 cat "$DOWNLOG" "$STATUS"
951 testwebserverlaststatuscode
'200'
954 rewritesourceslist
() {
955 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
956 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
957 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
961 # wait for up to 10s for a pid file to appear to avoid possible race
962 # when a helper is started and dosn't write the PID quick enough
965 for i
in $(seq 10); do
966 if test -s "$PIDFILE"; then
971 msgdie
"waiting for $PIDFILE failed"
975 changetowebserver
() {
976 if [ "$1" != '--no-rewrite' ]; then
977 rewritesourceslist
'http://localhost:8080/'
981 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
983 local LOG
="webserver.log"
984 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
988 waitforpidfile aptwebserver.pid
989 local PID
="$(cat aptwebserver.pid)"
990 if [ -z "$PID" ]; then
991 msgdie
'Could not fork aptwebserver successfully'
996 msgdie
'You have to build aptwerbserver or install a webserver'
1000 changetohttpswebserver
() {
1001 if ! which stunnel4
>/dev
/null
; then
1002 msgdie
'You need to install stunnel4 for https testcases'
1004 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1005 changetowebserver
--no-rewrite "$@"
1007 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1008 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1014 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1015 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1016 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1017 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1018 if [ -z "$PID" ]; then
1019 msgdie
'Could not fork stunnel4 successfully'
1021 addtrap
'prefix' "kill ${PID};"
1022 rewritesourceslist
'https://localhost:4433/'
1026 mkdir -p rootdir
/media
/cdrom
/.disk
1027 local CD
="$(readlink -f rootdir/media/cdrom)"
1028 echo "acquire::cdrom::mount \"${CD}\";
1029 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1030 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1031 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1032 echo -n "$1" > ${CD}/.disk
/info
1033 if [ ! -d aptarchive
/dists
]; then
1034 msgdie
'Flat file archive cdroms can not be created currently'
1037 mv aptarchive
/dists
"$CD"
1038 ln -s "$(readlink -f ./incoming)" $CD/pool
1039 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1040 # start with an unmounted disk
1041 mv "${CD}" "${CD}-unmounted"
1042 # we don't want the disk to be modifiable
1043 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1044 chmod -R -w rootdir
/media
/cdrom
-unmounted/dists
1048 local PROTO
="$(echo "$1" | cut -d':' -f 1 )"
1049 apthelper
-o Debug
::Acquire
::${PROTO}=1 \
1050 download
-file "$1" "$2" 2>&1 || true
1051 # only if the file exists the download was successful
1052 if [ -e "$2" ]; then
1060 local DIFFTEXT
="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1061 if [ -n "$DIFFTEXT" ]; then
1063 echo >&2 "$DIFFTEXT"
1073 msgtest
"Test for correctness of file" "$FILE"
1074 if [ -z "$*" ]; then
1075 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1077 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1082 msgtest
"Test for no output of" "$*"
1083 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1084 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1090 aptautotest
'testempty' "$@"
1094 local MSG
='Test of equality of'
1095 if [ "$1" = '--nomsg' ]; then
1100 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1101 echo "$1" > $COMPAREFILE
1104 if [ -n "$MSG" ]; then
1107 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1108 aptautotest
'testequal' "$@"
1112 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1113 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1114 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1115 echo "$1" > $COMPAREFILE1
1116 echo "$2" > $COMPAREFILE2
1118 msgtest
"Test for equality OR of" "$*"
1119 "$@" >$COMPAREAGAINST 2>&1 || true
1120 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1121 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1125 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1126 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1127 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1128 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1131 aptautotest
'testequalor2' "$@"
1135 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1138 while [ -n "$1" ]; do
1140 N: Can't select versions from package '$1' as it is purely virtual"
1141 PACKAGE
="${PACKAGE} $1"
1144 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1146 N: No packages found"
1147 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1148 local ARCH
="$(getarchitecture 'native')"
1149 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1150 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1154 msgtest
"Test for non-existent packages" "apt-cache show $*"
1155 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1156 if [ -n "$SHOWPKG" ]; then
1165 testdpkginstalled
() {
1166 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1167 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1168 if [ "$PKGS" != $# ]; then
1170 dpkg
-l "$@" | grep '^[a-z]' >&2
1177 testdpkgnotinstalled
() {
1178 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1179 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1180 if [ "$PKGS" != 0 ]; then
1182 dpkg
-l "$@" | grep '^[a-z]' >&2
1190 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1191 if [ -n "$1" ]; then
1192 msgtest
'Test for correctly marked as auto-installed' "$*"
1193 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1195 msgtest
'Test for correctly marked as auto-installed' 'no package'
1196 echo -n > $COMPAREFILE
1198 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1202 if [ "$1" = '--nomsg' ]; then
1205 msgtest
'Test for successful execution of' "$*"
1207 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1208 if "$@" >${OUTPUT} 2>&1; then
1209 if expr match
"$1" '^apt.*' >/dev
/null
; then
1210 if grep -q -E '^[WE]: ' "$OUTPUT"; then
1213 msgfail
'successful run, but output contains warnings/errors'
1224 msgfail
"exitcode $EXITCODE"
1226 aptautotest
'testsuccess' "$@"
1229 if [ "$1" = '--nomsg' ]; then
1232 msgtest
'Test for successful execution with warnings of' "$*"
1234 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1235 if "$@" >${OUTPUT} 2>&1; then
1236 if expr match
"$1" '^apt.*' >/dev
/null
; then
1237 if grep -q -E '^E: ' "$OUTPUT"; then
1240 msgfail
'successful run, but output contains errors'
1241 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1244 msgfail
'successful run, but output contains no warnings'
1255 msgfail
"exitcode $EXITCODE"
1257 aptautotest
'testwarning' "$@"
1260 if [ "$1" = '--nomsg' ]; then
1263 msgtest
'Test for failure in execution of' "$*"
1265 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1266 if "$@" >${OUTPUT} 2>&1; then
1270 msgfail
"exitcode $EXITCODE"
1273 if expr match
"$1" '^apt.*' >/dev
/null
; then
1274 if ! grep -q -E '^E: ' "$OUTPUT"; then
1277 msgfail
"run failed with exitcode ${EXITCODE}, but with no errors"
1285 aptautotest
'testfailure' "$@"
1289 msgtest
"Test that file $1 has $2 $3" "$4"
1290 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1295 echo -n >&2 "stat(1) reports for $2: "
1296 stat
--format "$2" "$1"
1300 testaccessrights
() {
1301 testfilestats
"$1" '%a' '=' "$2"
1304 testwebserverlaststatuscode
() {
1305 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1306 local STATUS
='rootdir/tmp/webserverstatus-statusfile.log'
1307 rm -f "$DOWNLOG" "$STATUS"
1308 msgtest
'Test last status code from the webserver was' "$1"
1309 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
1310 if [ "$(cat "$STATUS")" = "$1" ]; then
1314 if [ -n "$2" ]; then
1316 echo >&2 '#### Additionally provided output files contain:'
1319 echo >&2 '#### Download log of the status code:'
1321 msgfail
"Status was $(cat "$STATUS")"
1326 echo "STOPPED execution. Press enter to continue"
1331 listcurrentlistsdirectory
() {
1332 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1333 stat
--format '%U:%G:%a:%n' "$line"
1335 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1336 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1340 ### The following tests are run by most test methods automatically to check
1341 ### general things about commands executed without writing the test every time.
1347 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1348 if command -v $AUTOTEST >/dev
/null
; then
1350 # save and restore the *.output files from other tests
1351 # as we might otherwise override them in these automatic tests
1352 rm -rf rootdir
/tmp
-before
1353 mv rootdir
/tmp rootdir
/tmp
-before
1355 $AUTOTEST "$TESTCALL" "$@"
1356 rm -rf rootdir
/tmp
-aptautotest
1357 mv rootdir
/tmp rootdir
/tmp
-aptautotest
1358 mv rootdir
/tmp
-before rootdir
/tmp
1362 aptautotest_aptget_update
() {
1363 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1364 # all copied files are properly chmodded
1365 find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f
| while read file; do
1366 testfilestats
"$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
1369 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }