1 #!/bin/sh -- # no runable script, just for vi
5 # we all like colorful messages
6 if [ "$MSGCOLOR" != 'NO' ]; then
7 if [ ! -t 1 ]; then # but check that we output to a terminal
13 if [ "$MSGCOLOR" != 'NO' ]; then
14 CERROR
="\033[1;31m" # red
15 CWARNING
="\033[1;33m" # yellow
16 CMSG
="\033[1;32m" # green
17 CINFO
="\033[1;96m" # light blue
18 CDEBUG
="\033[1;94m" # blue
19 CNORMAL
="\033[0;39m" # default system console color
20 CDONE
="\033[1;32m" # green
21 CPASS
="\033[1;32m" # green
22 CFAIL
="\033[1;31m" # red
23 CCMD
="\033[1;35m" # pink
35 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')"
41 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
42 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
43 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
44 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
45 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
46 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
47 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
48 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
49 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
50 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
51 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
52 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
54 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
55 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
58 if [ $# -gt 0 ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
59 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
60 if [ -n "$APT_DEBUG_TESTS" ]; then
63 EXIT_CODE
=$((EXIT_CODE+1));
66 # enable / disable Debugging
67 MSGLEVEL
=${MSGLEVEL:-3}
68 if [ $MSGLEVEL -le 0 ]; then
71 if [ $MSGLEVEL -le 1 ]; then
75 if [ $MSGLEVEL -le 2 ]; then
79 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
81 if [ $MSGLEVEL -le 3 ]; then
85 if [ $MSGLEVEL -le 4 ]; then
90 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
91 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
92 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
93 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
94 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
97 printf "${CDONE}DONE${CNORMAL}\n";
101 if [ -f .
/aptconfig.conf
]; then
102 echo "./aptconfig.conf"
103 elif [ -f ..
/aptconfig.conf
]; then
104 echo "../aptconfig.conf"
108 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
112 sh
|aptitude
|*/*|command) ;;
113 *) CMD
="${BUILDDIRECTORY}/$CMD";;
115 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${LIBRARYPATH} $CMD "$@"
117 aptconfig
() { runapt apt
-config "$@"; }
118 aptcache
() { runapt apt
-cache "$@"; }
119 aptcdrom
() { runapt apt
-cdrom "$@"; }
120 aptget
() { runapt apt
-get "$@"; }
121 aptftparchive
() { runapt apt
-ftparchive "$@"; }
122 aptkey
() { runapt apt
-key "$@"; }
123 aptmark
() { runapt apt
-mark "$@"; }
124 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
125 apt
() { runapt apt
"$@"; }
126 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
127 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
128 aptitude
() { runapt aptitude
"$@"; }
129 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
130 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
131 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
134 command dpkg
--root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
"$@"
136 dpkgcheckbuilddeps
() {
137 command dpkg
-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
"$@"
142 runapt
command gdb
--quiet -ex run
"${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
146 # error if we about to overflow, but ...
147 # "255 failures ought to be enough for everybody"
148 if [ $EXIT_CODE -gt 255 ]; then
149 msgdie
"Total failure count $EXIT_CODE too big"
151 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
154 shellsetedetector
() {
156 if [ "$exit_status" != '0' ]; then
157 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
158 if [ "$EXIT_CODE" = '0' ]; then
159 EXIT_CODE
="$exit_status"
165 if [ "$1" = 'prefix' ]; then
166 CURRENTTRAP
="$2 $CURRENTTRAP"
168 CURRENTTRAP
="$CURRENTTRAP $1"
170 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
174 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
175 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
178 TMPWORKINGDIRECTORY
=$(mktemp -d)
179 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
180 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
182 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
183 if [ "$(id -u)" = '0' ]; then
184 # relax permissions so that running as root with user switching works
186 chmod 711 "$TMPWORKINGDIRECTORY"
187 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
190 TESTDIRECTORY
=$(readlink -f $(dirname $0))
191 # allow overriding the default BUILDDIR location
192 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
193 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
194 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
195 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
196 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
197 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
198 APTDUMPSOLVER
=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}
199 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
202 cd $TMPWORKINGDIRECTORY
203 mkdir rootdir aptarchive keys
205 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
206 mkdir -p usr
/bin var
/cache var
/lib var
/log tmp
207 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
208 touch var
/lib
/dpkg
/available
210 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
211 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
212 mkdir -p usr
/lib
/apt
/solvers
213 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
214 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
215 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
217 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
219 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
220 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
222 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
225 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
226 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
227 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
229 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
230 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
231 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
233 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
234 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
235 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
237 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
238 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
239 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
240 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
241 # store apt-key were we can access it, even if we run it as a different user
242 # destroys coverage reporting though, so just do it for root for now
243 if [ "$(id -u)" = '0' ]; then
244 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
245 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
246 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
248 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
250 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
251 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
252 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
253 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
254 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
255 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
256 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
258 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
259 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
260 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
261 # too distracting for users, but helpful to detect changes
262 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
263 # in testcases, it can appear as if localhost has a rotation setup,
264 # hide this as we can't really deal with it properly
265 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
267 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
268 if [ "$(id -u)" = '0' ]; then
269 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
271 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
272 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
273 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
275 # create some files in /tmp and look at user/group to get what this means
276 TEST_DEFAULT_USER
="$USER"
277 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
278 TEST_DEFAULT_GROUP
='root'
280 TEST_DEFAULT_GROUP
="$USER"
283 # Acquire::AllowInsecureRepositories=false is not yet the default
284 # but we want it to be the default soon
285 configallowinsecurerepositories
"false";
287 # cleanup the environment a bit
288 # prefer our apt binaries over the system apt binaries
289 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
290 export LC_ALL
=C.UTF
-8
291 unset LANGUAGE APT_CONFIG
292 unset GREP_OPTIONS DEB_BUILD_PROFILES
298 if [ "$1" = "native" -o -z "$1" ]; then
299 eval `aptconfig shell ARCH APT::Architecture`
300 if [ -n "$ARCH" ]; then
303 dpkg
--print-architecture
311 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
314 getarchitecturesfromcommalist
() {
315 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
318 configarchitecture
() {
320 echo "APT::Architecture \"$(getarchitecture $1)\";"
321 while [ -n "$1" ]; do
322 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
325 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
330 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
331 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
332 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
333 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
335 echo -n > rootdir/var/lib/dpkg/status
338 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
339 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
340 local ARCHS="$(getarchitectures)"
341 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
342 DPKGARCH="$(dpkg --print-architecture)"
343 for ARCH in ${ARCHS}; do
344 if [ "${ARCH}" != "${DPKGARCH}" ]; then
345 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
346 # old-style used e.g. in Ubuntu-P – and as it seems travis
347 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
348 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
352 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
353 # dpkg doesn't really check the version as long as it is fully installed,
354 # but just to be sure we choose one above the required version
355 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
361 configdpkgnoopchroot() {
362 # create a library to noop chroot() and rewrite maintainer script executions
363 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
364 # chroot directory dpkg could chroot into to execute the maintainer scripts
365 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
366 cat << EOF > noopchroot.c
373 static char * chrootdir = NULL;
375 int chroot(const char *path) {
376 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
378 chrootdir = strdup(path);
381 int execvp(const char *file, char *const argv[]) {
382 static int (*func_execvp) (const char *, char * const []) = NULL;
383 if (func_execvp == NULL)
384 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
385 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
386 return func_execvp(file, argv);
387 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
388 char newfile[strlen(chrootdir) + strlen(file)];
389 strcpy(newfile, chrootdir);
390 strcat(newfile, file);
391 return func_execvp(newfile, argv);
394 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
396 mkdir -p "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
397 DPKG="${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
"
399 if [ -n \"\
$LD_PRELOAD\" ]; then
400 export LD_PRELOAD
=\"${TMPWORKINGDIRECTORY}/noopchroot.so \
${LD_PRELOAD}\"
402 export LD_PRELOAD
=\"${TMPWORKINGDIRECTORY}/noopchroot.so
\"
404 dpkg
\"\$@
\"" > $DPKG
406 sed -ie "s
|^DPKG
::options
:: \"dpkg
\";\$
|DPKG
::options
:: \"$DPKG\";|" aptconfig.conf
409 configallowinsecurerepositories() {
410 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
414 configcompression() {
415 while [ -n "$1" ]; do
417 '.') printf ".
\t.
\tcat
\n";;
418 'gz') printf "gzip\tgz
\tgzip
\n";;
419 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
420 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
421 'xz') printf "xz
\txz
\txz
\n";;
422 *) printf "$1\t$1\t$1\n";;
425 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
432 gzip) COMPRESS='gz';;
433 bzip2) COMPRESS='bz2';;
434 lzma) COMPRESS='lzma';;
436 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
438 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
439 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
440 Dir::Bin::uncompressed \"/does/not/exist\";
441 Dir::Bin::gzip \"/does/not/exist\";
442 Dir::Bin::bzip2 \"/does/not/exist\";
443 Dir::Bin::lzma \"/does/not/exist\";
444 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
445 if [ -e "/bin/${COMPRESSOR}" ]; then
446 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
447 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
448 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
449 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
450 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
451 COMPRESSOR_CMD='xz
--format=lzma
'
453 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
458 setupsimplenativepackage() {
462 local RELEASE="${4:-unstable}"
463 local DEPENDENCIES="$5"
464 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
465 If you find such a package installed on your system,
466 something went horribly wrong! They are autogenerated
467 und used only by testcases and surf no other propose…"}"
469 local SECTION="${7:-others}"
471 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
474 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
476 local BUILDDIR=incoming/${NAME}-${VERSION}
477 mkdir -p ${BUILDDIR}/debian/source
479 echo "* most suckless software product ever" > FEATURES
480 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
481 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
485 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
486 test -e debian/control || echo "Source: $NAME
489 Maintainer: Joe Sixpack <joe@example.org>
490 Build-Depends: debhelper (>= 7)
491 Standards-Version: 3.9.1
493 Package: $NAME" > debian/control
494 if [ "$ARCH" = 'all
' ]; then
495 echo "Architecture: all" >> debian/control
497 echo "Architecture: any" >> debian/control
499 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
500 echo "Description: $DESCRIPTION" >> debian/control
502 test -e debian/compat || echo "7" > debian/compat
503 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
504 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
508 buildsimplenativepackage() {
512 local RELEASE="${4:-unstable}"
513 local DEPENDENCIES="$5"
514 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
515 If you find such a package installed on your system,
516 something went horribly wrong! They are autogenerated
517 und used only by testcases and surf no other propose…"}"
519 local SECTION="${7:-others}"
520 local PRIORITY="${8:-optional}"
522 local COMPRESS_TYPE="${10:-gzip}"
524 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
527 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
529 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
531 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
532 mkdir -p $BUILDDIR/debian/source
533 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
535 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
537 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
538 echo "$NAME ($VERSION) $RELEASE; urgency=low
542 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
546 Maintainer: Joe Sixpack <joe@example.org>
547 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
548 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
549 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
551 Package: $NAME" >> ${BUILDDIR}/debian/control
553 if [ "$ARCH" = 'all
' ]; then
554 echo "Architecture: all" >> ${BUILDDIR}/debian/control
556 echo "Architecture: any" >> ${BUILDDIR}/debian/control
558 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
559 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
560 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
562 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
564 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
566 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
568 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
569 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
570 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
571 # adv --yes --default-key 'Joe Sixpack' \
572 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
573 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
577 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
578 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
579 rm -rf ${BUILDDIR}/debian
/tmp
580 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
581 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
582 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
583 if [ -n "$FILE_TREE" ]; then
584 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
587 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
588 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
589 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
590 # ensure the right permissions as dpkg-deb ensists
591 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
592 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
593 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
596 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
597 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
598 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
607 local ARCH
=$(getarchitecture $4)
608 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
609 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
610 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
612 if [ "$ARCH" = "all" ]; then
613 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
615 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
616 cp ${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
$BUILDLOG
617 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
618 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
621 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
624 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
629 if [ -d incoming
]; then
630 buildaptarchivefromincoming
"$@"
632 buildaptarchivefromfiles
"$@"
636 createaptftparchiveconfig
() {
637 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
638 local COMPRESSORS
="${COMPRESSORS%* }"
639 local ARCHS
="$(getarchitectures)"
641 ArchiveDir "' >> ftparchive.conf
642 echo -n $(readlink -f .) >> ftparchive.conf
644 CacheDir "' >> ftparchive.conf
645 echo -n $(readlink -f ..) >> ftparchive.conf
647 FileListDir "' >> ftparchive.conf
648 echo -n $(readlink -f pool/) >> ftparchive.conf
652 Packages::Compress "'"$COMPRESSORS"'";
653 Sources::Compress "'"$COMPRESSORS"'";
654 Contents::Compress "'"$COMPRESSORS"'";
655 Translation::Compress "'"$COMPRESSORS"'";
656 LongDescription "false";
660 SrcDirectory "pool/";
666 Label "apttestcases";
668 Description "repository with dummy packages";
669 Architectures "' >> ftparchive.conf
670 echo -n "$ARCHS" >> ftparchive.conf
674 };' >> ftparchive.conf
675 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
676 echo -n 'tree "dists/' >> ftparchive.conf
677 echo -n "$DIST" >> ftparchive.conf
679 Architectures "' >> ftparchive.conf
680 echo -n "$ARCHS" >> ftparchive.conf
682 FileList "' >> ftparchive.conf
683 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
685 SourceFileList "' >> ftparchive.conf
686 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
688 Sections "' >> ftparchive.conf
689 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
691 };' >> ftparchive.conf
695 buildaptftparchivedirectorystructure
() {
696 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
697 for DIST
in $DISTS; do
698 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
699 for SECTION
in $SECTIONS; do
700 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
701 for ARCH
in $ARCHS; do
702 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
704 mkdir -p dists
/${DIST}/${SECTION}/source
705 mkdir -p dists
/${DIST}/${SECTION}/i18n
715 local DEPENDENCIES
="$5"
716 local PRIORITY
="${6:-optional}"
717 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
718 If you find such a package installed on your system,
719 something went horribly wrong! They are autogenerated
720 und used only by testcases and surf no other propose…"}"
722 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
723 if [ "$RELEASE" = 'installed' ]; then
724 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
727 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
728 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
729 ARCHS="$(getarchitectures)"
733 for BUILDARCH in $ARCHS; do
734 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
736 local FILE="${PPATH}/Packages
"
741 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
742 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
743 echo "Version
: $VERSION
744 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
745 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
746 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
747 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
751 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
752 touch aptarchive/dists/${RELEASE}/main/source/Sources
754 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
755 Description
-en: $DESCRIPTION
756 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
765 local DEPENDENCIES="$5"
767 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
769 local FILE="${SPATH}/Sources
"
773 Maintainer
: Joe Sixpack
<joe@example.org
>
774 Architecture
: $ARCH" >> $FILE
775 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
777 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
778 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
782 insertinstalledpackage() {
786 local DEPENDENCIES="$4"
787 local PRIORITY="${5:-optional}"
788 local STATUS="${6:-install ok installed}"
789 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
790 If you
find such a package installed on your system
,
791 something went horribly wrong
! They are autogenerated
792 und used only by testcases and surf no other propose…
"}"
794 local FILE
='rootdir/var/lib/dpkg/status'
795 local INFO
='rootdir/var/lib/dpkg/info'
796 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
802 Maintainer: Joe Sixpack <joe@example.org>
803 Version: $VERSION" >> $FILE
804 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
805 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
806 echo "Description: $DESCRIPTION" >> $FILE
808 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
809 echo -n > ${INFO}/${NAME}:${arch}.list
811 echo -n > ${INFO}/${NAME}.list
817 buildaptarchivefromincoming
() {
818 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
820 [ -e pool
] || ln -s ..
/incoming pool
821 [ -e ftparchive.conf
] || createaptftparchiveconfig
822 [ -e dists
] || buildaptftparchivedirectorystructure
823 msgninfo
"\tGenerate Packages, Sources and Contents files… "
824 aptftparchive
-qq generate ftparchive.conf
827 generatereleasefiles
"$@"
830 buildaptarchivefromfiles
() {
831 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
832 find aptarchive
-name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
833 msgninfo
"\t${line} file… "
834 compressfile
"$line" "$1"
837 generatereleasefiles
"$@"
841 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
842 if [ "$compressor" = '.' ]; then
848 cat "$1" | $command > "${1}.${extension}"
850 touch -d "$2" "${1}.${extension}"
855 # can be overridden by testcases for their pleasure
856 getcodenamefromsuite
() {
858 unstable
) echo 'sid';;
862 getreleaseversionfromsuite
() { true
; }
863 getlabelfromsuite
() { true
; }
865 generatereleasefiles
() {
866 # $1 is the Date header and $2 is the ValidUntil header to be set
867 # both should be given in notation date/touch can understand
868 msgninfo
"\tGenerate Release files… "
869 if [ -e aptarchive
/dists
]; then
870 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
871 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
872 local CODENAME
="$(getcodenamefromsuite $SUITE)"
873 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
874 local LABEL
="$(getlabelfromsuite $SUITE)"
875 if [ -n "$VERSION" ]; then
876 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
878 if [ -n "$LABEL" ]; then
879 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
881 aptftparchive
-qq release
$dir \
882 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
883 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
886 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
887 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
889 NotAutomatic: yes' $dir/Release
891 if [ -n "$1" -a "$1" != "now" ]; then
892 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
896 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
900 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
902 if [ -n "$1" -a "$1" != "now" ]; then
903 for release
in $(find ./aptarchive -name 'Release'); do
904 touch -d "$1" $release
910 setupdistsaptarchive
() {
911 local APTARCHIVE
=$(readlink -f ./aptarchive)
912 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
913 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
914 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
915 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
916 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
917 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
918 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
923 setupflataptarchive
() {
924 local APTARCHIVE
=$(readlink -f ./aptarchive)
925 if [ -f ${APTARCHIVE}/Packages
]; then
926 msgninfo
"\tadd deb sources.list line… "
927 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
930 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
932 if [ -f ${APTARCHIVE}/Sources
]; then
933 msgninfo
"\tadd deb-src sources.list line… "
934 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
937 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
943 if [ "$1" = '--no-update' ]; then
948 if [ -e aptarchive
/dists
]; then
953 signreleasefiles
'Joe Sixpack'
954 if [ "1" != "$NOUPDATE" ]; then
955 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
960 local SIGNER
="${1:-Joe Sixpack}"
961 local REPODIR
="${2:-aptarchive}"
962 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
963 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
964 msgninfo
"\tSign archive with $SIGNER key $KEY… "
965 local REXKEY
='keys/rexexpired'
966 local SECEXPIREBAK
="${REXKEY}.sec.bak"
967 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
968 if [ "${SIGNER}" = 'Rex Expired' ]; then
969 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
970 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
971 # therefore we 'temporary' make the key not expired and restore a backup after signing
972 cp ${REXKEY}.sec
$SECEXPIREBAK
973 cp ${REXKEY}.pub
$PUBEXPIREBAK
974 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
975 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
976 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
977 cp $SECUNEXPIRED ${REXKEY}.sec
978 cp $PUBUNEXPIRED ${REXKEY}.pub
980 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
984 cp ${REXKEY}.sec
$SECUNEXPIRED
985 cp ${REXKEY}.pub
$PUBUNEXPIRED
988 for RELEASE
in $(find ${REPODIR}/ -name Release); do
989 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
990 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
991 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
992 # we might have set a specific date for the Release file, so copy it
993 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
995 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
996 mv -f $SECEXPIREBAK ${REXKEY}.sec
997 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1004 if [ "$1" = '--no-check' ]; then
1008 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1009 local STATUS
='downloaded/webserverconfig.status'
1010 rm -f "$STATUS" "$DOWNLOG"
1012 if [ -n "$2" ]; then
1013 msgtest
"Set webserver config option '${1}' to" "$2"
1014 URI
="http://localhost:8080/_config/set/${1}/${2}"
1016 msgtest
'Clear webserver config option' "${1}"
1017 URI
="http://localhost:8080/_config/clear/${1}"
1019 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1022 cat "$DOWNLOG" "$STATUS" || true
1025 $NOCHECK || testwebserverlaststatuscode
'200'
1028 rewritesourceslist
() {
1029 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1030 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1031 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
1035 # wait for up to 10s for a pid file to appear to avoid possible race
1036 # when a helper is started and dosn't write the PID quick enough
1039 for i
in $(seq 10); do
1040 if test -s "$PIDFILE"; then
1045 msgdie
"waiting for $PIDFILE failed"
1049 changetowebserver
() {
1050 if [ "$1" != '--no-rewrite' ]; then
1051 rewritesourceslist
'http://localhost:8080/'
1055 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1057 local LOG
="webserver.log"
1058 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1062 waitforpidfile aptwebserver.pid
1063 local PID
="$(cat aptwebserver.pid)"
1064 if [ -z "$PID" ]; then
1065 msgdie
'Could not fork aptwebserver successfully'
1067 addtrap
"kill $PID;"
1070 msgdie
'You have to build aptwerbserver or install a webserver'
1074 changetohttpswebserver
() {
1075 if ! which stunnel4
>/dev
/null
; then
1076 msgdie
'You need to install stunnel4 for https testcases'
1078 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1079 changetowebserver
--no-rewrite "$@"
1081 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1082 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1088 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1089 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1090 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1091 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1092 if [ -z "$PID" ]; then
1093 msgdie
'Could not fork stunnel4 successfully'
1095 addtrap
'prefix' "kill ${PID};"
1096 rewritesourceslist
'https://localhost:4433/'
1100 mkdir -p rootdir
/media
/cdrom
/.disk
1101 local CD
="$(readlink -f rootdir/media/cdrom)"
1102 echo "acquire::cdrom::mount \"${CD}\";
1103 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1104 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1105 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1106 echo -n "$1" > ${CD}/.disk
/info
1107 if [ ! -d aptarchive
/dists
]; then
1108 msgdie
'Flat file archive cdroms can not be created currently'
1111 mv aptarchive
/dists
"$CD"
1112 ln -s "$(readlink -f ./incoming)" $CD/pool
1113 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1114 # start with an unmounted disk
1115 mv "${CD}" "${CD}-unmounted"
1116 # we don't want the disk to be modifiable
1117 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1118 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1122 local PROTO
="${1%%:*}"
1123 apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1124 download
-file "$1" "$2" 2>&1 || true
1125 # only if the file exists the download was successful
1126 if [ -r "$2" ]; then
1134 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1135 if [ -n "$DIFFTEXT" ]; then
1137 echo >&2 "$DIFFTEXT"
1147 msgtest
"Test for correctness of file" "$FILE"
1148 if [ -z "$*" ]; then
1149 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1151 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1156 msgtest
"Test for no output of" "$*"
1157 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1158 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1165 aptautotest
'testempty' "$@"
1169 local MSG
='Test of equality of'
1170 if [ "$1" = '--nomsg' ]; then
1175 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1176 echo "$1" > $COMPAREFILE
1179 if [ -n "$MSG" ]; then
1182 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1183 aptautotest
'testequal' "$@"
1187 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1188 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1189 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1190 echo "$1" > $COMPAREFILE1
1191 echo "$2" > $COMPAREFILE2
1193 msgtest
"Test for equality OR of" "$*"
1194 "$@" >$COMPAREAGAINST 2>&1 || true
1195 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1196 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1200 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1201 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1202 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1203 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1206 aptautotest
'testequalor2' "$@"
1210 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1213 while [ -n "$1" ]; do
1215 N: Can't select versions from package '$1' as it is purely virtual"
1216 PACKAGE
="${PACKAGE} $1"
1219 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1221 N: No packages found"
1222 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1223 local ARCH
="$(getarchitecture 'native')"
1224 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1225 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1229 msgtest
"Test for non-existent packages" "apt-cache show $*"
1230 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1231 if [ -n "$SHOWPKG" ]; then
1244 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1245 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1246 if [ "$PKGS" != $NR ]; then
1248 dpkg
-l "$@" | grep '^[a-z]' >&2
1255 testdpkginstalled
() {
1256 testdpkgstatus
'ii' "$#" "$@"
1259 testdpkgnotinstalled
() {
1260 testdpkgstatus
'ii' '0' "$@"
1264 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1265 if [ -n "$1" ]; then
1266 msgtest
'Test for correctly marked as auto-installed' "$*"
1267 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1269 msgtest
'Test for correctly marked as auto-installed' 'no package'
1270 echo -n > $COMPAREFILE
1272 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1280 if [ "$1" = 'grep' ]; then
1281 while [ -n "$2" ]; do shift; done
1282 echo "#### Complete file: $1 ####"
1283 cat >&2 "$1" || true
1284 echo '#### grep output ####'
1285 elif [ "$1" = 'test' ]; then
1286 # doesn't support ! or non-file flags
1287 msgfailoutputstatfile
() {
1288 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1289 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1290 echo "#### stat(2) of file: $2 ####"
1294 msgfailoutputstatfile
"$2" "$3"
1295 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1297 msgfailoutputstatfile
"$2" "$3"
1299 echo '#### test output ####'
1306 if [ "$1" = '--nomsg' ]; then
1309 msgtest
'Test for successful execution of' "$*"
1311 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1312 if "$@" >${OUTPUT} 2>&1; then
1313 if expr match
"$1" '^apt.*' >/dev
/null
; then
1314 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1315 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1316 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1317 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1326 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1328 aptautotest
'testsuccess' "$@"
1331 if [ "$1" = '--nomsg' ]; then
1334 msgtest
'Test for successful execution with warnings of' "$*"
1336 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1337 if "$@" >${OUTPUT} 2>&1; then
1338 if expr match
"$1" '^apt.*' >/dev
/null
; then
1339 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1340 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1341 elif grep -q -E '^E: ' "$OUTPUT"; then
1342 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1343 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1344 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1355 msgfail
"exitcode $EXITCODE"
1357 aptautotest
'testwarning' "$@"
1360 if [ "$1" = '--nomsg' ]; then
1363 msgtest
'Test for failure in execution of' "$*"
1365 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1366 if "$@" >${OUTPUT} 2>&1; then
1368 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1371 if expr match
"$1" '^apt.*' >/dev
/null
; then
1372 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1373 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1374 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1375 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1383 aptautotest
'testfailure' "$@"
1387 msgtest
"Test that file $1 has $2 $3" "$4"
1388 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1393 echo -n >&2 "stat(1) reports for $2: "
1394 stat
--format "$2" "$1"
1398 testaccessrights
() {
1399 testfilestats
"$1" '%a' '=' "$2"
1402 testwebserverlaststatuscode
() {
1403 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1404 local STATUS
='downloaded/webserverstatus-statusfile.log'
1405 rm -f "$DOWNLOG" "$STATUS"
1406 msgtest
'Test last status code from the webserver was' "$1"
1407 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1411 if [ -n "$2" ]; then
1413 echo >&2 '#### Additionally provided output files contain:'
1416 echo >&2 '#### Download log of the status code:'
1418 msgfail
"Status was $(cat "$STATUS")"
1423 echo "STOPPED execution. Press enter to continue"
1428 listcurrentlistsdirectory
() {
1429 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1430 stat
--format '%U:%G:%a:%n' "$line"
1432 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1433 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1437 ### convinience hacks ###
1439 # creating some directories by hand is a tedious task, so make it look simple
1440 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1441 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1442 # only the last directory created by mkdir is effected by the -m !
1443 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1444 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1445 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1446 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1447 if [ "$(id -u)" = '0' ]; then
1448 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1455 ### The following tests are run by most test methods automatically to check
1456 ### general things about commands executed without writing the test every time.
1462 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1463 if command -v $AUTOTEST >/dev
/null
; then
1465 # save and restore the *.output files from other tests
1466 # as we might otherwise override them in these automatic tests
1467 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1468 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1469 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1470 $AUTOTEST "$TESTCALL" "$@"
1471 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1472 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1473 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1477 aptautotest_aptget_update
() {
1478 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1479 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1480 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1481 # all copied files are properly chmodded
1482 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f ! -name 'lock'); do
1483 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1486 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1488 testaptautotestnodpkgwarning
() {
1490 while [ -n "$2" ]; do
1491 if [ "$2" = '-s' ]; then return; fi
1494 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1497 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1498 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1499 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1500 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1501 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1502 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }