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
/apt 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 "Debug::NoLocking \"true\";" >> aptconfig.conf
240 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
241 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
242 # store apt-key were we can access it, even if we run it as a different user
243 # destroys coverage reporting though, so just do it for root for now
244 if [ "$(id -u)" = '0' ]; then
245 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
246 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
247 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
249 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
251 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
252 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
253 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
254 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
255 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
256 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
257 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
259 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
260 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
261 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
262 # too distracting for users, but helpful to detect changes
263 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
264 # in testcases, it can appear as if localhost has a rotation setup,
265 # hide this as we can't really deal with it properly
266 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
268 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
269 if [ "$(id -u)" = '0' ]; then
270 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
272 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
273 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
274 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
276 # Acquire::AllowInsecureRepositories=false is not yet the default
277 # but we want it to be the default soon
278 configallowinsecurerepositories
"false";
280 # cleanup the environment a bit
281 # prefer our apt binaries over the system apt binaries
282 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
283 export LC_ALL
=C.UTF
-8
284 unset LANGUAGE APT_CONFIG
285 unset GREP_OPTIONS DEB_BUILD_PROFILES
291 if [ "$1" = "native" -o -z "$1" ]; then
292 eval `aptconfig shell ARCH APT::Architecture`
293 if [ -n "$ARCH" ]; then
296 dpkg
--print-architecture
304 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
307 getarchitecturesfromcommalist
() {
308 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
311 configarchitecture
() {
313 echo "APT::Architecture \"$(getarchitecture $1)\";"
314 while [ -n "$1" ]; do
315 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
318 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
323 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
324 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
325 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
326 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
328 echo -n > rootdir/var/lib/dpkg/status
331 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
332 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
333 local ARCHS="$(getarchitectures)"
334 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
335 DPKGARCH="$(dpkg --print-architecture)"
336 for ARCH in ${ARCHS}; do
337 if [ "${ARCH}" != "${DPKGARCH}" ]; then
338 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
339 # old-style used e.g. in Ubuntu-P – and as it seems travis
340 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
341 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
345 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
346 # dpkg doesn't really check the version as long as it is fully installed,
347 # but just to be sure we choose one above the required version
348 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
354 configallowinsecurerepositories() {
355 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
359 configcompression() {
360 while [ -n "$1" ]; do
362 '.') printf ".
\t.
\tcat
\n";;
363 'gz') printf "gzip\tgz
\tgzip
\n";;
364 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
365 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
366 'xz') printf "xz
\txz
\txz
\n";;
367 *) printf "$1\t$1\t$1\n";;
370 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
377 gzip) COMPRESS='gz';;
378 bzip2) COMPRESS='bz2';;
379 lzma) COMPRESS='lzma';;
381 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
383 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
384 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
385 Dir::Bin::uncompressed \"/does/not/exist\";
386 Dir::Bin::gzip \"/does/not/exist\";
387 Dir::Bin::bzip2 \"/does/not/exist\";
388 Dir::Bin::lzma \"/does/not/exist\";
389 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
390 if [ -e "/bin/${COMPRESSOR}" ]; then
391 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
392 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
393 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
394 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
395 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
396 COMPRESSOR_CMD='xz
--format=lzma
'
398 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
403 setupsimplenativepackage() {
407 local RELEASE="${4:-unstable}"
408 local DEPENDENCIES="$5"
409 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
410 If you find such a package installed on your system,
411 something went horribly wrong! They are autogenerated
412 und used only by testcases and surf no other propose…"}"
414 local SECTION="${7:-others}"
416 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
419 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
421 local BUILDDIR=incoming/${NAME}-${VERSION}
422 mkdir -p ${BUILDDIR}/debian/source
424 echo "* most suckless software product ever" > FEATURES
425 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
426 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
430 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
431 test -e debian/control || echo "Source: $NAME
434 Maintainer: Joe Sixpack <joe@example.org>
435 Build-Depends: debhelper (>= 7)
436 Standards-Version: 3.9.1
438 Package: $NAME" > debian/control
439 if [ "$ARCH" = 'all
' ]; then
440 echo "Architecture: all" >> debian/control
442 echo "Architecture: any" >> debian/control
444 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
445 echo "Description: $DESCRIPTION" >> debian/control
447 test -e debian/compat || echo "7" > debian/compat
448 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
449 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
453 buildsimplenativepackage() {
457 local RELEASE="${4:-unstable}"
458 local DEPENDENCIES="$5"
459 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
460 If you find such a package installed on your system,
461 something went horribly wrong! They are autogenerated
462 und used only by testcases and surf no other propose…"}"
464 local SECTION="${7:-others}"
465 local PRIORITY="${8:-optional}"
467 local COMPRESS_TYPE="${10:-gzip}"
469 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
472 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
474 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
476 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
477 mkdir -p $BUILDDIR/debian/source
478 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
480 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
482 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
483 echo "$NAME ($VERSION) $RELEASE; urgency=low
487 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
491 Maintainer: Joe Sixpack <joe@example.org>
492 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
493 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
494 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
496 Package: $NAME" >> ${BUILDDIR}/debian/control
498 if [ "$ARCH" = 'all
' ]; then
499 echo "Architecture: all" >> ${BUILDDIR}/debian/control
501 echo "Architecture: any" >> ${BUILDDIR}/debian/control
503 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
504 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
505 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
507 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
508 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' \
510 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
511 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
512 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
513 # adv --yes --default-key 'Joe Sixpack' \
514 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
515 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
519 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
520 rm -rf ${BUILDDIR}/debian
/tmp
521 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
522 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
523 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
524 if [ -n "$FILE_TREE" ]; then
525 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
528 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
529 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
530 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
531 # ensure the right permissions as dpkg-deb ensists
532 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
533 if ! dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
538 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
541 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
542 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
543 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
552 local ARCH
=$(getarchitecture $4)
553 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
554 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
555 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
557 if [ "$ARCH" = "all" ]; then
558 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
560 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
564 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
565 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
568 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
571 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
577 if [ -d incoming
]; then
578 buildaptarchivefromincoming
"$@"
580 buildaptarchivefromfiles
"$@"
584 createaptftparchiveconfig
() {
585 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
586 COMPRESSORS
="${COMPRESSORS%* }"
587 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' ' ')"
588 if [ -z "$ARCHS" ]; then
589 # the pool is empty, so we will operate on faked packages - let us use the configured archs
590 ARCHS
="$(getarchitectures)"
593 ArchiveDir "' >> ftparchive.conf
594 echo -n $(readlink -f .) >> ftparchive.conf
596 CacheDir "' >> ftparchive.conf
597 echo -n $(readlink -f ..) >> ftparchive.conf
599 FileListDir "' >> ftparchive.conf
600 echo -n $(readlink -f pool/) >> ftparchive.conf
604 Packages::Compress "'"$COMPRESSORS"'";
605 Sources::Compress "'"$COMPRESSORS"'";
606 Contents::Compress "'"$COMPRESSORS"'";
607 Translation::Compress "'"$COMPRESSORS"'";
608 LongDescription "false";
612 SrcDirectory "pool/";
618 Label "apttestcases";
620 Description "repository with dummy packages";
621 Architectures "' >> ftparchive.conf
622 echo -n "$ARCHS" >> ftparchive.conf
626 };' >> ftparchive.conf
627 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
628 echo -n 'tree "dists/' >> ftparchive.conf
629 echo -n "$DIST" >> ftparchive.conf
631 Architectures "' >> ftparchive.conf
632 echo -n "$ARCHS" >> ftparchive.conf
634 FileList "' >> ftparchive.conf
635 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
637 SourceFileList "' >> ftparchive.conf
638 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
640 Sections "' >> ftparchive.conf
641 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
643 };' >> ftparchive.conf
647 buildaptftparchivedirectorystructure
() {
648 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
649 for DIST
in $DISTS; do
650 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
651 for SECTION
in $SECTIONS; do
652 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
653 for ARCH
in $ARCHS; do
654 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
656 mkdir -p dists
/${DIST}/${SECTION}/source
657 mkdir -p dists
/${DIST}/${SECTION}/i18n
667 local DEPENDENCIES
="$5"
668 local PRIORITY
="${6:-optional}"
669 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
670 If you find such a package installed on your system,
671 something went horribly wrong! They are autogenerated
672 und used only by testcases and surf no other propose…"}"
674 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
675 if [ "$RELEASE" = 'installed' ]; then
676 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
679 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
680 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
681 ARCHS="$(getarchitectures)"
685 for BUILDARCH in $ARCHS; do
686 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
688 local FILE="${PPATH}/Packages
"
693 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
694 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
695 echo "Version
: $VERSION
696 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
697 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
698 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
699 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
703 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
704 touch aptarchive/dists/${RELEASE}/main/source/Sources
706 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
707 Description
-en: $DESCRIPTION
708 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
717 local DEPENDENCIES="$5"
719 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
721 local FILE="${SPATH}/Sources
"
725 Maintainer
: Joe Sixpack
<joe@example.org
>
726 Architecture
: $ARCH" >> $FILE
727 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
729 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
730 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
734 insertinstalledpackage() {
738 local DEPENDENCIES="$4"
739 local PRIORITY="${5:-optional}"
740 local STATUS="${6:-install ok installed}"
741 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
742 If you
find such a package installed on your system
,
743 something went horribly wrong
! They are autogenerated
744 und used only by testcases and surf no other propose…
"}"
746 local FILE
='rootdir/var/lib/dpkg/status'
747 local INFO
='rootdir/var/lib/dpkg/info'
748 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
754 Maintainer: Joe Sixpack <joe@example.org>
755 Version: $VERSION" >> $FILE
756 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
757 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
758 echo "Description: $DESCRIPTION" >> $FILE
760 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
761 echo -n > ${INFO}/${NAME}:${arch}.list
763 echo -n > ${INFO}/${NAME}.list
769 buildaptarchivefromincoming
() {
770 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
772 [ -e pool
] || ln -s ..
/incoming pool
773 [ -e ftparchive.conf
] || createaptftparchiveconfig
774 [ -e dists
] || buildaptftparchivedirectorystructure
775 msgninfo
"\tGenerate Packages, Sources and Contents files… "
776 aptftparchive
-qq generate ftparchive.conf
779 generatereleasefiles
"$@"
782 buildaptarchivefromfiles
() {
783 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
784 find aptarchive
-name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
785 msgninfo
"\t${line} file… "
786 compressfile
"$line" "$1"
789 generatereleasefiles
"$@"
793 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
794 if [ "$compressor" = '.' ]; then
800 cat "$1" | $command > "${1}.${extension}"
802 touch -d "$2" "${1}.${extension}"
807 # can be overridden by testcases for their pleasure
808 getcodenamefromsuite
() {
810 unstable
) echo 'sid';;
814 getreleaseversionfromsuite
() { true
; }
815 getlabelfromsuite
() { true
; }
817 generatereleasefiles
() {
818 # $1 is the Date header and $2 is the ValidUntil header to be set
819 # both should be given in notation date/touch can understand
820 msgninfo
"\tGenerate Release files… "
821 if [ -e aptarchive
/dists
]; then
822 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
823 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
824 local CODENAME
="$(getcodenamefromsuite $SUITE)"
825 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
826 local LABEL
="$(getlabelfromsuite $SUITE)"
827 if [ -n "$VERSION" ]; then
828 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
830 if [ -n "$LABEL" ]; then
831 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
833 aptftparchive
-qq release
$dir \
834 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
835 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
838 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
839 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
841 NotAutomatic: yes' $dir/Release
843 if [ -n "$1" -a "$1" != "now" ]; then
844 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
848 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
852 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
854 if [ -n "$1" -a "$1" != "now" ]; then
855 for release
in $(find ./aptarchive -name 'Release'); do
856 touch -d "$1" $release
862 setupdistsaptarchive
() {
863 local APTARCHIVE
=$(readlink -f ./aptarchive)
864 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
865 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
866 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
867 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
868 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
869 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
870 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
875 setupflataptarchive
() {
876 local APTARCHIVE
=$(readlink -f ./aptarchive)
877 if [ -f ${APTARCHIVE}/Packages
]; then
878 msgninfo
"\tadd deb sources.list line… "
879 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
882 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
884 if [ -f ${APTARCHIVE}/Sources
]; then
885 msgninfo
"\tadd deb-src sources.list line… "
886 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
889 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
895 if [ "$1" = '--no-update' ]; then
900 if [ -e aptarchive
/dists
]; then
905 signreleasefiles
'Joe Sixpack'
906 if [ "1" != "$NOUPDATE" ]; then
907 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
912 local SIGNER
="${1:-Joe Sixpack}"
913 local REPODIR
="${2:-aptarchive}"
914 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
915 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
916 msgninfo
"\tSign archive with $SIGNER key $KEY… "
917 local REXKEY
='keys/rexexpired'
918 local SECEXPIREBAK
="${REXKEY}.sec.bak"
919 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
920 if [ "${SIGNER}" = 'Rex Expired' ]; then
921 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
922 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
923 # therefore we 'temporary' make the key not expired and restore a backup after signing
924 cp ${REXKEY}.sec
$SECEXPIREBAK
925 cp ${REXKEY}.pub
$PUBEXPIREBAK
926 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
927 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
928 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
929 cp $SECUNEXPIRED ${REXKEY}.sec
930 cp $PUBUNEXPIRED ${REXKEY}.pub
932 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
936 cp ${REXKEY}.sec
$SECUNEXPIRED
937 cp ${REXKEY}.pub
$PUBUNEXPIRED
940 for RELEASE
in $(find ${REPODIR}/ -name Release); do
941 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
942 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
943 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
944 # we might have set a specific date for the Release file, so copy it
945 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
947 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
948 mv -f $SECEXPIREBAK ${REXKEY}.sec
949 mv -f $PUBEXPIREBAK ${REXKEY}.pub
956 if [ "$1" = '--no-check' ]; then
960 local DOWNLOG
='rootdir/tmp/download-testfile.log'
961 local STATUS
='downloaded/webserverconfig.status'
962 rm -f "$STATUS" "$DOWNLOG"
965 msgtest
"Set webserver config option '${1}' to" "$2"
966 URI
="http://localhost:8080/_config/set/${1}/${2}"
968 msgtest
'Clear webserver config option' "${1}"
969 URI
="http://localhost:8080/_config/clear/${1}"
971 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
974 cat "$DOWNLOG" "$STATUS" || true
977 $NOCHECK || testwebserverlaststatuscode
'200'
980 rewritesourceslist
() {
981 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
982 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
983 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
987 # wait for up to 10s for a pid file to appear to avoid possible race
988 # when a helper is started and dosn't write the PID quick enough
991 for i
in $(seq 10); do
992 if test -s "$PIDFILE"; then
997 msgdie
"waiting for $PIDFILE failed"
1001 changetowebserver
() {
1002 if [ "$1" != '--no-rewrite' ]; then
1003 rewritesourceslist
'http://localhost:8080/'
1007 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1009 local LOG
="webserver.log"
1010 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1014 waitforpidfile aptwebserver.pid
1015 local PID
="$(cat aptwebserver.pid)"
1016 if [ -z "$PID" ]; then
1017 msgdie
'Could not fork aptwebserver successfully'
1019 addtrap
"kill $PID;"
1022 msgdie
'You have to build aptwerbserver or install a webserver'
1026 changetohttpswebserver
() {
1027 if ! which stunnel4
>/dev
/null
; then
1028 msgdie
'You need to install stunnel4 for https testcases'
1030 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1031 changetowebserver
--no-rewrite "$@"
1033 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1034 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1040 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1041 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1042 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1043 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1044 if [ -z "$PID" ]; then
1045 msgdie
'Could not fork stunnel4 successfully'
1047 addtrap
'prefix' "kill ${PID};"
1048 rewritesourceslist
'https://localhost:4433/'
1052 mkdir -p rootdir
/media
/cdrom
/.disk
1053 local CD
="$(readlink -f rootdir/media/cdrom)"
1054 echo "acquire::cdrom::mount \"${CD}\";
1055 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1056 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1057 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1058 echo -n "$1" > ${CD}/.disk
/info
1059 if [ ! -d aptarchive
/dists
]; then
1060 msgdie
'Flat file archive cdroms can not be created currently'
1063 mv aptarchive
/dists
"$CD"
1064 ln -s "$(readlink -f ./incoming)" $CD/pool
1065 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1066 # start with an unmounted disk
1067 mv "${CD}" "${CD}-unmounted"
1068 # we don't want the disk to be modifiable
1069 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1070 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1074 local PROTO
="$(echo "$1" | cut -d':' -f 1 )"
1075 apthelper
-o Debug
::Acquire
::${PROTO}=1 \
1076 download
-file "$1" "$2" 2>&1 || true
1077 # only if the file exists the download was successful
1078 if [ -r "$2" ]; then
1086 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1087 if [ -n "$DIFFTEXT" ]; then
1089 echo >&2 "$DIFFTEXT"
1099 msgtest
"Test for correctness of file" "$FILE"
1100 if [ -z "$*" ]; then
1101 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1103 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1108 msgtest
"Test for no output of" "$*"
1109 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1110 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1117 aptautotest
'testempty' "$@"
1121 local MSG
='Test of equality of'
1122 if [ "$1" = '--nomsg' ]; then
1127 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1128 echo "$1" > $COMPAREFILE
1131 if [ -n "$MSG" ]; then
1134 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1135 aptautotest
'testequal' "$@"
1139 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1140 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1141 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1142 echo "$1" > $COMPAREFILE1
1143 echo "$2" > $COMPAREFILE2
1145 msgtest
"Test for equality OR of" "$*"
1146 "$@" >$COMPAREAGAINST 2>&1 || true
1147 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1148 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1152 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1153 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1154 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1155 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1158 aptautotest
'testequalor2' "$@"
1162 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1165 while [ -n "$1" ]; do
1167 N: Can't select versions from package '$1' as it is purely virtual"
1168 PACKAGE
="${PACKAGE} $1"
1171 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1173 N: No packages found"
1174 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1175 local ARCH
="$(getarchitecture 'native')"
1176 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1177 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1181 msgtest
"Test for non-existent packages" "apt-cache show $*"
1182 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1183 if [ -n "$SHOWPKG" ]; then
1192 testdpkginstalled
() {
1193 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1194 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1195 if [ "$PKGS" != $# ]; then
1197 dpkg
-l "$@" | grep '^[a-z]' >&2
1204 testdpkgnotinstalled
() {
1205 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1206 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1207 if [ "$PKGS" != 0 ]; then
1209 dpkg
-l "$@" | grep '^[a-z]' >&2
1217 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1218 if [ -n "$1" ]; then
1219 msgtest
'Test for correctly marked as auto-installed' "$*"
1220 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1222 msgtest
'Test for correctly marked as auto-installed' 'no package'
1223 echo -n > $COMPAREFILE
1225 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1233 if [ "$1" = 'grep' ]; then
1234 while [ -n "$2" ]; do shift; done
1235 echo "#### Complete file: $1 ####"
1236 cat >&2 "$1" || true
1237 echo '#### grep output ####'
1238 elif [ "$1" = 'test' ]; then
1239 # doesn't support ! or non-file flags
1240 msgfailoutputstatfile
() {
1241 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1242 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1243 echo "#### stat(2) of file: $2 ####"
1247 msgfailoutputstatfile
"$2" "$3"
1248 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1250 msgfailoutputstatfile
"$2" "$3"
1252 echo '#### test output ####'
1259 if [ "$1" = '--nomsg' ]; then
1262 msgtest
'Test for successful execution of' "$*"
1264 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1265 if "$@" >${OUTPUT} 2>&1; then
1266 if expr match
"$1" '^apt.*' >/dev
/null
; then
1267 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1268 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1269 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1270 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1279 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1281 aptautotest
'testsuccess' "$@"
1284 if [ "$1" = '--nomsg' ]; then
1287 msgtest
'Test for successful execution with warnings of' "$*"
1289 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1290 if "$@" >${OUTPUT} 2>&1; then
1291 if expr match
"$1" '^apt.*' >/dev
/null
; then
1292 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1293 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1294 elif grep -q -E '^E: ' "$OUTPUT"; then
1295 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1296 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1297 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1308 msgfail
"exitcode $EXITCODE"
1310 aptautotest
'testwarning' "$@"
1313 if [ "$1" = '--nomsg' ]; then
1316 msgtest
'Test for failure in execution of' "$*"
1318 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1319 if "$@" >${OUTPUT} 2>&1; then
1321 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1324 if expr match
"$1" '^apt.*' >/dev
/null
; then
1325 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1326 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1327 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1328 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1336 aptautotest
'testfailure' "$@"
1340 msgtest
"Test that file $1 has $2 $3" "$4"
1341 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1346 echo -n >&2 "stat(1) reports for $2: "
1347 stat
--format "$2" "$1"
1351 testaccessrights
() {
1352 testfilestats
"$1" '%a' '=' "$2"
1355 testwebserverlaststatuscode
() {
1356 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1357 local STATUS
='downloaded/webserverstatus-statusfile.log'
1358 rm -f "$DOWNLOG" "$STATUS"
1359 msgtest
'Test last status code from the webserver was' "$1"
1360 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1364 if [ -n "$2" ]; then
1366 echo >&2 '#### Additionally provided output files contain:'
1369 echo >&2 '#### Download log of the status code:'
1371 msgfail
"Status was $(cat "$STATUS")"
1376 echo "STOPPED execution. Press enter to continue"
1381 listcurrentlistsdirectory
() {
1382 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1383 stat
--format '%U:%G:%a:%n' "$line"
1385 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1386 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1390 ### The following tests are run by most test methods automatically to check
1391 ### general things about commands executed without writing the test every time.
1397 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1398 if command -v $AUTOTEST >/dev
/null
; then
1400 # save and restore the *.output files from other tests
1401 # as we might otherwise override them in these automatic tests
1402 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1403 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1404 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1405 $AUTOTEST "$TESTCALL" "$@"
1406 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1407 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1408 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1412 aptautotest_aptget_update
() {
1413 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1414 # all copied files are properly chmodded
1415 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f); do
1416 testfilestats
"$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
1419 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }