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\([cfghs]\)#apt-\1#')"
41 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
42 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
43 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
44 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
45 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
46 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
47 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
48 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
49 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
50 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
51 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
52 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
54 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
55 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
58 if [ $# -gt 0 ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
59 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
60 if [ -n "$APT_DEBUG_TESTS" ]; then
63 EXIT_CODE
=$((EXIT_CODE+1));
66 # enable / disable Debugging
67 MSGLEVEL
=${MSGLEVEL:-3}
68 if [ $MSGLEVEL -le 0 ]; then
71 if [ $MSGLEVEL -le 1 ]; then
75 if [ $MSGLEVEL -le 2 ]; then
79 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
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 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
188 if [ "$(id -u)" = '0' ]; then
189 # relax permissions so that running as root with user switching works
191 chmod 711 "$TMPWORKINGDIRECTORY"
192 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
195 TESTDIRECTORY
=$(readlink -f $(dirname $0))
196 # allow overriding the default BUILDDIR location
197 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
198 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
199 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
200 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
201 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
202 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
203 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
206 cd $TMPWORKINGDIRECTORY
207 mkdir rootdir aptarchive keys
209 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
210 mkdir -p usr
/bin var
/cache var
/lib
/apt var
/log tmp
211 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
212 touch var
/lib
/dpkg
/available
214 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
215 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
216 mkdir -p usr
/lib
/apt
/solvers
217 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
218 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
219 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
221 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
223 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
224 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
226 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
229 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
230 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
231 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
233 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
234 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
235 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
237 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
238 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
239 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
241 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
242 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
243 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
244 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
245 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
246 # store apt-key were we can access it, even if we run it as a different user
247 # destroys coverage reporting though, so just do it for root for now
248 if [ "$(id -u)" = '0' ]; then
249 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
250 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
251 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
253 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
255 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
256 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
257 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
258 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
259 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
260 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
261 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
263 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
264 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
265 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
266 # too distracting for users, but helpful to detect changes
267 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
268 # in testcases, it can appear as if localhost has a rotation setup,
269 # hide this as we can't really deal with it properly
270 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
272 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
273 if [ "$(id -u)" = '0' ]; then
274 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
276 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
277 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
278 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
280 # Acquire::AllowInsecureRepositories=false is not yet the default
281 # but we want it to be the default soon
282 configallowinsecurerepositories
"false";
284 # cleanup the environment a bit
285 # prefer our apt binaries over the system apt binaries
286 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
287 export LC_ALL
=C.UTF
-8
288 unset LANGUAGE APT_CONFIG
289 unset GREP_OPTIONS DEB_BUILD_PROFILES
295 if [ "$1" = "native" -o -z "$1" ]; then
296 eval `aptconfig shell ARCH APT::Architecture`
297 if [ -n "$ARCH" ]; then
300 dpkg
--print-architecture
308 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
311 getarchitecturesfromcommalist
() {
312 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
315 configarchitecture
() {
317 echo "APT::Architecture \"$(getarchitecture $1)\";"
318 while [ -n "$1" ]; do
319 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
322 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
327 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
328 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
329 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
330 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
332 echo -n > rootdir/var/lib/dpkg/status
335 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
336 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
337 local ARCHS="$(getarchitectures)"
338 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
339 DPKGARCH="$(dpkg --print-architecture)"
340 for ARCH in ${ARCHS}; do
341 if [ "${ARCH}" != "${DPKGARCH}" ]; then
342 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
343 # old-style used e.g. in Ubuntu-P – and as it seems travis
344 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
345 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
349 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
350 # dpkg doesn't really check the version as long as it is fully installed,
351 # but just to be sure we choose one above the required version
352 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
358 configallowinsecurerepositories() {
359 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
363 configcompression() {
364 while [ -n "$1" ]; do
366 '.') printf ".
\t.
\tcat
\n";;
367 'gz') printf "gzip\tgz
\tgzip
\n";;
368 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
369 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
370 'xz') printf "xz
\txz
\txz
\n";;
371 *) printf "$1\t$1\t$1\n";;
374 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
381 gzip) COMPRESS='gz';;
382 bzip2) COMPRESS='bz2';;
383 lzma) COMPRESS='lzma';;
385 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
387 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
388 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
389 Dir::Bin::uncompressed \"/does/not/exist\";
390 Dir::Bin::gzip \"/does/not/exist\";
391 Dir::Bin::bzip2 \"/does/not/exist\";
392 Dir::Bin::lzma \"/does/not/exist\";
393 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
394 if [ -e "/bin/${COMPRESSOR}" ]; then
395 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
396 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
397 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
398 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
399 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
400 COMPRESSOR_CMD='xz
--format=lzma
'
402 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
407 setupsimplenativepackage() {
411 local RELEASE="${4:-unstable}"
412 local DEPENDENCIES="$5"
413 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
414 If you find such a package installed on your system,
415 something went horribly wrong! They are autogenerated
416 und used only by testcases and surf no other propose…"}"
418 local SECTION="${7:-others}"
420 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
423 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
425 local BUILDDIR=incoming/${NAME}-${VERSION}
426 mkdir -p ${BUILDDIR}/debian/source
428 echo "* most suckless software product ever" > FEATURES
429 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
430 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
434 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
435 test -e debian/control || echo "Source: $NAME
438 Maintainer: Joe Sixpack <joe@example.org>
439 Build-Depends: debhelper (>= 7)
440 Standards-Version: 3.9.1
442 Package: $NAME" > debian/control
443 if [ "$ARCH" = 'all
' ]; then
444 echo "Architecture: all" >> debian/control
446 echo "Architecture: any" >> debian/control
448 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
449 echo "Description: $DESCRIPTION" >> debian/control
451 test -e debian/compat || echo "7" > debian/compat
452 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
453 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
457 buildsimplenativepackage() {
461 local RELEASE="${4:-unstable}"
462 local DEPENDENCIES="$5"
463 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
464 If you find such a package installed on your system,
465 something went horribly wrong! They are autogenerated
466 und used only by testcases and surf no other propose…"}"
468 local SECTION="${7:-others}"
469 local PRIORITY="${8:-optional}"
471 local COMPRESS_TYPE="${10:-gzip}"
473 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
476 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
478 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
480 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
481 mkdir -p $BUILDDIR/debian/source
482 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
484 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
486 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
487 echo "$NAME ($VERSION) $RELEASE; urgency=low
491 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
495 Maintainer: Joe Sixpack <joe@example.org>
496 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
497 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
498 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
500 Package: $NAME" >> ${BUILDDIR}/debian/control
502 if [ "$ARCH" = 'all
' ]; then
503 echo "Architecture: all" >> ${BUILDDIR}/debian/control
505 echo "Architecture: any" >> ${BUILDDIR}/debian/control
507 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
508 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
509 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
511 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
512 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' \
514 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
515 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
516 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
517 # adv --yes --default-key 'Joe Sixpack' \
518 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
519 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
523 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
524 rm -rf ${BUILDDIR}/debian
/tmp
525 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
526 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
527 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
528 if [ -n "$FILE_TREE" ]; then
529 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
532 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
533 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
534 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
535 # ensure the right permissions as dpkg-deb ensists
536 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
537 if ! dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
542 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
545 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
546 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
547 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
556 local ARCH
=$(getarchitecture $4)
557 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
558 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
559 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
561 if [ "$ARCH" = "all" ]; then
562 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
564 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
568 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
569 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
572 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
575 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
581 if [ -d incoming
]; then
582 buildaptarchivefromincoming
"$@"
584 buildaptarchivefromfiles
"$@"
588 createaptftparchiveconfig
() {
589 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
590 COMPRESSORS
="${COMPRESSORS%* }"
591 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' ' ')"
592 if [ -z "$ARCHS" ]; then
593 # the pool is empty, so we will operate on faked packages - let us use the configured archs
594 ARCHS
="$(getarchitectures)"
597 ArchiveDir "' >> ftparchive.conf
598 echo -n $(readlink -f .) >> ftparchive.conf
600 CacheDir "' >> ftparchive.conf
601 echo -n $(readlink -f ..) >> ftparchive.conf
603 FileListDir "' >> ftparchive.conf
604 echo -n $(readlink -f pool/) >> ftparchive.conf
608 Packages::Compress "'"$COMPRESSORS"'";
609 Sources::Compress "'"$COMPRESSORS"'";
610 Contents::Compress "'"$COMPRESSORS"'";
611 Translation::Compress "'"$COMPRESSORS"'";
612 LongDescription "false";
616 SrcDirectory "pool/";
622 Label "apttestcases";
624 Description "repository with dummy packages";
625 Architectures "' >> ftparchive.conf
626 echo -n "$ARCHS" >> ftparchive.conf
630 };' >> ftparchive.conf
631 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
632 echo -n 'tree "dists/' >> ftparchive.conf
633 echo -n "$DIST" >> ftparchive.conf
635 Architectures "' >> ftparchive.conf
636 echo -n "$ARCHS" >> ftparchive.conf
638 FileList "' >> ftparchive.conf
639 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
641 SourceFileList "' >> ftparchive.conf
642 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
644 Sections "' >> ftparchive.conf
645 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
647 };' >> ftparchive.conf
651 buildaptftparchivedirectorystructure
() {
652 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
653 for DIST
in $DISTS; do
654 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
655 for SECTION
in $SECTIONS; do
656 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
657 for ARCH
in $ARCHS; do
658 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
660 mkdir -p dists
/${DIST}/${SECTION}/source
661 mkdir -p dists
/${DIST}/${SECTION}/i18n
671 local DEPENDENCIES
="$5"
672 local PRIORITY
="${6:-optional}"
673 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
674 If you find such a package installed on your system,
675 something went horribly wrong! They are autogenerated
676 und used only by testcases and surf no other propose…"}"
678 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
679 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
680 ARCHS="$(getarchitectures)"
684 for BUILDARCH in $ARCHS; do
685 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
687 local FILE="${PPATH}/Packages
"
692 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
693 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
694 echo "Version
: $VERSION
695 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
696 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
697 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
698 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
702 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
703 touch aptarchive/dists/${RELEASE}/main/source/Sources
705 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
706 Description
-en: $DESCRIPTION
707 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
715 local DEPENDENCIES="$5"
717 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
719 local FILE="${SPATH}/Sources
"
723 Maintainer
: Joe Sixpack
<joe@example.org
>
724 Architecture
: $ARCH" >> $FILE
725 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
727 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
728 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
732 insertinstalledpackage() {
736 local DEPENDENCIES="$4"
737 local PRIORITY="${5:-optional}"
738 local STATUS="${6:-install ok installed}"
739 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
740 If you
find such a package installed on your system
,
741 something went horribly wrong
! They are autogenerated
742 und used only by testcases and surf no other propose…
"}"
744 local FILE
='rootdir/var/lib/dpkg/status'
745 local INFO
='rootdir/var/lib/dpkg/info'
746 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
752 Maintainer: Joe Sixpack <joe@example.org>
753 Version: $VERSION" >> $FILE
754 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
755 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
756 echo "Description: $DESCRIPTION" >> $FILE
758 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
759 echo -n > ${INFO}/${NAME}:${arch}.list
761 echo -n > ${INFO}/${NAME}.list
767 buildaptarchivefromincoming
() {
768 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
770 [ -e pool
] || ln -s ..
/incoming pool
771 [ -e ftparchive.conf
] || createaptftparchiveconfig
772 [ -e dists
] || buildaptftparchivedirectorystructure
773 msgninfo
"\tGenerate Packages, Sources and Contents files… "
774 aptftparchive
-qq generate ftparchive.conf
777 generatereleasefiles
"$@"
780 buildaptarchivefromfiles
() {
781 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
782 find aptarchive
-name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
783 msgninfo
"\t${line} file… "
784 compressfile
"$line" "$1"
787 generatereleasefiles
"$@"
791 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
792 if [ "$compressor" = '.' ]; then
798 cat "$1" | $command > "${1}.${extension}"
800 touch -d "$2" "${1}.${extension}"
805 # can be overridden by testcases for their pleasure
806 getcodenamefromsuite
() {
808 unstable
) echo 'sid';;
812 getreleaseversionfromsuite
() { true
; }
813 getlabelfromsuite
() { true
; }
815 generatereleasefiles
() {
816 # $1 is the Date header and $2 is the ValidUntil header to be set
817 # both should be given in notation date/touch can understand
818 msgninfo
"\tGenerate Release files… "
819 if [ -e aptarchive
/dists
]; then
820 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
821 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
822 local CODENAME
="$(getcodenamefromsuite $SUITE)"
823 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
824 local LABEL
="$(getlabelfromsuite $SUITE)"
825 if [ -n "$VERSION" ]; then
826 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
828 if [ -n "$LABEL" ]; then
829 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
831 aptftparchive
-qq release
$dir \
832 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
833 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
836 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
837 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
839 NotAutomatic: yes' $dir/Release
841 if [ -n "$1" -a "$1" != "now" ]; then
842 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
846 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
850 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
852 if [ -n "$1" -a "$1" != "now" ]; then
853 for release
in $(find ./aptarchive -name 'Release'); do
854 touch -d "$1" $release
860 setupdistsaptarchive
() {
861 local APTARCHIVE
=$(readlink -f ./aptarchive)
862 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
863 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
864 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
865 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
866 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
867 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
868 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
873 setupflataptarchive
() {
874 local APTARCHIVE
=$(readlink -f ./aptarchive)
875 if [ -f ${APTARCHIVE}/Packages
]; then
876 msgninfo
"\tadd deb sources.list line… "
877 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
880 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
882 if [ -f ${APTARCHIVE}/Sources
]; then
883 msgninfo
"\tadd deb-src sources.list line… "
884 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
887 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
893 if [ "$1" = '--no-update' ]; then
898 if [ -e aptarchive
/dists
]; then
903 signreleasefiles
'Joe Sixpack'
904 if [ "1" != "$NOUPDATE" ]; then
905 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
910 local SIGNER
="${1:-Joe Sixpack}"
911 local REPODIR
="${2:-aptarchive}"
912 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
913 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
914 msgninfo
"\tSign archive with $SIGNER key $KEY… "
915 local REXKEY
='keys/rexexpired'
916 local SECEXPIREBAK
="${REXKEY}.sec.bak"
917 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
918 if [ "${SIGNER}" = 'Rex Expired' ]; then
919 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
920 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
921 # therefore we 'temporary' make the key not expired and restore a backup after signing
922 cp ${REXKEY}.sec
$SECEXPIREBAK
923 cp ${REXKEY}.pub
$PUBEXPIREBAK
924 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
925 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
926 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
927 cp $SECUNEXPIRED ${REXKEY}.sec
928 cp $PUBUNEXPIRED ${REXKEY}.pub
930 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
934 cp ${REXKEY}.sec
$SECUNEXPIRED
935 cp ${REXKEY}.pub
$PUBUNEXPIRED
938 for RELEASE
in $(find ${REPODIR}/ -name Release); do
939 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
940 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
941 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
942 # we might have set a specific date for the Release file, so copy it
943 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
945 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
946 mv -f $SECEXPIREBAK ${REXKEY}.sec
947 mv -f $PUBEXPIREBAK ${REXKEY}.pub
954 if [ "$1" = '--no-check' ]; then
958 local DOWNLOG
='rootdir/tmp/download-testfile.log'
959 local STATUS
='downloaded/webserverconfig.status'
960 rm -f "$STATUS" "$DOWNLOG"
963 msgtest
"Set webserver config option '${1}' to" "$2"
964 URI
="http://localhost:8080/_config/set/${1}/${2}"
966 msgtest
'Clear webserver config option' "${1}"
967 URI
="http://localhost:8080/_config/clear/${1}"
969 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
972 cat "$DOWNLOG" "$STATUS" || true
975 $NOCHECK || testwebserverlaststatuscode
'200'
978 rewritesourceslist
() {
979 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
980 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
981 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
985 # wait for up to 10s for a pid file to appear to avoid possible race
986 # when a helper is started and dosn't write the PID quick enough
989 for i
in $(seq 10); do
990 if test -s "$PIDFILE"; then
995 msgdie
"waiting for $PIDFILE failed"
999 changetowebserver
() {
1000 if [ "$1" != '--no-rewrite' ]; then
1001 rewritesourceslist
'http://localhost:8080/'
1005 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1007 local LOG
="webserver.log"
1008 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1012 waitforpidfile aptwebserver.pid
1013 local PID
="$(cat aptwebserver.pid)"
1014 if [ -z "$PID" ]; then
1015 msgdie
'Could not fork aptwebserver successfully'
1017 addtrap
"kill $PID;"
1020 msgdie
'You have to build aptwerbserver or install a webserver'
1024 changetohttpswebserver
() {
1025 if ! which stunnel4
>/dev
/null
; then
1026 msgdie
'You need to install stunnel4 for https testcases'
1028 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1029 changetowebserver
--no-rewrite "$@"
1031 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1032 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1038 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1039 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1040 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1041 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1042 if [ -z "$PID" ]; then
1043 msgdie
'Could not fork stunnel4 successfully'
1045 addtrap
'prefix' "kill ${PID};"
1046 rewritesourceslist
'https://localhost:4433/'
1050 mkdir -p rootdir
/media
/cdrom
/.disk
1051 local CD
="$(readlink -f rootdir/media/cdrom)"
1052 echo "acquire::cdrom::mount \"${CD}\";
1053 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1054 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1055 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1056 echo -n "$1" > ${CD}/.disk
/info
1057 if [ ! -d aptarchive
/dists
]; then
1058 msgdie
'Flat file archive cdroms can not be created currently'
1061 mv aptarchive
/dists
"$CD"
1062 ln -s "$(readlink -f ./incoming)" $CD/pool
1063 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1064 # start with an unmounted disk
1065 mv "${CD}" "${CD}-unmounted"
1066 # we don't want the disk to be modifiable
1067 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1068 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1072 local PROTO
="$(echo "$1" | cut -d':' -f 1 )"
1073 apthelper
-o Debug
::Acquire
::${PROTO}=1 \
1074 download
-file "$1" "$2" 2>&1 || true
1075 # only if the file exists the download was successful
1076 if [ -r "$2" ]; then
1084 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1085 if [ -n "$DIFFTEXT" ]; then
1087 echo >&2 "$DIFFTEXT"
1097 msgtest
"Test for correctness of file" "$FILE"
1098 if [ -z "$*" ]; then
1099 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1101 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1106 msgtest
"Test for no output of" "$*"
1107 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1108 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1114 aptautotest
'testempty' "$@"
1118 local MSG
='Test of equality of'
1119 if [ "$1" = '--nomsg' ]; then
1124 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1125 echo "$1" > $COMPAREFILE
1128 if [ -n "$MSG" ]; then
1131 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1132 aptautotest
'testequal' "$@"
1136 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1137 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1138 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1139 echo "$1" > $COMPAREFILE1
1140 echo "$2" > $COMPAREFILE2
1142 msgtest
"Test for equality OR of" "$*"
1143 "$@" >$COMPAREAGAINST 2>&1 || true
1144 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1145 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1149 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1150 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1151 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1152 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1155 aptautotest
'testequalor2' "$@"
1159 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1162 while [ -n "$1" ]; do
1164 N: Can't select versions from package '$1' as it is purely virtual"
1165 PACKAGE
="${PACKAGE} $1"
1168 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1170 N: No packages found"
1171 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1172 local ARCH
="$(getarchitecture 'native')"
1173 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1174 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1178 msgtest
"Test for non-existent packages" "apt-cache show $*"
1179 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1180 if [ -n "$SHOWPKG" ]; then
1189 testdpkginstalled
() {
1190 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1191 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1192 if [ "$PKGS" != $# ]; then
1194 dpkg
-l "$@" | grep '^[a-z]' >&2
1201 testdpkgnotinstalled
() {
1202 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1203 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1204 if [ "$PKGS" != 0 ]; then
1206 dpkg
-l "$@" | grep '^[a-z]' >&2
1214 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1215 if [ -n "$1" ]; then
1216 msgtest
'Test for correctly marked as auto-installed' "$*"
1217 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1219 msgtest
'Test for correctly marked as auto-installed' 'no package'
1220 echo -n > $COMPAREFILE
1222 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1226 if [ "$1" = '--nomsg' ]; then
1229 msgtest
'Test for successful execution of' "$*"
1231 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1232 if "$@" >${OUTPUT} 2>&1; then
1233 if expr match
"$1" '^apt.*' >/dev
/null
; then
1234 if grep -q -E '^[WE]: ' "$OUTPUT"; then
1237 msgfail
'successful run, but output contains warnings/errors'
1248 msgfail
"exitcode $EXITCODE"
1250 aptautotest
'testsuccess' "$@"
1253 if [ "$1" = '--nomsg' ]; then
1256 msgtest
'Test for successful execution with warnings of' "$*"
1258 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1259 if "$@" >${OUTPUT} 2>&1; then
1260 if expr match
"$1" '^apt.*' >/dev
/null
; then
1261 if grep -q -E '^E: ' "$OUTPUT"; then
1264 msgfail
'successful run, but output contains errors'
1265 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1268 msgfail
'successful run, but output contains no warnings'
1279 msgfail
"exitcode $EXITCODE"
1281 aptautotest
'testwarning' "$@"
1284 if [ "$1" = '--nomsg' ]; then
1287 msgtest
'Test for failure in execution of' "$*"
1289 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1290 if "$@" >${OUTPUT} 2>&1; then
1294 msgfail
"exitcode $EXITCODE"
1297 if expr match
"$1" '^apt.*' >/dev
/null
; then
1298 if ! grep -q -E '^E: ' "$OUTPUT"; then
1301 msgfail
"run failed with exitcode ${EXITCODE}, but with no errors"
1309 aptautotest
'testfailure' "$@"
1313 msgtest
"Test that file $1 has $2 $3" "$4"
1314 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1319 echo -n >&2 "stat(1) reports for $2: "
1320 stat
--format "$2" "$1"
1324 testaccessrights
() {
1325 testfilestats
"$1" '%a' '=' "$2"
1328 testwebserverlaststatuscode
() {
1329 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1330 local STATUS
='downloaded/webserverstatus-statusfile.log'
1331 rm -f "$DOWNLOG" "$STATUS"
1332 msgtest
'Test last status code from the webserver was' "$1"
1333 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1337 if [ -n "$2" ]; then
1339 echo >&2 '#### Additionally provided output files contain:'
1342 echo >&2 '#### Download log of the status code:'
1344 msgfail
"Status was $(cat "$STATUS")"
1349 echo "STOPPED execution. Press enter to continue"
1354 listcurrentlistsdirectory
() {
1355 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1356 stat
--format '%U:%G:%a:%n' "$line"
1358 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1359 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1363 ### The following tests are run by most test methods automatically to check
1364 ### general things about commands executed without writing the test every time.
1370 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1371 if command -v $AUTOTEST >/dev
/null
; then
1373 # save and restore the *.output files from other tests
1374 # as we might otherwise override them in these automatic tests
1375 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1376 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1377 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1378 $AUTOTEST "$TESTCALL" "$@"
1379 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1380 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1381 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1385 aptautotest_aptget_update
() {
1386 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1387 # all copied files are properly chmodded
1388 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f); do
1389 testfilestats
"$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
1392 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }