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 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
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
251 cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
254 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
255 if [ -n "\$LD_PRELOAD" ]; then
256 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
258 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
261 exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
262 --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
263 --force-not-root --force-bad-path "\$@"
265 chmod +x
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
266 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
268 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
269 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
271 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
272 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
273 # too distracting for users, but helpful to detect changes
274 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
275 # in testcases, it can appear as if localhost has a rotation setup,
276 # hide this as we can't really deal with it properly
277 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
279 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
280 if [ "$(id -u)" = '0' ]; then
281 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
283 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
284 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
285 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
287 # create some files in /tmp and look at user/group to get what this means
288 TEST_DEFAULT_USER
="$USER"
289 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
290 TEST_DEFAULT_GROUP
='root'
292 TEST_DEFAULT_GROUP
="$USER"
295 # Acquire::AllowInsecureRepositories=false is not yet the default
296 # but we want it to be the default soon
297 configallowinsecurerepositories
"false";
299 # cleanup the environment a bit
300 # prefer our apt binaries over the system apt binaries
301 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
302 export LC_ALL
=C.UTF
-8
303 unset LANGUAGE APT_CONFIG
304 unset GREP_OPTIONS DEB_BUILD_PROFILES
310 if [ "$1" = "native" -o -z "$1" ]; then
311 eval `aptconfig shell ARCH APT::Architecture`
312 if [ -n "$ARCH" ]; then
315 dpkg
--print-architecture
323 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
326 getarchitecturesfromcommalist
() {
327 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
330 configarchitecture
() {
332 echo "APT::Architecture \"$(getarchitecture $1)\";"
333 while [ -n "$1" ]; do
334 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
337 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
342 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
343 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
344 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
345 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
347 echo -n > rootdir/var/lib/dpkg/status
350 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
351 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
352 local ARCHS="$(getarchitectures)"
353 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
354 DPKGARCH="$(dpkg --print-architecture)"
355 for ARCH in ${ARCHS}; do
356 if [ "${ARCH}" != "${DPKGARCH}" ]; then
357 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
358 # old-style used e.g. in Ubuntu-P – and as it seems travis
359 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
360 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
364 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
365 # dpkg doesn't really check the version as long as it is fully installed,
366 # but just to be sure we choose one above the required version
367 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
373 configdpkgnoopchroot() {
374 # create a library to noop chroot() and rewrite maintainer script executions
375 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
376 # chroot directory dpkg could chroot into to execute the maintainer scripts
377 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
378 cat << EOF > noopchroot.c
385 static char * chrootdir = NULL;
387 int chroot(const char *path) {
388 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
390 chrootdir = strdup(path);
393 int execvp(const char *file, char *const argv[]) {
394 static int (*func_execvp) (const char *, char * const []) = NULL;
395 if (func_execvp == NULL)
396 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
397 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
398 return func_execvp(file, argv);
399 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
400 char newfile[strlen(chrootdir) + strlen(file)];
401 strcpy(newfile, chrootdir);
402 strcat(newfile, file);
403 char const * const baseadmindir = "/var
/lib
/dpkg
";
404 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
405 strcpy(admindir, chrootdir);
406 strcat(admindir, baseadmindir);
407 setenv("DPKG_ADMINDIR
", admindir, 1);
408 return func_execvp(newfile, argv);
411 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
414 configallowinsecurerepositories() {
415 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
419 configcompression() {
420 while [ -n "$1" ]; do
422 '.') printf ".
\t.
\tcat
\n";;
423 'gz') printf "gzip\tgz
\tgzip
\n";;
424 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
425 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
426 'xz') printf "xz
\txz
\txz
\n";;
427 *) printf "$1\t$1\t$1\n";;
430 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
437 gzip) COMPRESS='gz';;
438 bzip2) COMPRESS='bz2';;
439 lzma) COMPRESS='lzma';;
441 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
443 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
444 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
445 Dir::Bin::uncompressed \"/does/not/exist\";
446 Dir::Bin::gzip \"/does/not/exist\";
447 Dir::Bin::bzip2 \"/does/not/exist\";
448 Dir::Bin::lzma \"/does/not/exist\";
449 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
450 if [ -e "/bin/${COMPRESSOR}" ]; then
451 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
452 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
453 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
454 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
455 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
456 COMPRESSOR_CMD='xz
--format=lzma
'
458 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
463 setupsimplenativepackage() {
467 local RELEASE="${4:-unstable}"
468 local DEPENDENCIES="$5"
469 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
470 If you find such a package installed on your system,
471 something went horribly wrong! They are autogenerated
472 und used only by testcases and surf no other propose…"}"
474 local SECTION="${7:-others}"
476 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
479 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
481 local BUILDDIR=incoming/${NAME}-${VERSION}
482 mkdir -p ${BUILDDIR}/debian/source
484 echo "* most suckless software product ever" > FEATURES
485 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
486 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
490 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
491 test -e debian/control || echo "Source: $NAME
494 Maintainer: Joe Sixpack <joe@example.org>
495 Build-Depends: debhelper (>= 7)
496 Standards-Version: 3.9.1
498 Package: $NAME" > debian/control
499 if [ "$ARCH" = 'all
' ]; then
500 echo "Architecture: all" >> debian/control
502 echo "Architecture: any" >> debian/control
504 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
505 echo "Description: $DESCRIPTION" >> debian/control
507 test -e debian/compat || echo "7" > debian/compat
508 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
509 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
513 buildsimplenativepackage() {
517 local RELEASE="${4:-unstable}"
518 local DEPENDENCIES="$5"
519 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
520 If you find such a package installed on your system,
521 something went horribly wrong! They are autogenerated
522 und used only by testcases and surf no other propose…"}"
524 local SECTION="${7:-others}"
525 local PRIORITY="${8:-optional}"
527 local COMPRESS_TYPE="${10:-gzip}"
529 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
532 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
534 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
536 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
537 mkdir -p $BUILDDIR/debian/source
538 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
540 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
542 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
543 echo "$NAME ($VERSION) $RELEASE; urgency=low
547 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
551 Maintainer: Joe Sixpack <joe@example.org>
552 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
553 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
554 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
556 Package: $NAME" >> ${BUILDDIR}/debian/control
558 if [ "$ARCH" = 'all
' ]; then
559 echo "Architecture: all" >> ${BUILDDIR}/debian/control
561 echo "Architecture: any" >> ${BUILDDIR}/debian/control
563 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
564 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
565 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
567 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
569 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
571 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
573 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
574 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
575 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
576 # adv --yes --default-key 'Joe Sixpack' \
577 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
578 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
582 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
583 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
584 rm -rf ${BUILDDIR}/debian
/tmp
585 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
586 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
587 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
588 if [ -n "$FILE_TREE" ]; then
589 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
592 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
593 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
594 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
595 # ensure the right permissions as dpkg-deb ensists
596 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
597 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
598 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
601 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
602 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
603 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
612 local ARCH
=$(getarchitecture $4)
613 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
614 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
615 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
617 if [ "$ARCH" = "all" ]; then
618 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
620 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
621 cp ${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
$BUILDLOG
622 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
623 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
626 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
629 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
634 if [ -d incoming
]; then
635 buildaptarchivefromincoming
"$@"
637 buildaptarchivefromfiles
"$@"
641 createaptftparchiveconfig
() {
642 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
643 local COMPRESSORS
="${COMPRESSORS%* }"
644 local ARCHS
="$(getarchitectures)"
646 ArchiveDir "' >> ftparchive.conf
647 echo -n $(readlink -f .) >> ftparchive.conf
649 CacheDir "' >> ftparchive.conf
650 echo -n $(readlink -f ..) >> ftparchive.conf
652 FileListDir "' >> ftparchive.conf
653 echo -n $(readlink -f pool/) >> ftparchive.conf
657 Packages::Compress "'"$COMPRESSORS"'";
658 Sources::Compress "'"$COMPRESSORS"'";
659 Contents::Compress "'"$COMPRESSORS"'";
660 Translation::Compress "'"$COMPRESSORS"'";
661 LongDescription "false";
665 SrcDirectory "pool/";
671 Label "apttestcases";
673 Description "repository with dummy packages";
674 Architectures "' >> ftparchive.conf
675 echo -n "$ARCHS" >> ftparchive.conf
679 };' >> ftparchive.conf
680 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
681 echo -n 'tree "dists/' >> ftparchive.conf
682 echo -n "$DIST" >> ftparchive.conf
684 Architectures "' >> ftparchive.conf
685 echo -n "$ARCHS" >> ftparchive.conf
687 FileList "' >> ftparchive.conf
688 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
690 SourceFileList "' >> ftparchive.conf
691 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
693 Sections "' >> ftparchive.conf
694 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
696 };' >> ftparchive.conf
700 buildaptftparchivedirectorystructure
() {
701 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
702 for DIST
in $DISTS; do
703 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
704 for SECTION
in $SECTIONS; do
705 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
706 for ARCH
in $ARCHS; do
707 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
709 mkdir -p dists
/${DIST}/${SECTION}/source
710 mkdir -p dists
/${DIST}/${SECTION}/i18n
720 local DEPENDENCIES
="$5"
721 local PRIORITY
="${6:-optional}"
722 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
723 If you find such a package installed on your system,
724 something went horribly wrong! They are autogenerated
725 und used only by testcases and surf no other propose…"}"
727 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
728 if [ "$RELEASE" = 'installed' ]; then
729 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
732 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
733 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
734 ARCHS="$(getarchitectures)"
738 for BUILDARCH in $ARCHS; do
739 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
741 local FILE="${PPATH}/Packages
"
746 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
747 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
748 echo "Version
: $VERSION
749 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
750 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
751 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
752 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
756 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
757 touch aptarchive/dists/${RELEASE}/main/source/Sources
759 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
760 Description
-en: $DESCRIPTION
761 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
770 local DEPENDENCIES="$5"
772 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
774 local FILE="${SPATH}/Sources
"
778 Maintainer
: Joe Sixpack
<joe@example.org
>
779 Architecture
: $ARCH" >> $FILE
780 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
782 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
783 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
787 insertinstalledpackage() {
791 local DEPENDENCIES="$4"
792 local PRIORITY="${5:-optional}"
793 local STATUS="${6:-install ok installed}"
794 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
795 If you
find such a package installed on your system
,
796 something went horribly wrong
! They are autogenerated
797 und used only by testcases and surf no other propose…
"}"
799 local FILE
='rootdir/var/lib/dpkg/status'
800 local INFO
='rootdir/var/lib/dpkg/info'
801 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
807 Maintainer: Joe Sixpack <joe@example.org>
808 Version: $VERSION" >> $FILE
809 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
810 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
811 echo "Description: $DESCRIPTION" >> $FILE
813 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
814 echo -n > ${INFO}/${NAME}:${arch}.list
816 echo -n > ${INFO}/${NAME}.list
822 buildaptarchivefromincoming
() {
823 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
825 [ -e pool
] || ln -s ..
/incoming pool
826 [ -e ftparchive.conf
] || createaptftparchiveconfig
827 [ -e dists
] || buildaptftparchivedirectorystructure
828 msgninfo
"\tGenerate Packages, Sources and Contents files… "
829 testsuccess aptftparchive generate ftparchive.conf
832 generatereleasefiles
"$@"
835 buildaptarchivefromfiles
() {
836 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
837 find aptarchive
-name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
838 msgninfo
"\t${line} file… "
839 compressfile
"$line" "$1"
842 generatereleasefiles
"$@"
846 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
847 if [ "$compressor" = '.' ]; then
853 cat "$1" | $command > "${1}.${extension}"
855 touch -d "$2" "${1}.${extension}"
860 # can be overridden by testcases for their pleasure
861 getcodenamefromsuite
() {
863 unstable
) echo 'sid';;
867 getreleaseversionfromsuite
() { true
; }
868 getlabelfromsuite
() { true
; }
870 generatereleasefiles
() {
871 # $1 is the Date header and $2 is the ValidUntil header to be set
872 # both should be given in notation date/touch can understand
873 msgninfo
"\tGenerate Release files… "
874 if [ -e aptarchive
/dists
]; then
875 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
876 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
877 local CODENAME
="$(getcodenamefromsuite $SUITE)"
878 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
879 local LABEL
="$(getlabelfromsuite $SUITE)"
880 if [ -n "$VERSION" ]; then
881 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
883 if [ -n "$LABEL" ]; then
884 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
886 aptftparchive
-qq release
$dir \
887 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
888 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
891 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
892 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
894 NotAutomatic: yes' $dir/Release
896 if [ -n "$1" -a "$1" != "now" ]; then
897 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
901 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
905 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
907 if [ -n "$1" -a "$1" != "now" ]; then
908 for release
in $(find ./aptarchive -name 'Release'); do
909 touch -d "$1" $release
915 setupdistsaptarchive
() {
916 local APTARCHIVE
=$(readlink -f ./aptarchive)
917 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
918 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
919 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
920 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
921 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
922 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
923 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
928 setupflataptarchive
() {
929 local APTARCHIVE
=$(readlink -f ./aptarchive)
930 if [ -f ${APTARCHIVE}/Packages
]; then
931 msgninfo
"\tadd deb sources.list line… "
932 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
935 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
937 if [ -f ${APTARCHIVE}/Sources
]; then
938 msgninfo
"\tadd deb-src sources.list line… "
939 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
942 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
948 if [ "$1" = '--no-update' ]; then
953 if [ -e aptarchive
/dists
]; then
958 signreleasefiles
'Joe Sixpack'
959 if [ "1" != "$NOUPDATE" ]; then
960 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
965 local SIGNER
="${1:-Joe Sixpack}"
966 local REPODIR
="${2:-aptarchive}"
967 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
968 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
969 msgninfo
"\tSign archive with $SIGNER key $KEY… "
970 local REXKEY
='keys/rexexpired'
971 local SECEXPIREBAK
="${REXKEY}.sec.bak"
972 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
973 if [ "${SIGNER}" = 'Rex Expired' ]; then
974 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
975 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
976 # therefore we 'temporary' make the key not expired and restore a backup after signing
977 cp ${REXKEY}.sec
$SECEXPIREBAK
978 cp ${REXKEY}.pub
$PUBEXPIREBAK
979 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
980 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
981 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
982 cp $SECUNEXPIRED ${REXKEY}.sec
983 cp $PUBUNEXPIRED ${REXKEY}.pub
985 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
989 cp ${REXKEY}.sec
$SECUNEXPIRED
990 cp ${REXKEY}.pub
$PUBUNEXPIRED
993 for RELEASE
in $(find ${REPODIR}/ -name Release); do
994 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
995 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
996 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
997 # we might have set a specific date for the Release file, so copy it
998 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
1000 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1001 mv -f $SECEXPIREBAK ${REXKEY}.sec
1002 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1009 if [ "$1" = '--no-check' ]; then
1013 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1014 local STATUS
='downloaded/webserverconfig.status'
1015 rm -f "$STATUS" "$DOWNLOG"
1017 if [ -n "$2" ]; then
1018 msgtest
"Set webserver config option '${1}' to" "$2"
1019 URI
="http://localhost:8080/_config/set/${1}/${2}"
1021 msgtest
'Clear webserver config option' "${1}"
1022 URI
="http://localhost:8080/_config/clear/${1}"
1024 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1027 cat "$DOWNLOG" "$STATUS" || true
1030 $NOCHECK || testwebserverlaststatuscode
'200'
1033 rewritesourceslist
() {
1034 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1035 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1036 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
1040 # wait for up to 10s for a pid file to appear to avoid possible race
1041 # when a helper is started and dosn't write the PID quick enough
1044 for i
in $(seq 10); do
1045 if test -s "$PIDFILE"; then
1050 msgdie
"waiting for $PIDFILE failed"
1054 changetowebserver
() {
1055 if [ "$1" != '--no-rewrite' ]; then
1056 rewritesourceslist
'http://localhost:8080/'
1060 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1062 local LOG
="webserver.log"
1063 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1067 waitforpidfile aptwebserver.pid
1068 local PID
="$(cat aptwebserver.pid)"
1069 if [ -z "$PID" ]; then
1070 msgdie
'Could not fork aptwebserver successfully'
1072 addtrap
"kill $PID;"
1075 msgdie
'You have to build aptwerbserver or install a webserver'
1079 changetohttpswebserver
() {
1080 if ! which stunnel4
>/dev
/null
; then
1081 msgdie
'You need to install stunnel4 for https testcases'
1083 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1084 changetowebserver
--no-rewrite "$@"
1086 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1087 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1093 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1094 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1095 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1096 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1097 if [ -z "$PID" ]; then
1098 msgdie
'Could not fork stunnel4 successfully'
1100 addtrap
'prefix' "kill ${PID};"
1101 rewritesourceslist
'https://localhost:4433/'
1105 mkdir -p rootdir
/media
/cdrom
/.disk
1106 local CD
="$(readlink -f rootdir/media/cdrom)"
1107 echo "acquire::cdrom::mount \"${CD}\";
1108 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1109 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1110 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1111 echo -n "$1" > ${CD}/.disk
/info
1112 if [ ! -d aptarchive
/dists
]; then
1113 msgdie
'Flat file archive cdroms can not be created currently'
1116 mv aptarchive
/dists
"$CD"
1117 ln -s "$(readlink -f ./incoming)" $CD/pool
1118 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1119 # start with an unmounted disk
1120 mv "${CD}" "${CD}-unmounted"
1121 # we don't want the disk to be modifiable
1122 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1123 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1127 local PROTO
="${1%%:*}"
1128 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1129 download
-file "$1" "$2" 2>&1 ; then
1132 # only if the file exists the download was successful
1133 if [ -r "$2" ]; then
1141 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1142 if [ -n "$DIFFTEXT" ]; then
1144 echo >&2 "$DIFFTEXT"
1154 msgtest
"Test for correctness of file" "$FILE"
1155 if [ -z "$*" ]; then
1156 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1158 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1163 msgtest
"Test for no output of" "$*"
1164 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1165 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1172 aptautotest
'testempty' "$@"
1176 local MSG
='Test of equality of'
1177 if [ "$1" = '--nomsg' ]; then
1182 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1183 echo "$1" > $COMPAREFILE
1186 if [ -n "$MSG" ]; then
1189 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1190 aptautotest
'testequal' "$@"
1194 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1195 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1196 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1197 echo "$1" > $COMPAREFILE1
1198 echo "$2" > $COMPAREFILE2
1200 msgtest
"Test for equality OR of" "$*"
1201 "$@" >$COMPAREAGAINST 2>&1 || true
1202 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1203 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1207 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1208 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1209 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1210 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1213 aptautotest
'testequalor2' "$@"
1217 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1220 while [ -n "$1" ]; do
1222 N: Can't select versions from package '$1' as it is purely virtual"
1223 PACKAGE
="${PACKAGE} $1"
1226 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1228 N: No packages found"
1229 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1230 local ARCH
="$(getarchitecture 'native')"
1231 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1232 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1236 msgtest
"Test for non-existent packages" "apt-cache show $*"
1237 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1238 if [ -n "$SHOWPKG" ]; then
1251 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1252 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1253 if [ "$PKGS" != $NR ]; then
1255 dpkg
-l "$@" | grep '^[a-z]' >&2
1262 testdpkginstalled
() {
1263 testdpkgstatus
'ii' "$#" "$@"
1266 testdpkgnotinstalled
() {
1267 testdpkgstatus
'ii' '0' "$@"
1271 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1272 if [ -n "$1" ]; then
1273 msgtest
'Test for correctly marked as auto-installed' "$*"
1274 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1276 msgtest
'Test for correctly marked as auto-installed' 'no package'
1277 echo -n > $COMPAREFILE
1279 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1287 if [ "$1" = 'grep' ]; then
1288 while [ -n "$2" ]; do shift; done
1289 echo "#### Complete file: $1 ####"
1290 cat >&2 "$1" || true
1291 echo '#### grep output ####'
1292 elif [ "$1" = 'test' ]; then
1293 # doesn't support ! or non-file flags
1294 msgfailoutputstatfile
() {
1295 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1296 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1297 echo "#### stat(2) of file: $2 ####"
1301 msgfailoutputstatfile
"$2" "$3"
1302 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1304 msgfailoutputstatfile
"$2" "$3"
1306 echo '#### test output ####'
1313 if [ "$1" = '--nomsg' ]; then
1316 msgtest
'Test for successful execution of' "$*"
1318 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1319 if "$@" >${OUTPUT} 2>&1; then
1320 if expr match
"$1" '^apt.*' >/dev
/null
; then
1321 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1322 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1323 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1324 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1333 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1335 aptautotest
'testsuccess' "$@"
1338 if [ "$1" = '--nomsg' ]; then
1341 msgtest
'Test for successful execution with warnings of' "$*"
1343 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1344 if "$@" >${OUTPUT} 2>&1; then
1345 if expr match
"$1" '^apt.*' >/dev
/null
; then
1346 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1347 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1348 elif grep -q -E '^E: ' "$OUTPUT"; then
1349 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1350 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1351 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1362 msgfail
"exitcode $EXITCODE"
1364 aptautotest
'testwarning' "$@"
1367 if [ "$1" = '--nomsg' ]; then
1370 msgtest
'Test for failure in execution of' "$*"
1372 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1373 if "$@" >${OUTPUT} 2>&1; then
1375 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1378 if expr match
"$1" '^apt.*' >/dev
/null
; then
1379 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1380 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1381 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1382 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1390 aptautotest
'testfailure' "$@"
1393 testsuccessequal
() {
1397 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
1399 testwarningequal
() {
1403 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
1405 testfailureequal
() {
1409 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
1416 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1417 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output" 2>&1 || true
1418 if echo "$CMP" | checkdiff
- "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output"; then
1421 echo '### Complete output ###'
1422 cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1428 msgtest
"Test that file $1 has $2 $3" "$4"
1429 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1434 echo -n >&2 "stat(1) reports for $2: "
1435 stat
--format "$2" "$1"
1439 testaccessrights
() {
1440 testfilestats
"$1" '%a' '=' "$2"
1443 testwebserverlaststatuscode
() {
1444 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1445 local STATUS
='downloaded/webserverstatus-statusfile.log'
1446 rm -f "$DOWNLOG" "$STATUS"
1447 msgtest
'Test last status code from the webserver was' "$1"
1448 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1452 if [ -n "$2" ]; then
1454 echo >&2 '#### Additionally provided output files contain:'
1457 echo >&2 '#### Download log of the status code:'
1459 msgfail
"Status was $(cat "$STATUS")"
1464 echo "STOPPED execution. Press enter to continue"
1469 listcurrentlistsdirectory
() {
1470 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1471 stat
--format '%U:%G:%a:%n' "$line"
1473 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1474 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1478 ### convinience hacks ###
1480 # creating some directories by hand is a tedious task, so make it look simple
1481 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1482 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1483 # only the last directory created by mkdir is effected by the -m !
1484 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1485 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1486 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1487 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1488 if [ "$(id -u)" = '0' ]; then
1489 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1496 ### The following tests are run by most test methods automatically to check
1497 ### general things about commands executed without writing the test every time.
1503 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1504 if command -v $AUTOTEST >/dev
/null
; then
1506 # save and restore the *.output files from other tests
1507 # as we might otherwise override them in these automatic tests
1508 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1509 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1510 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1511 $AUTOTEST "$TESTCALL" "$@"
1512 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1513 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1514 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1518 aptautotest_aptget_update
() {
1519 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1520 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1521 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1522 # all copied files are properly chmodded
1523 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f ! -name 'lock'); do
1524 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1527 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1529 testaptautotestnodpkgwarning
() {
1531 while [ -n "$2" ]; do
1532 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi
1535 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1538 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1539 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1540 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1541 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1542 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1543 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }