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}"; }
81 if [ $MSGLEVEL -le 3 ]; then
85 if [ $MSGLEVEL -le 4 ]; then
90 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
91 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
92 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
93 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
94 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
97 printf "${CDONE}DONE${CNORMAL}\n";
101 if [ -f .
/aptconfig.conf
]; then
102 echo "./aptconfig.conf"
103 elif [ -f ..
/aptconfig.conf
]; then
104 echo "../aptconfig.conf"
108 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
112 sh
|aptitude
|*/*|command) ;;
113 *) CMD
="${BUILDDIRECTORY}/$CMD";;
115 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${LIBRARYPATH} $CMD "$@"
117 aptconfig
() { runapt apt
-config "$@"; }
118 aptcache
() { runapt apt
-cache "$@"; }
119 aptcdrom
() { runapt apt
-cdrom "$@"; }
120 aptget
() { runapt apt
-get "$@"; }
121 aptftparchive
() { runapt apt
-ftparchive "$@"; }
122 aptkey
() { runapt apt
-key "$@"; }
123 aptmark
() { runapt apt
-mark "$@"; }
124 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
125 apt
() { runapt apt
"$@"; }
126 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
127 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
128 aptitude
() { runapt aptitude
"$@"; }
129 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
130 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
131 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
134 command dpkg
--root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
"$@"
136 dpkgcheckbuilddeps
() {
137 command dpkg
-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
"$@"
142 runapt
command gdb
--quiet -ex run
"${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
146 # error if we about to overflow, but ...
147 # "255 failures ought to be enough for everybody"
148 if [ $EXIT_CODE -gt 255 ]; then
149 msgdie
"Total failure count $EXIT_CODE too big"
151 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
154 shellsetedetector
() {
156 if [ "$exit_status" != '0' ]; then
157 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
158 if [ "$EXIT_CODE" = '0' ]; then
159 EXIT_CODE
="$exit_status"
165 if [ "$1" = 'prefix' ]; then
166 CURRENTTRAP
="$2 $CURRENTTRAP"
168 CURRENTTRAP
="$CURRENTTRAP $1"
170 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
174 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
175 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
178 TMPWORKINGDIRECTORY
=$(mktemp -d)
179 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
180 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
182 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
183 if [ "$(id -u)" = '0' ]; then
184 # relax permissions so that running as root with user switching works
186 chmod 711 "$TMPWORKINGDIRECTORY"
187 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
190 TESTDIRECTORY
=$(readlink -f $(dirname $0))
191 # allow overriding the default BUILDDIR location
192 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
193 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
194 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
195 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
196 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
197 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
198 APTDUMPSOLVER
=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}
199 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
202 cd $TMPWORKINGDIRECTORY
203 mkdir rootdir aptarchive keys
205 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
206 mkdir -p usr
/bin var
/cache var
/lib var
/log tmp
207 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
208 touch var
/lib
/dpkg
/available
210 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
211 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
212 mkdir -p usr
/lib
/apt
/solvers
213 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
214 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
215 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
217 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
219 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
220 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
222 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
225 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
226 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
227 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
229 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
230 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
231 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
233 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
234 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
235 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
237 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
238 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
239 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
240 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
241 # store apt-key were we can access it, even if we run it as a different user
242 # destroys coverage reporting though, so just do it for root for now
243 if [ "$(id -u)" = '0' ]; then
244 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
245 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
246 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
248 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
250 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
251 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
252 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
253 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
254 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
255 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
256 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
258 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
259 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
260 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
261 # too distracting for users, but helpful to detect changes
262 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
263 # in testcases, it can appear as if localhost has a rotation setup,
264 # hide this as we can't really deal with it properly
265 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
267 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
268 if [ "$(id -u)" = '0' ]; then
269 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
271 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
272 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
273 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
275 # Acquire::AllowInsecureRepositories=false is not yet the default
276 # but we want it to be the default soon
277 configallowinsecurerepositories
"false";
279 # cleanup the environment a bit
280 # prefer our apt binaries over the system apt binaries
281 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
282 export LC_ALL
=C.UTF
-8
283 unset LANGUAGE APT_CONFIG
284 unset GREP_OPTIONS DEB_BUILD_PROFILES
290 if [ "$1" = "native" -o -z "$1" ]; then
291 eval `aptconfig shell ARCH APT::Architecture`
292 if [ -n "$ARCH" ]; then
295 dpkg
--print-architecture
303 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
306 getarchitecturesfromcommalist
() {
307 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
310 configarchitecture
() {
312 echo "APT::Architecture \"$(getarchitecture $1)\";"
313 while [ -n "$1" ]; do
314 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
317 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
322 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
323 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
324 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
325 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
327 echo -n > rootdir/var/lib/dpkg/status
330 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
331 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
332 local ARCHS="$(getarchitectures)"
333 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
334 DPKGARCH="$(dpkg --print-architecture)"
335 for ARCH in ${ARCHS}; do
336 if [ "${ARCH}" != "${DPKGARCH}" ]; then
337 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
338 # old-style used e.g. in Ubuntu-P – and as it seems travis
339 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
340 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
344 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
345 # dpkg doesn't really check the version as long as it is fully installed,
346 # but just to be sure we choose one above the required version
347 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
353 configallowinsecurerepositories() {
354 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
358 configcompression() {
359 while [ -n "$1" ]; do
361 '.') printf ".
\t.
\tcat
\n";;
362 'gz') printf "gzip\tgz
\tgzip
\n";;
363 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
364 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
365 'xz') printf "xz
\txz
\txz
\n";;
366 *) printf "$1\t$1\t$1\n";;
369 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
376 gzip) COMPRESS='gz';;
377 bzip2) COMPRESS='bz2';;
378 lzma) COMPRESS='lzma';;
380 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
382 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
383 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
384 Dir::Bin::uncompressed \"/does/not/exist\";
385 Dir::Bin::gzip \"/does/not/exist\";
386 Dir::Bin::bzip2 \"/does/not/exist\";
387 Dir::Bin::lzma \"/does/not/exist\";
388 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
389 if [ -e "/bin/${COMPRESSOR}" ]; then
390 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
391 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
392 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
393 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
394 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
395 COMPRESSOR_CMD='xz
--format=lzma
'
397 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
402 setupsimplenativepackage() {
406 local RELEASE="${4:-unstable}"
407 local DEPENDENCIES="$5"
408 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
409 If you find such a package installed on your system,
410 something went horribly wrong! They are autogenerated
411 und used only by testcases and surf no other propose…"}"
413 local SECTION="${7:-others}"
415 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
418 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
420 local BUILDDIR=incoming/${NAME}-${VERSION}
421 mkdir -p ${BUILDDIR}/debian/source
423 echo "* most suckless software product ever" > FEATURES
424 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
425 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
429 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
430 test -e debian/control || echo "Source: $NAME
433 Maintainer: Joe Sixpack <joe@example.org>
434 Build-Depends: debhelper (>= 7)
435 Standards-Version: 3.9.1
437 Package: $NAME" > debian/control
438 if [ "$ARCH" = 'all
' ]; then
439 echo "Architecture: all" >> debian/control
441 echo "Architecture: any" >> debian/control
443 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
444 echo "Description: $DESCRIPTION" >> debian/control
446 test -e debian/compat || echo "7" > debian/compat
447 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
448 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
452 buildsimplenativepackage() {
456 local RELEASE="${4:-unstable}"
457 local DEPENDENCIES="$5"
458 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
459 If you find such a package installed on your system,
460 something went horribly wrong! They are autogenerated
461 und used only by testcases and surf no other propose…"}"
463 local SECTION="${7:-others}"
464 local PRIORITY="${8:-optional}"
466 local COMPRESS_TYPE="${10:-gzip}"
468 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
471 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
473 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
475 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
476 mkdir -p $BUILDDIR/debian/source
477 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
479 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
481 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
482 echo "$NAME ($VERSION) $RELEASE; urgency=low
486 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
490 Maintainer: Joe Sixpack <joe@example.org>
491 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
492 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
493 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
495 Package: $NAME" >> ${BUILDDIR}/debian/control
497 if [ "$ARCH" = 'all
' ]; then
498 echo "Architecture: all" >> ${BUILDDIR}/debian/control
500 echo "Architecture: any" >> ${BUILDDIR}/debian/control
502 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
503 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
504 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
506 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
507 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' \
509 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
510 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
511 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
512 # adv --yes --default-key 'Joe Sixpack' \
513 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
514 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
518 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
519 rm -rf ${BUILDDIR}/debian
/tmp
520 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
521 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
522 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
523 if [ -n "$FILE_TREE" ]; then
524 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
527 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
528 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
529 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
530 # ensure the right permissions as dpkg-deb ensists
531 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
532 if ! dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
537 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
540 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
541 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
542 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
551 local ARCH
=$(getarchitecture $4)
552 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
553 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
554 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
556 if [ "$ARCH" = "all" ]; then
557 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
559 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
563 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
564 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
567 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
570 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
576 if [ -d incoming
]; then
577 buildaptarchivefromincoming
"$@"
579 buildaptarchivefromfiles
"$@"
583 createaptftparchiveconfig
() {
584 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
585 COMPRESSORS
="${COMPRESSORS%* }"
586 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' ' ')"
587 if [ -z "$ARCHS" ]; then
588 # the pool is empty, so we will operate on faked packages - let us use the configured archs
589 ARCHS
="$(getarchitectures)"
592 ArchiveDir "' >> ftparchive.conf
593 echo -n $(readlink -f .) >> ftparchive.conf
595 CacheDir "' >> ftparchive.conf
596 echo -n $(readlink -f ..) >> ftparchive.conf
598 FileListDir "' >> ftparchive.conf
599 echo -n $(readlink -f pool/) >> ftparchive.conf
603 Packages::Compress "'"$COMPRESSORS"'";
604 Sources::Compress "'"$COMPRESSORS"'";
605 Contents::Compress "'"$COMPRESSORS"'";
606 Translation::Compress "'"$COMPRESSORS"'";
607 LongDescription "false";
611 SrcDirectory "pool/";
617 Label "apttestcases";
619 Description "repository with dummy packages";
620 Architectures "' >> ftparchive.conf
621 echo -n "$ARCHS" >> ftparchive.conf
625 };' >> ftparchive.conf
626 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
627 echo -n 'tree "dists/' >> ftparchive.conf
628 echo -n "$DIST" >> ftparchive.conf
630 Architectures "' >> ftparchive.conf
631 echo -n "$ARCHS" >> ftparchive.conf
633 FileList "' >> ftparchive.conf
634 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
636 SourceFileList "' >> ftparchive.conf
637 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
639 Sections "' >> ftparchive.conf
640 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
642 };' >> ftparchive.conf
646 buildaptftparchivedirectorystructure
() {
647 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
648 for DIST
in $DISTS; do
649 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
650 for SECTION
in $SECTIONS; do
651 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
652 for ARCH
in $ARCHS; do
653 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
655 mkdir -p dists
/${DIST}/${SECTION}/source
656 mkdir -p dists
/${DIST}/${SECTION}/i18n
666 local DEPENDENCIES
="$5"
667 local PRIORITY
="${6:-optional}"
668 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
669 If you find such a package installed on your system,
670 something went horribly wrong! They are autogenerated
671 und used only by testcases and surf no other propose…"}"
673 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
674 if [ "$RELEASE" = 'installed' ]; then
675 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
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
716 local DEPENDENCIES="$5"
718 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
720 local FILE="${SPATH}/Sources
"
724 Maintainer
: Joe Sixpack
<joe@example.org
>
725 Architecture
: $ARCH" >> $FILE
726 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
728 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
729 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
733 insertinstalledpackage() {
737 local DEPENDENCIES="$4"
738 local PRIORITY="${5:-optional}"
739 local STATUS="${6:-install ok installed}"
740 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
741 If you
find such a package installed on your system
,
742 something went horribly wrong
! They are autogenerated
743 und used only by testcases and surf no other propose…
"}"
745 local FILE
='rootdir/var/lib/dpkg/status'
746 local INFO
='rootdir/var/lib/dpkg/info'
747 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
753 Maintainer: Joe Sixpack <joe@example.org>
754 Version: $VERSION" >> $FILE
755 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
756 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
757 echo "Description: $DESCRIPTION" >> $FILE
759 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
760 echo -n > ${INFO}/${NAME}:${arch}.list
762 echo -n > ${INFO}/${NAME}.list
768 buildaptarchivefromincoming
() {
769 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
771 [ -e pool
] || ln -s ..
/incoming pool
772 [ -e ftparchive.conf
] || createaptftparchiveconfig
773 [ -e dists
] || buildaptftparchivedirectorystructure
774 msgninfo
"\tGenerate Packages, Sources and Contents files… "
775 aptftparchive
-qq generate ftparchive.conf
778 generatereleasefiles
"$@"
781 buildaptarchivefromfiles
() {
782 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
783 find aptarchive
-name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
784 msgninfo
"\t${line} file… "
785 compressfile
"$line" "$1"
788 generatereleasefiles
"$@"
792 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
793 if [ "$compressor" = '.' ]; then
799 cat "$1" | $command > "${1}.${extension}"
801 touch -d "$2" "${1}.${extension}"
806 # can be overridden by testcases for their pleasure
807 getcodenamefromsuite
() {
809 unstable
) echo 'sid';;
813 getreleaseversionfromsuite
() { true
; }
814 getlabelfromsuite
() { true
; }
816 generatereleasefiles
() {
817 # $1 is the Date header and $2 is the ValidUntil header to be set
818 # both should be given in notation date/touch can understand
819 msgninfo
"\tGenerate Release files… "
820 if [ -e aptarchive
/dists
]; then
821 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
822 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
823 local CODENAME
="$(getcodenamefromsuite $SUITE)"
824 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
825 local LABEL
="$(getlabelfromsuite $SUITE)"
826 if [ -n "$VERSION" ]; then
827 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
829 if [ -n "$LABEL" ]; then
830 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
832 aptftparchive
-qq release
$dir \
833 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
834 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
837 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
838 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
840 NotAutomatic: yes' $dir/Release
842 if [ -n "$1" -a "$1" != "now" ]; then
843 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
847 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
851 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
853 if [ -n "$1" -a "$1" != "now" ]; then
854 for release
in $(find ./aptarchive -name 'Release'); do
855 touch -d "$1" $release
861 setupdistsaptarchive
() {
862 local APTARCHIVE
=$(readlink -f ./aptarchive)
863 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
864 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
865 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
866 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
867 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
868 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
869 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
874 setupflataptarchive
() {
875 local APTARCHIVE
=$(readlink -f ./aptarchive)
876 if [ -f ${APTARCHIVE}/Packages
]; then
877 msgninfo
"\tadd deb sources.list line… "
878 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
881 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
883 if [ -f ${APTARCHIVE}/Sources
]; then
884 msgninfo
"\tadd deb-src sources.list line… "
885 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
888 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
894 if [ "$1" = '--no-update' ]; then
899 if [ -e aptarchive
/dists
]; then
904 signreleasefiles
'Joe Sixpack'
905 if [ "1" != "$NOUPDATE" ]; then
906 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
911 local SIGNER
="${1:-Joe Sixpack}"
912 local REPODIR
="${2:-aptarchive}"
913 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
914 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
915 msgninfo
"\tSign archive with $SIGNER key $KEY… "
916 local REXKEY
='keys/rexexpired'
917 local SECEXPIREBAK
="${REXKEY}.sec.bak"
918 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
919 if [ "${SIGNER}" = 'Rex Expired' ]; then
920 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
921 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
922 # therefore we 'temporary' make the key not expired and restore a backup after signing
923 cp ${REXKEY}.sec
$SECEXPIREBAK
924 cp ${REXKEY}.pub
$PUBEXPIREBAK
925 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
926 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
927 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
928 cp $SECUNEXPIRED ${REXKEY}.sec
929 cp $PUBUNEXPIRED ${REXKEY}.pub
931 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
935 cp ${REXKEY}.sec
$SECUNEXPIRED
936 cp ${REXKEY}.pub
$PUBUNEXPIRED
939 for RELEASE
in $(find ${REPODIR}/ -name Release); do
940 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
941 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
942 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
943 # we might have set a specific date for the Release file, so copy it
944 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
946 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
947 mv -f $SECEXPIREBAK ${REXKEY}.sec
948 mv -f $PUBEXPIREBAK ${REXKEY}.pub
955 if [ "$1" = '--no-check' ]; then
959 local DOWNLOG
='rootdir/tmp/download-testfile.log'
960 local STATUS
='downloaded/webserverconfig.status'
961 rm -f "$STATUS" "$DOWNLOG"
964 msgtest
"Set webserver config option '${1}' to" "$2"
965 URI
="http://localhost:8080/_config/set/${1}/${2}"
967 msgtest
'Clear webserver config option' "${1}"
968 URI
="http://localhost:8080/_config/clear/${1}"
970 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
973 cat "$DOWNLOG" "$STATUS" || true
976 $NOCHECK || testwebserverlaststatuscode
'200'
979 rewritesourceslist
() {
980 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
981 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
982 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
986 # wait for up to 10s for a pid file to appear to avoid possible race
987 # when a helper is started and dosn't write the PID quick enough
990 for i
in $(seq 10); do
991 if test -s "$PIDFILE"; then
996 msgdie
"waiting for $PIDFILE failed"
1000 changetowebserver
() {
1001 if [ "$1" != '--no-rewrite' ]; then
1002 rewritesourceslist
'http://localhost:8080/'
1006 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1008 local LOG
="webserver.log"
1009 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1013 waitforpidfile aptwebserver.pid
1014 local PID
="$(cat aptwebserver.pid)"
1015 if [ -z "$PID" ]; then
1016 msgdie
'Could not fork aptwebserver successfully'
1018 addtrap
"kill $PID;"
1021 msgdie
'You have to build aptwerbserver or install a webserver'
1025 changetohttpswebserver
() {
1026 if ! which stunnel4
>/dev
/null
; then
1027 msgdie
'You need to install stunnel4 for https testcases'
1029 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1030 changetowebserver
--no-rewrite "$@"
1032 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1033 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1039 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1040 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1041 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1042 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1043 if [ -z "$PID" ]; then
1044 msgdie
'Could not fork stunnel4 successfully'
1046 addtrap
'prefix' "kill ${PID};"
1047 rewritesourceslist
'https://localhost:4433/'
1051 mkdir -p rootdir
/media
/cdrom
/.disk
1052 local CD
="$(readlink -f rootdir/media/cdrom)"
1053 echo "acquire::cdrom::mount \"${CD}\";
1054 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1055 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1056 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1057 echo -n "$1" > ${CD}/.disk
/info
1058 if [ ! -d aptarchive
/dists
]; then
1059 msgdie
'Flat file archive cdroms can not be created currently'
1062 mv aptarchive
/dists
"$CD"
1063 ln -s "$(readlink -f ./incoming)" $CD/pool
1064 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1065 # start with an unmounted disk
1066 mv "${CD}" "${CD}-unmounted"
1067 # we don't want the disk to be modifiable
1068 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1069 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1073 local PROTO
="$(echo "$1" | cut -d':' -f 1 )"
1074 apthelper
-o Debug
::Acquire
::${PROTO}=1 \
1075 download
-file "$1" "$2" 2>&1 || true
1076 # only if the file exists the download was successful
1077 if [ -r "$2" ]; then
1085 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1086 if [ -n "$DIFFTEXT" ]; then
1088 echo >&2 "$DIFFTEXT"
1098 msgtest
"Test for correctness of file" "$FILE"
1099 if [ -z "$*" ]; then
1100 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1102 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1107 msgtest
"Test for no output of" "$*"
1108 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1109 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1116 aptautotest
'testempty' "$@"
1120 local MSG
='Test of equality of'
1121 if [ "$1" = '--nomsg' ]; then
1126 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1127 echo "$1" > $COMPAREFILE
1130 if [ -n "$MSG" ]; then
1133 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1134 aptautotest
'testequal' "$@"
1138 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1139 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1140 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1141 echo "$1" > $COMPAREFILE1
1142 echo "$2" > $COMPAREFILE2
1144 msgtest
"Test for equality OR of" "$*"
1145 "$@" >$COMPAREAGAINST 2>&1 || true
1146 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1147 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1151 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1152 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1153 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1154 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1157 aptautotest
'testequalor2' "$@"
1161 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1164 while [ -n "$1" ]; do
1166 N: Can't select versions from package '$1' as it is purely virtual"
1167 PACKAGE
="${PACKAGE} $1"
1170 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1172 N: No packages found"
1173 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1174 local ARCH
="$(getarchitecture 'native')"
1175 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1176 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1180 msgtest
"Test for non-existent packages" "apt-cache show $*"
1181 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1182 if [ -n "$SHOWPKG" ]; then
1191 testdpkginstalled
() {
1192 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1193 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1194 if [ "$PKGS" != $# ]; then
1196 dpkg
-l "$@" | grep '^[a-z]' >&2
1203 testdpkgnotinstalled
() {
1204 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1205 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1206 if [ "$PKGS" != 0 ]; then
1208 dpkg
-l "$@" | grep '^[a-z]' >&2
1216 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1217 if [ -n "$1" ]; then
1218 msgtest
'Test for correctly marked as auto-installed' "$*"
1219 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1221 msgtest
'Test for correctly marked as auto-installed' 'no package'
1222 echo -n > $COMPAREFILE
1224 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1232 if [ "$1" = 'grep' ]; then
1233 while [ -n "$2" ]; do shift; done
1234 echo "#### Complete file: $1 ####"
1235 cat >&2 "$1" || true
1236 echo '#### grep output ####'
1237 elif [ "$1" = 'test' ]; then
1238 # doesn't support ! or non-file flags
1239 msgfailoutputstatfile
() {
1240 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1241 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1242 echo "#### stat(2) of file: $2 ####"
1246 msgfailoutputstatfile
"$2" "$3"
1247 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1249 msgfailoutputstatfile
"$2" "$3"
1251 echo '#### test output ####'
1258 if [ "$1" = '--nomsg' ]; then
1261 msgtest
'Test for successful execution of' "$*"
1263 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1264 if "$@" >${OUTPUT} 2>&1; then
1265 if expr match
"$1" '^apt.*' >/dev
/null
; then
1266 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1267 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1268 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1269 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1278 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1280 aptautotest
'testsuccess' "$@"
1283 if [ "$1" = '--nomsg' ]; then
1286 msgtest
'Test for successful execution with warnings of' "$*"
1288 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1289 if "$@" >${OUTPUT} 2>&1; then
1290 if expr match
"$1" '^apt.*' >/dev
/null
; then
1291 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1292 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1293 elif grep -q -E '^E: ' "$OUTPUT"; then
1294 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1295 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1296 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1307 msgfail
"exitcode $EXITCODE"
1309 aptautotest
'testwarning' "$@"
1312 if [ "$1" = '--nomsg' ]; then
1315 msgtest
'Test for failure in execution of' "$*"
1317 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1318 if "$@" >${OUTPUT} 2>&1; then
1320 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1323 if expr match
"$1" '^apt.*' >/dev
/null
; then
1324 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1325 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1326 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1327 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1335 aptautotest
'testfailure' "$@"
1339 msgtest
"Test that file $1 has $2 $3" "$4"
1340 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1345 echo -n >&2 "stat(1) reports for $2: "
1346 stat
--format "$2" "$1"
1350 testaccessrights
() {
1351 testfilestats
"$1" '%a' '=' "$2"
1354 testwebserverlaststatuscode
() {
1355 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1356 local STATUS
='downloaded/webserverstatus-statusfile.log'
1357 rm -f "$DOWNLOG" "$STATUS"
1358 msgtest
'Test last status code from the webserver was' "$1"
1359 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1363 if [ -n "$2" ]; then
1365 echo >&2 '#### Additionally provided output files contain:'
1368 echo >&2 '#### Download log of the status code:'
1370 msgfail
"Status was $(cat "$STATUS")"
1375 echo "STOPPED execution. Press enter to continue"
1380 listcurrentlistsdirectory
() {
1381 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1382 stat
--format '%U:%G:%a:%n' "$line"
1384 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1385 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1389 ### convinience hacks ###
1391 # creating some directories by hand is a tedious task, so make it look simple
1392 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1393 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1394 # only the last directory created by mkdir is effected by the -m !
1395 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1396 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1397 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1398 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1399 if [ "$(id -u)" = '0' ]; then
1400 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1407 ### The following tests are run by most test methods automatically to check
1408 ### general things about commands executed without writing the test every time.
1414 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1415 if command -v $AUTOTEST >/dev
/null
; then
1417 # save and restore the *.output files from other tests
1418 # as we might otherwise override them in these automatic tests
1419 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1420 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1421 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1422 $AUTOTEST "$TESTCALL" "$@"
1423 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1424 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1425 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1429 aptautotest_aptget_update
() {
1430 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1431 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${USER}:${USER}:755"
1432 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${USER}:${USER}:755"
1433 # all copied files are properly chmodded
1434 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f ! -name 'lock'); do
1435 testfilestats
"$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
1438 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }