1 #!/bin/sh -- # no runable script, just for vi
5 # we all like colorful messages
6 if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; 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 aptget
) CMD
="apt-get";;
143 aptcache
) CMD
="apt-cache";;
144 aptmark
) CMD
="apt-mark";;
145 apthelper
) CMD
="apt-helper";;
146 aptftparchive
) CMD
="apt-ftparchive";;
150 runapt
command gdb
--quiet -ex run
"${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
154 # error if we about to overflow, but ...
155 # "255 failures ought to be enough for everybody"
156 if [ $EXIT_CODE -gt 255 ]; then
157 msgdie
"Total failure count $EXIT_CODE too big"
159 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
162 shellsetedetector
() {
164 if [ "$exit_status" != '0' ]; then
165 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
166 if [ "$EXIT_CODE" = '0' ]; then
167 EXIT_CODE
="$exit_status"
173 if [ "$1" = 'prefix' ]; then
174 CURRENTTRAP
="$2 $CURRENTTRAP"
176 CURRENTTRAP
="$CURRENTTRAP $1"
178 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
182 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
183 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
186 TMPWORKINGDIRECTORY
=$(mktemp -d)
187 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
188 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
190 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
191 if [ "$(id -u)" = '0' ]; then
192 # relax permissions so that running as root with user switching works
194 chmod 711 "$TMPWORKINGDIRECTORY"
195 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
198 TESTDIRECTORY
=$(readlink -f $(dirname $0))
199 # allow overriding the default BUILDDIR location
200 SOURCEDIRECTORY
=${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}
201 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
202 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
203 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
204 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
205 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
206 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
207 APTDUMPSOLVER
=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}
208 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
211 cd $TMPWORKINGDIRECTORY
212 mkdir rootdir aptarchive keys
214 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
215 mkdir -p usr
/bin var
/cache var
/lib var
/log tmp
216 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
217 touch var
/lib
/dpkg
/available
219 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
220 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
221 mkdir -p usr
/lib
/apt
/solvers
222 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
223 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
224 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
226 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
228 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
229 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
231 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
234 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
235 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
236 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
238 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
239 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
240 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
242 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
243 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
244 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
246 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
247 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
248 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
249 echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
250 # store apt-key were we can access it, even if we run it as a different user
251 # destroys coverage reporting though, so just do it for root for now
252 if [ "$(id -u)" = '0' ]; then
253 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
254 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
255 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
257 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
260 cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
263 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
264 if [ -n "\$LD_PRELOAD" ]; then
265 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
267 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
270 exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
271 --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
272 --force-not-root --force-bad-path "\$@"
274 chmod +x
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
275 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
278 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
279 echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
281 echo 'quiet::NoUpdate "true";'
282 echo 'quiet::NoStatistic "true";'
283 # too distracting for users, but helpful to detect changes
284 echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
285 echo 'Acquire::Progress::Diffpercent "true";'
286 # in testcases, it can appear as if localhost has a rotation setup,
287 # hide this as we can't really deal with it properly
288 echo 'Acquire::Failure::ShowIP "false";'
291 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
292 if [ "$(id -u)" = '0' ]; then
293 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
295 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
296 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
297 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
299 # create some files in /tmp and look at user/group to get what this means
300 TEST_DEFAULT_USER
="$USER"
301 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
302 TEST_DEFAULT_GROUP
='root'
304 TEST_DEFAULT_GROUP
="$USER"
307 # Acquire::AllowInsecureRepositories=false is not yet the default
308 # but we want it to be the default soon
309 configallowinsecurerepositories
"false";
311 # cleanup the environment a bit
312 # prefer our apt binaries over the system apt binaries
313 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
314 export LC_ALL
=C.UTF
-8
315 unset LANGUAGE APT_CONFIG
316 unset GREP_OPTIONS DEB_BUILD_PROFILES
322 if [ "$1" = "native" -o -z "$1" ]; then
323 eval `aptconfig shell ARCH APT::Architecture`
324 if [ -n "$ARCH" ]; then
327 dpkg
--print-architecture
335 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
338 getarchitecturesfromcommalist
() {
339 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
342 configarchitecture
() {
344 echo "APT::Architecture \"$(getarchitecture $1)\";"
345 while [ -n "$1" ]; do
346 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
349 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
354 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
355 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
356 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
357 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
359 echo -n > rootdir/var/lib/dpkg/status
362 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
363 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
364 local ARCHS="$(getarchitectures)"
365 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
366 DPKGARCH="$(dpkg --print-architecture)"
367 for ARCH in ${ARCHS}; do
368 if [ "${ARCH}" != "${DPKGARCH}" ]; then
369 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
370 # old-style used e.g. in Ubuntu-P – and as it seems travis
371 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
372 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
376 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
377 # dpkg doesn't really check the version as long as it is fully installed,
378 # but just to be sure we choose one above the required version
379 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
385 configdpkgnoopchroot() {
386 # create a library to noop chroot() and rewrite maintainer script executions
387 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
388 # chroot directory dpkg could chroot into to execute the maintainer scripts
389 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
390 cat << EOF > noopchroot.c
397 static char * chrootdir = NULL;
399 int chroot(const char *path) {
400 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
402 chrootdir = strdup(path);
405 int execvp(const char *file, char *const argv[]) {
406 static int (*func_execvp) (const char *, char * const []) = NULL;
407 if (func_execvp == NULL)
408 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
409 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
410 return func_execvp(file, argv);
411 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
412 char newfile[strlen(chrootdir) + strlen(file)];
413 strcpy(newfile, chrootdir);
414 strcat(newfile, file);
415 char const * const baseadmindir = "/var
/lib
/dpkg
";
416 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
417 strcpy(admindir, chrootdir);
418 strcat(admindir, baseadmindir);
419 setenv("DPKG_ADMINDIR
", admindir, 1);
420 return func_execvp(newfile, argv);
423 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
426 configallowinsecurerepositories() {
427 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
431 configcompression() {
432 while [ -n "$1" ]; do
434 '.') printf ".
\t.
\tcat
\n";;
435 'gz') printf "gzip\tgz
\tgzip
\n";;
436 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
437 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
438 'xz') printf "xz
\txz
\txz
\n";;
439 *) printf "$1\t$1\t$1\n";;
442 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
449 gzip) COMPRESS='gz';;
450 bzip2) COMPRESS='bz2';;
451 lzma) COMPRESS='lzma';;
453 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
455 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
456 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
457 Dir::Bin::uncompressed \"/does/not/exist\";
458 Dir::Bin::gzip \"/does/not/exist\";
459 Dir::Bin::bzip2 \"/does/not/exist\";
460 Dir::Bin::lzma \"/does/not/exist\";
461 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
462 if [ -e "/bin/${COMPRESSOR}" ]; then
463 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
464 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
465 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
466 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
467 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
468 COMPRESSOR_CMD='xz
--format=lzma
'
470 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
475 setupsimplenativepackage() {
479 local RELEASE="${4:-unstable}"
480 local DEPENDENCIES="$5"
481 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
482 If you find such a package installed on your system,
483 something went horribly wrong! They are autogenerated
484 und used only by testcases and surf no other propose…"}"
486 local SECTION="${7:-others}"
488 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
491 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
493 local BUILDDIR=incoming/${NAME}-${VERSION}
494 mkdir -p ${BUILDDIR}/debian/source
496 echo "* most suckless software product ever" > FEATURES
497 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
498 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
502 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
503 test -e debian/control || echo "Source: $NAME
506 Maintainer: Joe Sixpack <joe@example.org>
507 Build-Depends: debhelper (>= 7)
508 Standards-Version: 3.9.1
510 Package: $NAME" > debian/control
511 if [ "$ARCH" = 'all
' ]; then
512 echo "Architecture: all" >> debian/control
514 echo "Architecture: any" >> debian/control
516 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
517 echo "Description: $DESCRIPTION" >> debian/control
519 test -e debian/compat || echo "7" > debian/compat
520 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
521 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
525 buildsimplenativepackage() {
528 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib
' ]; then
529 NM="$(echo "$NAME" | cut -c 1-4)"
531 NM="$(echo "$NAME" | cut -c 1)"
535 local RELEASE="${4:-unstable}"
536 local DEPENDENCIES="$5"
537 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
538 If you find such a package installed on your system,
539 something went horribly wrong! They are autogenerated
540 und used only by testcases and surf no other propose…"}"
542 local SECTION="${7:-others}"
543 local PRIORITY="${8:-optional}"
545 local COMPRESS_TYPE="${10:-gzip}"
547 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
550 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
552 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
554 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
555 mkdir -p $BUILDDIR/debian/source
556 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
558 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
560 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
561 echo "$NAME ($VERSION) $RELEASE; urgency=low
565 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
569 Maintainer: Joe Sixpack <joe@example.org>
570 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
571 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
572 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
574 Package: $NAME" >> ${BUILDDIR}/debian/control
576 if [ "$ARCH" = 'all
' ]; then
577 echo "Architecture: all" >> ${BUILDDIR}/debian/control
579 echo "Architecture: any" >> ${BUILDDIR}/debian/control
581 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
582 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
583 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
585 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
587 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
589 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
591 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
592 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
593 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
594 # adv --yes --default-key 'Joe Sixpack' \
595 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
596 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
600 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
601 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
602 rm -rf ${BUILDDIR}/debian
/tmp
603 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
604 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
605 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
606 if [ -n "$FILE_TREE" ]; then
607 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
610 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
611 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
612 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
613 # ensure the right permissions as dpkg-deb insists
614 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
615 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
616 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
619 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
621 cp ${BUILDDIR}/debian
/changelog
$CHANGEPATH
630 local ARCH
=$(getarchitecture $4)
631 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
632 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
633 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
635 if [ "$ARCH" = "all" ]; then
636 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
638 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
639 cp ${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
$BUILDLOG
640 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
641 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
644 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
647 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
652 if [ -d incoming
]; then
653 buildaptarchivefromincoming
"$@"
655 buildaptarchivefromfiles
"$@"
659 createaptftparchiveconfig
() {
660 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
661 local COMPRESSORS
="${COMPRESSORS%* }"
662 local ARCHS
="$(getarchitectures)"
664 ArchiveDir "' >> ftparchive.conf
665 echo -n $(readlink -f .) >> ftparchive.conf
667 CacheDir "' >> ftparchive.conf
668 echo -n $(readlink -f ..) >> ftparchive.conf
670 FileListDir "' >> ftparchive.conf
671 echo -n $(readlink -f pool/) >> ftparchive.conf
675 Packages::Compress "'"$COMPRESSORS"'";
676 Sources::Compress "'"$COMPRESSORS"'";
677 Contents::Compress "'"$COMPRESSORS"'";
678 Translation::Compress "'"$COMPRESSORS"'";
679 LongDescription "false";
683 SrcDirectory "pool/";
689 Label "apttestcases";
691 Description "repository with dummy packages";
692 Architectures "' >> ftparchive.conf
693 echo -n "$ARCHS" >> ftparchive.conf
697 };' >> ftparchive.conf
698 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
699 echo -n 'tree "dists/' >> ftparchive.conf
700 echo -n "$DIST" >> ftparchive.conf
702 Architectures "' >> ftparchive.conf
703 echo -n "$ARCHS" >> ftparchive.conf
705 FileList "' >> ftparchive.conf
706 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
708 SourceFileList "' >> ftparchive.conf
709 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
711 Sections "' >> ftparchive.conf
712 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
714 };' >> ftparchive.conf
718 buildaptftparchivedirectorystructure
() {
719 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
720 for DIST
in $DISTS; do
721 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
722 for SECTION
in $SECTIONS; do
723 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
724 for ARCH
in $ARCHS; do
725 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
727 mkdir -p dists
/${DIST}/${SECTION}/source
728 mkdir -p dists
/${DIST}/${SECTION}/i18n
738 local DEPENDENCIES
="$5"
739 local PRIORITY
="${6:-optional}"
740 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
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 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
746 if [ "$RELEASE" = 'installed' ]; then
747 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
750 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
751 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
752 ARCHS="$(getarchitectures)"
756 for BUILDARCH in $ARCHS; do
757 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
759 local FILE="${PPATH}/Packages
"
764 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
765 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
766 echo "Version
: $VERSION
767 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
768 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
769 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
770 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
774 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
775 touch aptarchive/dists/${RELEASE}/main/source/Sources
777 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
778 Description
-en: $DESCRIPTION
779 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
788 local DEPENDENCIES="$5"
790 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
792 local FILE="${SPATH}/Sources
"
793 local DSCFILE="${NAME}_
${VERSION}.dsc
"
794 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
798 Maintainer
: Joe Sixpack
<joe@example.org
>
799 Architecture
: $ARCH" >> $FILE
800 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
802 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE
803 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE
807 insertinstalledpackage() {
811 local DEPENDENCIES="$4"
812 local PRIORITY="${5:-optional}"
813 local STATUS="${6:-install ok installed}"
814 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
815 If you
find such a package installed on your system
,
816 something went horribly wrong
! They are autogenerated
817 und used only by testcases and surf no other propose…
"}"
819 local FILE
='rootdir/var/lib/dpkg/status'
820 local INFO
='rootdir/var/lib/dpkg/info'
821 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
827 Maintainer: Joe Sixpack <joe@example.org>
828 Version: $VERSION" >> $FILE
829 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
830 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
831 echo "Description: $DESCRIPTION" >> $FILE
833 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
834 echo -n > ${INFO}/${NAME}:${arch}.list
836 echo -n > ${INFO}/${NAME}.list
842 buildaptarchivefromincoming
() {
843 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
845 [ -e pool
] || ln -s ..
/incoming pool
846 [ -e ftparchive.conf
] || createaptftparchiveconfig
847 [ -e dists
] || buildaptftparchivedirectorystructure
848 msgninfo
"\tGenerate Packages, Sources and Contents files… "
849 testsuccess aptftparchive generate ftparchive.conf
852 generatereleasefiles
"$@"
855 buildaptarchivefromfiles
() {
856 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
857 local DIR
='aptarchive'
858 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
859 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
860 msgninfo
"\t${line} file… "
861 compressfile
"$line" "$1"
864 generatereleasefiles
"$@"
868 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
869 if [ "$compressor" = '.' ]; then
875 cat "$1" | $command > "${1}.${extension}"
877 touch -d "$2" "${1}.${extension}"
882 # can be overridden by testcases for their pleasure
883 getcodenamefromsuite
() {
885 unstable
) echo 'sid';;
889 getreleaseversionfromsuite
() { true
; }
890 getlabelfromsuite
() { true
; }
891 getoriginfromsuite
() { true
; }
893 generatereleasefiles
() {
894 # $1 is the Date header and $2 is the ValidUntil header to be set
895 # both should be given in notation date/touch can understand
896 msgninfo
"\tGenerate Release files… "
897 if [ -e aptarchive
/dists
]; then
898 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
899 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
900 local CODENAME
="$(getcodenamefromsuite $SUITE)"
901 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
902 local LABEL
="$(getlabelfromsuite $SUITE)"
903 local ORIGIN
="$(getoriginfromsuite $SUITE)"
904 if [ -n "$VERSION" ]; then
905 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
907 if [ -n "$LABEL" ]; then
908 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
910 if [ -n "$ORIGIN" ]; then
911 ORIGIN
="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
913 aptftparchive
-qq release
$dir \
914 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
915 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
919 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
920 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
922 NotAutomatic: yes' $dir/Release
924 if [ -n "$1" -a "$1" != "now" ]; then
925 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
929 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
933 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
935 if [ -n "$1" -a "$1" != "now" ]; then
936 for release
in $(find ./aptarchive -name 'Release'); do
937 touch -d "$1" $release
943 setupdistsaptarchive
() {
944 local APTARCHIVE
=$(readlink -f ./aptarchive)
945 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
946 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
947 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
948 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
949 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
950 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
951 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
956 setupflataptarchive
() {
957 local APTARCHIVE
=$(readlink -f ./aptarchive)
958 if [ -f ${APTARCHIVE}/Packages
]; then
959 msgninfo
"\tadd deb sources.list line… "
960 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
963 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
965 if [ -f ${APTARCHIVE}/Sources
]; then
966 msgninfo
"\tadd deb-src sources.list line… "
967 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
970 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
976 if [ "$1" = '--no-update' ]; then
981 if [ -e aptarchive
/dists
]; then
986 signreleasefiles
'Joe Sixpack'
987 if [ "1" != "$NOUPDATE" ]; then
988 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
993 local SIGNER
="${1:-Joe Sixpack}"
994 local REPODIR
="${2:-aptarchive}"
995 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
996 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
997 msgninfo
"\tSign archive with $SIGNER key $KEY… "
998 local REXKEY
='keys/rexexpired'
999 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1000 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1001 if [ "${SIGNER}" = 'Rex Expired' ]; then
1002 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1003 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1004 # therefore we 'temporary' make the key not expired and restore a backup after signing
1005 cp ${REXKEY}.sec
$SECEXPIREBAK
1006 cp ${REXKEY}.pub
$PUBEXPIREBAK
1007 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1008 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1009 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1010 cp $SECUNEXPIRED ${REXKEY}.sec
1011 cp $PUBUNEXPIRED ${REXKEY}.pub
1013 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1017 cp ${REXKEY}.sec
$SECUNEXPIRED
1018 cp ${REXKEY}.pub
$PUBUNEXPIRED
1021 for RELEASE
in $(find ${REPODIR}/ -name Release); do
1022 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
1023 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1024 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
1025 # we might have set a specific date for the Release file, so copy it
1026 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
1028 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1029 mv -f $SECEXPIREBAK ${REXKEY}.sec
1030 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1035 redatereleasefiles
() {
1036 local DATE
="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1037 for release
in $(find aptarchive/ -name 'Release'); do
1038 sed -i "s/^Date: .*$/Date: ${DATE}/" $release
1039 touch -d "$DATE" $release
1041 signreleasefiles
"${2:-Joe Sixpack}"
1045 local WEBSERVER
="${3:-http://localhost:8080}"
1047 if [ "$1" = '--no-check' ]; then
1051 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1052 local STATUS
='downloaded/webserverconfig.status'
1053 rm -f "$STATUS" "$DOWNLOG"
1055 if [ -n "$2" ]; then
1056 msgtest
"Set webserver config option '${1}' to" "$2"
1057 URI
="${WEBSERVER}/_config/set/${1}/${2}"
1059 msgtest
'Clear webserver config option' "${1}"
1060 URI
="${WEBSERVER}/_config/clear/${1}"
1062 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1065 cat "$DOWNLOG" "$STATUS" || true
1068 $NOCHECK || testwebserverlaststatuscode
'200'
1071 rewritesourceslist
() {
1072 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1073 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1074 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
1078 # wait for up to 10s for a pid file to appear to avoid possible race
1079 # when a helper is started and dosn't write the PID quick enough
1082 for i
in $(seq 10); do
1083 if test -s "$PIDFILE"; then
1088 msgdie
"waiting for $PIDFILE failed"
1092 changetowebserver
() {
1093 if [ "$1" != '--no-rewrite' ]; then
1094 rewritesourceslist
'http://localhost:8080/'
1098 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1100 local LOG
="webserver.log"
1101 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1105 waitforpidfile aptwebserver.pid
1106 local PID
="$(cat aptwebserver.pid)"
1107 if [ -z "$PID" ]; then
1108 msgdie
'Could not fork aptwebserver successfully'
1110 addtrap
"kill $PID;"
1113 msgdie
'You have to build aptwerbserver or install a webserver'
1117 changetohttpswebserver
() {
1118 if ! which stunnel4
>/dev
/null
; then
1119 msgdie
'You need to install stunnel4 for https testcases'
1121 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1122 changetowebserver
--no-rewrite "$@"
1124 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1125 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1131 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1132 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1133 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1134 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1135 if [ -z "$PID" ]; then
1136 msgdie
'Could not fork stunnel4 successfully'
1138 addtrap
'prefix' "kill ${PID};"
1139 rewritesourceslist
'https://localhost:4433/'
1143 mkdir -p rootdir
/media
/cdrom
/.disk
1144 local CD
="$(readlink -f rootdir/media/cdrom)"
1145 echo "acquire::cdrom::mount \"${CD}\";
1146 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1147 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1148 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1149 echo -n "$1" > ${CD}/.disk
/info
1150 if [ ! -d aptarchive
/dists
]; then
1151 msgdie
'Flat file archive cdroms can not be created currently'
1154 mv aptarchive
/dists
"$CD"
1155 ln -s "$(readlink -f ./incoming)" $CD/pool
1156 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1157 # start with an unmounted disk
1158 mv "${CD}" "${CD}-unmounted"
1159 # we don't want the disk to be modifiable
1160 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1161 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1165 local PROTO
="${1%%:*}"
1166 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1167 download
-file "$1" "$2" "$3" 2>&1 ; then
1170 # only if the file exists the download was successful
1171 if [ -r "$2" ]; then
1179 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1180 if [ -n "$DIFFTEXT" ]; then
1182 echo >&2 "$DIFFTEXT"
1192 msgtest
"Test for correctness of file" "$FILE"
1193 if [ -z "$*" ]; then
1194 echo -n "" | checkdiff
- $FILE && msgpass
|| msgfail
1196 echo "$*" | checkdiff
- $FILE && msgpass
|| msgfail
1201 msgtest
"Test for no output of" "$*"
1202 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1203 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1210 aptautotest
'testempty' "$@"
1214 local MSG
='Test of equality of'
1215 if [ "$1" = '--nomsg' ]; then
1220 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1221 echo "$1" > $COMPAREFILE
1224 if [ -n "$MSG" ]; then
1227 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1228 aptautotest
'testequal' "$@"
1232 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1233 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1234 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1235 echo "$1" > $COMPAREFILE1
1236 echo "$2" > $COMPAREFILE2
1238 msgtest
"Test for equality OR of" "$*"
1239 "$@" >$COMPAREAGAINST 2>&1 || true
1240 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1241 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1245 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1246 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1247 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1248 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1251 aptautotest
'testequalor2' "$@"
1255 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1258 while [ -n "$1" ]; do
1260 N: Can't select versions from package '$1' as it is purely virtual"
1261 PACKAGE
="${PACKAGE} $1"
1264 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1266 N: No packages found"
1267 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1268 local ARCH
="$(getarchitecture 'native')"
1269 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1270 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1274 msgtest
"Test for non-existent packages" "apt-cache show $*"
1275 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1276 if [ -n "$SHOWPKG" ]; then
1289 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1290 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1291 if [ "$PKGS" != $NR ]; then
1293 dpkg
-l "$@" | grep '^[a-z]' >&2
1300 testdpkginstalled
() {
1301 testdpkgstatus
'ii' "$#" "$@"
1304 testdpkgnotinstalled
() {
1305 testdpkgstatus
'ii' '0' "$@"
1309 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1310 if [ -n "$1" ]; then
1311 msgtest
'Test for correctly marked as auto-installed' "$*"
1312 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1314 msgtest
'Test for correctly marked as auto-installed' 'no package'
1315 echo -n > $COMPAREFILE
1317 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1325 if [ "$1" = 'grep' ]; then
1326 while [ -n "$2" ]; do shift; done
1327 echo "#### Complete file: $1 ####"
1328 cat >&2 "$1" || true
1329 echo '#### grep output ####'
1330 elif [ "$1" = 'test' ]; then
1331 # doesn't support ! or non-file flags
1332 msgfailoutputstatfile
() {
1333 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1334 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1335 echo "#### stat(2) of file: $2 ####"
1339 msgfailoutputstatfile
"$2" "$3"
1340 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1342 msgfailoutputstatfile
"$2" "$3"
1344 echo '#### test output ####'
1351 if [ "$1" = '--nomsg' ]; then
1354 msgtest
'Test for successful execution of' "$*"
1356 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1357 if "$@" >${OUTPUT} 2>&1; then
1358 if expr match
"$1" '^apt.*' >/dev
/null
; then
1359 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1360 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1361 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1362 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1371 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1373 aptautotest
'testsuccess' "$@"
1376 if [ "$1" = '--nomsg' ]; then
1379 msgtest
'Test for successful execution with warnings of' "$*"
1381 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1382 if "$@" >${OUTPUT} 2>&1; then
1383 if expr match
"$1" '^apt.*' >/dev
/null
; then
1384 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1385 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1386 elif grep -q -E '^E: ' "$OUTPUT"; then
1387 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1388 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1389 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1400 msgfail
"exitcode $EXITCODE"
1402 aptautotest
'testwarning' "$@"
1405 if [ "$1" = '--nomsg' ]; then
1408 msgtest
'Test for failure in execution of' "$*"
1410 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1411 if "$@" >${OUTPUT} 2>&1; then
1413 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1416 if expr match
"$1" '^apt.*' >/dev
/null
; then
1417 if [ "$1" = 'aptkey' ]; then
1418 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1419 grep -q -E " BAD signature from " "$OUTPUT"; then
1422 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1425 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1426 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1427 elif grep -q -E '==ERROR' "$OUTPUT"; then
1428 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1429 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1430 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1439 aptautotest
'testfailure' "$@"
1442 testsuccessequal
() {
1446 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
1448 testwarningequal
() {
1452 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
1454 testfailureequal
() {
1458 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
1465 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1466 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output" 2>&1 || true
1467 if echo "$CMP" | checkdiff
- "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output"; then
1470 echo '### Complete output ###'
1471 cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1477 msgtest
"Test that file $1 has $2 $3" "$4"
1478 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1482 ls -ld >&2 "$1" || true
1483 echo -n >&2 "stat(1) reports for $2: "
1484 stat
--format "$2" "$1" || true
1488 testaccessrights
() {
1489 testfilestats
"$1" '%a' '=' "$2"
1492 testwebserverlaststatuscode
() {
1493 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1494 local STATUS
='downloaded/webserverstatus-statusfile.log'
1495 rm -f "$DOWNLOG" "$STATUS"
1496 msgtest
'Test last status code from the webserver was' "$1"
1497 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1501 if [ -n "$2" ]; then
1503 echo >&2 '#### Additionally provided output files contain:'
1506 echo >&2 '#### Download log of the status code:'
1508 msgfail
"Status was $(cat "$STATUS")"
1513 echo "STOPPED execution. Press enter to continue"
1518 listcurrentlistsdirectory
() {
1520 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1521 stat
--format '%U:%G:%a:%n' "$line"
1523 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1524 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1529 ### convinience hacks ###
1531 # creating some directories by hand is a tedious task, so make it look simple
1532 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1533 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1534 # only the last directory created by mkdir is effected by the -m !
1535 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1536 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1537 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1538 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1539 if [ "$(id -u)" = '0' ]; then
1540 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1547 ### The following tests are run by most test methods automatically to check
1548 ### general things about commands executed without writing the test every time.
1554 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1555 if command -v $AUTOTEST >/dev
/null
; then
1557 # save and restore the *.output files from other tests
1558 # as we might otherwise override them in these automatic tests
1559 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1560 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1561 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1562 $AUTOTEST "$TESTCALL" "$@"
1563 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1564 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1565 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1569 aptautotest_aptget_update
() {
1571 while [ -n "$2" ]; do
1572 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1575 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1576 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1577 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1578 # all copied files are properly chmodded
1579 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1580 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1582 if [ "$TESTCALL" = 'testsuccess' ]; then
1583 # failure cases can retain partial files and such
1584 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1587 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1588 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1590 testaptautotestnodpkgwarning
() {
1592 while [ -n "$2" ]; do
1593 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1594 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1597 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1600 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1601 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1602 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1603 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1604 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1605 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }