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 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 SOURCEDIRECTORY
=${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}
193 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
194 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
195 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
196 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
197 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
198 APTINTERNALSOLVER
=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
199 APTDUMPSOLVER
=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}
200 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
203 cd $TMPWORKINGDIRECTORY
204 mkdir rootdir aptarchive keys
206 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
207 mkdir -p usr
/bin var
/cache var
/lib var
/log tmp
208 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
209 touch var
/lib
/dpkg
/available
211 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
212 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
213 mkdir -p usr
/lib
/apt
/solvers
214 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr
/lib
/apt
/solvers
/dump
215 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr
/lib
/apt
/solvers
/apt
216 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc
/apt
/apt.conf.d
/externalsolver.conf
218 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
220 if [ -e ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
]; then
221 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
223 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
226 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
227 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
228 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
230 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
231 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
232 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
234 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
235 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
236 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
238 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
239 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
240 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
241 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
242 # store apt-key were we can access it, even if we run it as a different user
243 # destroys coverage reporting though, so just do it for root for now
244 if [ "$(id -u)" = '0' ]; then
245 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
246 chmod o
+rx
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
247 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
249 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
252 cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
255 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
256 if [ -n "\$LD_PRELOAD" ]; then
257 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
259 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
262 exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
263 --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
264 --force-not-root --force-bad-path "\$@"
266 chmod +x
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
267 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
269 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
270 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
272 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
273 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
274 # too distracting for users, but helpful to detect changes
275 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
276 # in testcases, it can appear as if localhost has a rotation setup,
277 # hide this as we can't really deal with it properly
278 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
280 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
281 if [ "$(id -u)" = '0' ]; then
282 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
284 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
285 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
286 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
288 # create some files in /tmp and look at user/group to get what this means
289 TEST_DEFAULT_USER
="$USER"
290 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
291 TEST_DEFAULT_GROUP
='root'
293 TEST_DEFAULT_GROUP
="$USER"
296 # Acquire::AllowInsecureRepositories=false is not yet the default
297 # but we want it to be the default soon
298 configallowinsecurerepositories
"false";
300 # cleanup the environment a bit
301 # prefer our apt binaries over the system apt binaries
302 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
303 export LC_ALL
=C.UTF
-8
304 unset LANGUAGE APT_CONFIG
305 unset GREP_OPTIONS DEB_BUILD_PROFILES
311 if [ "$1" = "native" -o -z "$1" ]; then
312 eval `aptconfig shell ARCH APT::Architecture`
313 if [ -n "$ARCH" ]; then
316 dpkg
--print-architecture
324 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
327 getarchitecturesfromcommalist
() {
328 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
331 configarchitecture
() {
333 echo "APT::Architecture \"$(getarchitecture $1)\";"
334 while [ -n "$1" ]; do
335 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
338 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
343 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
344 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
345 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
346 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
348 echo -n > rootdir/var/lib/dpkg/status
351 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
352 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
353 local ARCHS="$(getarchitectures)"
354 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
355 DPKGARCH="$(dpkg --print-architecture)"
356 for ARCH in ${ARCHS}; do
357 if [ "${ARCH}" != "${DPKGARCH}" ]; then
358 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
359 # old-style used e.g. in Ubuntu-P – and as it seems travis
360 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
361 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
365 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
366 # dpkg doesn't really check the version as long as it is fully installed,
367 # but just to be sure we choose one above the required version
368 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
374 configdpkgnoopchroot() {
375 # create a library to noop chroot() and rewrite maintainer script executions
376 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
377 # chroot directory dpkg could chroot into to execute the maintainer scripts
378 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
379 cat << EOF > noopchroot.c
386 static char * chrootdir = NULL;
388 int chroot(const char *path) {
389 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
391 chrootdir = strdup(path);
394 int execvp(const char *file, char *const argv[]) {
395 static int (*func_execvp) (const char *, char * const []) = NULL;
396 if (func_execvp == NULL)
397 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
398 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
399 return func_execvp(file, argv);
400 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
401 char newfile[strlen(chrootdir) + strlen(file)];
402 strcpy(newfile, chrootdir);
403 strcat(newfile, file);
404 char const * const baseadmindir = "/var
/lib
/dpkg
";
405 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
406 strcpy(admindir, chrootdir);
407 strcat(admindir, baseadmindir);
408 setenv("DPKG_ADMINDIR
", admindir, 1);
409 return func_execvp(newfile, argv);
412 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
415 configallowinsecurerepositories() {
416 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
420 configcompression() {
421 while [ -n "$1" ]; do
423 '.') printf ".
\t.
\tcat
\n";;
424 'gz') printf "gzip\tgz
\tgzip
\n";;
425 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
426 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
427 'xz') printf "xz
\txz
\txz
\n";;
428 *) printf "$1\t$1\t$1\n";;
431 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
438 gzip) COMPRESS='gz';;
439 bzip2) COMPRESS='bz2';;
440 lzma) COMPRESS='lzma';;
442 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
444 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
445 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
446 Dir::Bin::uncompressed \"/does/not/exist\";
447 Dir::Bin::gzip \"/does/not/exist\";
448 Dir::Bin::bzip2 \"/does/not/exist\";
449 Dir::Bin::lzma \"/does/not/exist\";
450 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
451 if [ -e "/bin/${COMPRESSOR}" ]; then
452 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
453 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
454 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
455 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
456 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
457 COMPRESSOR_CMD='xz
--format=lzma
'
459 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
464 setupsimplenativepackage() {
468 local RELEASE="${4:-unstable}"
469 local DEPENDENCIES="$5"
470 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
471 If you find such a package installed on your system,
472 something went horribly wrong! They are autogenerated
473 und used only by testcases and surf no other propose…"}"
475 local SECTION="${7:-others}"
477 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
480 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
482 local BUILDDIR=incoming/${NAME}-${VERSION}
483 mkdir -p ${BUILDDIR}/debian/source
485 echo "* most suckless software product ever" > FEATURES
486 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
487 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
491 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
492 test -e debian/control || echo "Source: $NAME
495 Maintainer: Joe Sixpack <joe@example.org>
496 Build-Depends: debhelper (>= 7)
497 Standards-Version: 3.9.1
499 Package: $NAME" > debian/control
500 if [ "$ARCH" = 'all
' ]; then
501 echo "Architecture: all" >> debian/control
503 echo "Architecture: any" >> debian/control
505 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
506 echo "Description: $DESCRIPTION" >> debian/control
508 test -e debian/compat || echo "7" > debian/compat
509 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
510 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
514 buildsimplenativepackage() {
518 local RELEASE="${4:-unstable}"
519 local DEPENDENCIES="$5"
520 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
521 If you find such a package installed on your system,
522 something went horribly wrong! They are autogenerated
523 und used only by testcases and surf no other propose…"}"
525 local SECTION="${7:-others}"
526 local PRIORITY="${8:-optional}"
528 local COMPRESS_TYPE="${10:-gzip}"
530 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
533 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
535 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
537 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
538 mkdir -p $BUILDDIR/debian/source
539 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
541 echo '$NAME says
\"Hello
!\"'" > ${BUILDDIR}/${NAME}
543 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
544 echo "$NAME ($VERSION) $RELEASE; urgency=low
548 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
552 Maintainer: Joe Sixpack <joe@example.org>
553 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
554 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
555 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
557 Package: $NAME" >> ${BUILDDIR}/debian/control
559 if [ "$ARCH" = 'all
' ]; then
560 echo "Architecture: all" >> ${BUILDDIR}/debian/control
562 echo "Architecture: any" >> ${BUILDDIR}/debian/control
564 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
565 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
566 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
568 echo '3.0 (native
)' > ${BUILDDIR}/debian/source/format
570 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
572 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
574 echo "pool/${SRC}" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
575 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
576 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
577 # adv --yes --default-key 'Joe Sixpack' \
578 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
579 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
583 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
584 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
585 rm -rf ${BUILDDIR}/debian
/tmp
586 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
587 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
588 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
589 if [ -n "$FILE_TREE" ]; then
590 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
593 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
594 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
595 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
596 # ensure the right permissions as dpkg-deb ensists
597 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
598 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
599 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
602 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
603 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
604 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
613 local ARCH
=$(getarchitecture $4)
614 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
615 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
616 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
618 if [ "$ARCH" = "all" ]; then
619 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
621 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
622 cp ${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
$BUILDLOG
623 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
624 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
627 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
630 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
635 if [ -d incoming
]; then
636 buildaptarchivefromincoming
"$@"
638 buildaptarchivefromfiles
"$@"
642 createaptftparchiveconfig
() {
643 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
644 local COMPRESSORS
="${COMPRESSORS%* }"
645 local ARCHS
="$(getarchitectures)"
647 ArchiveDir "' >> ftparchive.conf
648 echo -n $(readlink -f .) >> ftparchive.conf
650 CacheDir "' >> ftparchive.conf
651 echo -n $(readlink -f ..) >> ftparchive.conf
653 FileListDir "' >> ftparchive.conf
654 echo -n $(readlink -f pool/) >> ftparchive.conf
658 Packages::Compress "'"$COMPRESSORS"'";
659 Sources::Compress "'"$COMPRESSORS"'";
660 Contents::Compress "'"$COMPRESSORS"'";
661 Translation::Compress "'"$COMPRESSORS"'";
662 LongDescription "false";
666 SrcDirectory "pool/";
672 Label "apttestcases";
674 Description "repository with dummy packages";
675 Architectures "' >> ftparchive.conf
676 echo -n "$ARCHS" >> ftparchive.conf
680 };' >> ftparchive.conf
681 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
682 echo -n 'tree "dists/' >> ftparchive.conf
683 echo -n "$DIST" >> ftparchive.conf
685 Architectures "' >> ftparchive.conf
686 echo -n "$ARCHS" >> ftparchive.conf
688 FileList "' >> ftparchive.conf
689 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
691 SourceFileList "' >> ftparchive.conf
692 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
694 Sections "' >> ftparchive.conf
695 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
697 };' >> ftparchive.conf
701 buildaptftparchivedirectorystructure
() {
702 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
703 for DIST
in $DISTS; do
704 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
705 for SECTION
in $SECTIONS; do
706 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
707 for ARCH
in $ARCHS; do
708 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
710 mkdir -p dists
/${DIST}/${SECTION}/source
711 mkdir -p dists
/${DIST}/${SECTION}/i18n
721 local DEPENDENCIES
="$5"
722 local PRIORITY
="${6:-optional}"
723 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
724 If you find such a package installed on your system,
725 something went horribly wrong! They are autogenerated
726 und used only by testcases and surf no other propose…"}"
728 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
729 if [ "$RELEASE" = 'installed' ]; then
730 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
733 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
734 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
735 ARCHS="$(getarchitectures)"
739 for BUILDARCH in $ARCHS; do
740 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
742 local FILE="${PPATH}/Packages
"
747 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
748 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
749 echo "Version
: $VERSION
750 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
751 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
752 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
753 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
757 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
758 touch aptarchive/dists/${RELEASE}/main/source/Sources
760 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
761 Description
-en: $DESCRIPTION
762 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
771 local DEPENDENCIES="$5"
773 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
775 local FILE="${SPATH}/Sources
"
779 Maintainer
: Joe Sixpack
<joe@example.org
>
780 Architecture
: $ARCH" >> $FILE
781 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
783 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
784 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
788 insertinstalledpackage() {
792 local DEPENDENCIES="$4"
793 local PRIORITY="${5:-optional}"
794 local STATUS="${6:-install ok installed}"
795 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
796 If you
find such a package installed on your system
,
797 something went horribly wrong
! They are autogenerated
798 und used only by testcases and surf no other propose…
"}"
800 local FILE
='rootdir/var/lib/dpkg/status'
801 local INFO
='rootdir/var/lib/dpkg/info'
802 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
808 Maintainer: Joe Sixpack <joe@example.org>
809 Version: $VERSION" >> $FILE
810 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
811 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
812 echo "Description: $DESCRIPTION" >> $FILE
814 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
815 echo -n > ${INFO}/${NAME}:${arch}.list
817 echo -n > ${INFO}/${NAME}.list
823 buildaptarchivefromincoming
() {
824 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
826 [ -e pool
] || ln -s ..
/incoming pool
827 [ -e ftparchive.conf
] || createaptftparchiveconfig
828 [ -e dists
] || buildaptftparchivedirectorystructure
829 msgninfo
"\tGenerate Packages, Sources and Contents files… "
830 testsuccess aptftparchive generate ftparchive.conf
833 generatereleasefiles
"$@"
836 buildaptarchivefromfiles
() {
837 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
838 find aptarchive
-name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
839 msgninfo
"\t${line} file… "
840 compressfile
"$line" "$1"
843 generatereleasefiles
"$@"
847 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
848 if [ "$compressor" = '.' ]; then
854 cat "$1" | $command > "${1}.${extension}"
856 touch -d "$2" "${1}.${extension}"
861 # can be overridden by testcases for their pleasure
862 getcodenamefromsuite
() {
864 unstable
) echo 'sid';;
868 getreleaseversionfromsuite
() { true
; }
869 getlabelfromsuite
() { true
; }
871 generatereleasefiles
() {
872 # $1 is the Date header and $2 is the ValidUntil header to be set
873 # both should be given in notation date/touch can understand
874 msgninfo
"\tGenerate Release files… "
875 if [ -e aptarchive
/dists
]; then
876 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
877 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
878 local CODENAME
="$(getcodenamefromsuite $SUITE)"
879 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
880 local LABEL
="$(getlabelfromsuite $SUITE)"
881 if [ -n "$VERSION" ]; then
882 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
884 if [ -n "$LABEL" ]; then
885 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
887 aptftparchive
-qq release
$dir \
888 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
889 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
892 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
893 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
895 NotAutomatic: yes' $dir/Release
897 if [ -n "$1" -a "$1" != "now" ]; then
898 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
902 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
906 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
908 if [ -n "$1" -a "$1" != "now" ]; then
909 for release
in $(find ./aptarchive -name 'Release'); do
910 touch -d "$1" $release
916 setupdistsaptarchive
() {
917 local APTARCHIVE
=$(readlink -f ./aptarchive)
918 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
919 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
920 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
921 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
922 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
923 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
924 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
929 setupflataptarchive
() {
930 local APTARCHIVE
=$(readlink -f ./aptarchive)
931 if [ -f ${APTARCHIVE}/Packages
]; then
932 msgninfo
"\tadd deb sources.list line… "
933 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
936 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
938 if [ -f ${APTARCHIVE}/Sources
]; then
939 msgninfo
"\tadd deb-src sources.list line… "
940 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
943 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
949 if [ "$1" = '--no-update' ]; then
954 if [ -e aptarchive
/dists
]; then
959 signreleasefiles
'Joe Sixpack'
960 if [ "1" != "$NOUPDATE" ]; then
961 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
966 local SIGNER
="${1:-Joe Sixpack}"
967 local REPODIR
="${2:-aptarchive}"
968 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
969 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
970 msgninfo
"\tSign archive with $SIGNER key $KEY… "
971 local REXKEY
='keys/rexexpired'
972 local SECEXPIREBAK
="${REXKEY}.sec.bak"
973 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
974 if [ "${SIGNER}" = 'Rex Expired' ]; then
975 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
976 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
977 # therefore we 'temporary' make the key not expired and restore a backup after signing
978 cp ${REXKEY}.sec
$SECEXPIREBAK
979 cp ${REXKEY}.pub
$PUBEXPIREBAK
980 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
981 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
982 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
983 cp $SECUNEXPIRED ${REXKEY}.sec
984 cp $PUBUNEXPIRED ${REXKEY}.pub
986 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
990 cp ${REXKEY}.sec
$SECUNEXPIRED
991 cp ${REXKEY}.pub
$PUBUNEXPIRED
994 for RELEASE
in $(find ${REPODIR}/ -name Release); do
995 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
996 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
997 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
998 # we might have set a specific date for the Release file, so copy it
999 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
1001 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1002 mv -f $SECEXPIREBAK ${REXKEY}.sec
1003 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1009 local WEBSERVER
="${3:-http://localhost:8080}"
1011 if [ "$1" = '--no-check' ]; then
1015 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1016 local STATUS
='downloaded/webserverconfig.status'
1017 rm -f "$STATUS" "$DOWNLOG"
1019 if [ -n "$2" ]; then
1020 msgtest
"Set webserver config option '${1}' to" "$2"
1021 URI
="${WEBSERVER}/_config/set/${1}/${2}"
1023 msgtest
'Clear webserver config option' "${1}"
1024 URI
="${WEBSERVER}/_config/clear/${1}"
1026 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1029 cat "$DOWNLOG" "$STATUS" || true
1032 $NOCHECK || testwebserverlaststatuscode
'200'
1035 rewritesourceslist
() {
1036 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1037 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1038 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
1042 # wait for up to 10s for a pid file to appear to avoid possible race
1043 # when a helper is started and dosn't write the PID quick enough
1046 for i
in $(seq 10); do
1047 if test -s "$PIDFILE"; then
1052 msgdie
"waiting for $PIDFILE failed"
1056 changetowebserver
() {
1057 if [ "$1" != '--no-rewrite' ]; then
1058 rewritesourceslist
'http://localhost:8080/'
1062 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
1064 local LOG
="webserver.log"
1065 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
1069 waitforpidfile aptwebserver.pid
1070 local PID
="$(cat aptwebserver.pid)"
1071 if [ -z "$PID" ]; then
1072 msgdie
'Could not fork aptwebserver successfully'
1074 addtrap
"kill $PID;"
1077 msgdie
'You have to build aptwerbserver or install a webserver'
1081 changetohttpswebserver
() {
1082 if ! which stunnel4
>/dev
/null
; then
1083 msgdie
'You need to install stunnel4 for https testcases'
1085 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1086 changetowebserver
--no-rewrite "$@"
1088 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1089 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1095 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1096 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1097 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1098 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1099 if [ -z "$PID" ]; then
1100 msgdie
'Could not fork stunnel4 successfully'
1102 addtrap
'prefix' "kill ${PID};"
1103 rewritesourceslist
'https://localhost:4433/'
1107 mkdir -p rootdir
/media
/cdrom
/.disk
1108 local CD
="$(readlink -f rootdir/media/cdrom)"
1109 echo "acquire::cdrom::mount \"${CD}\";
1110 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1111 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1112 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
1113 echo -n "$1" > ${CD}/.disk
/info
1114 if [ ! -d aptarchive
/dists
]; then
1115 msgdie
'Flat file archive cdroms can not be created currently'
1118 mv aptarchive
/dists
"$CD"
1119 ln -s "$(readlink -f ./incoming)" $CD/pool
1120 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1121 # start with an unmounted disk
1122 mv "${CD}" "${CD}-unmounted"
1123 # we don't want the disk to be modifiable
1124 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1125 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1129 local PROTO
="${1%%:*}"
1130 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1131 download
-file "$1" "$2" 2>&1 ; then
1134 # only if the file exists the download was successful
1135 if [ -r "$2" ]; then
1143 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1144 if [ -n "$DIFFTEXT" ]; then
1146 echo >&2 "$DIFFTEXT"
1156 msgtest
"Test for correctness of file" "$FILE"
1157 if [ -z "$*" ]; then
1158 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
1160 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
1165 msgtest
"Test for no output of" "$*"
1166 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1167 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1174 aptautotest
'testempty' "$@"
1178 local MSG
='Test of equality of'
1179 if [ "$1" = '--nomsg' ]; then
1184 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1185 echo "$1" > $COMPAREFILE
1188 if [ -n "$MSG" ]; then
1191 "$@" 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1192 aptautotest
'testequal' "$@"
1196 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1197 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1198 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1199 echo "$1" > $COMPAREFILE1
1200 echo "$2" > $COMPAREFILE2
1202 msgtest
"Test for equality OR of" "$*"
1203 "$@" >$COMPAREAGAINST 2>&1 || true
1204 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1205 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1209 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1210 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1211 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1212 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1215 aptautotest
'testequalor2' "$@"
1219 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1222 while [ -n "$1" ]; do
1224 N: Can't select versions from package '$1' as it is purely virtual"
1225 PACKAGE
="${PACKAGE} $1"
1228 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1230 N: No packages found"
1231 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1232 local ARCH
="$(getarchitecture 'native')"
1233 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1234 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1238 msgtest
"Test for non-existent packages" "apt-cache show $*"
1239 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1240 if [ -n "$SHOWPKG" ]; then
1253 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1254 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1255 if [ "$PKGS" != $NR ]; then
1257 dpkg
-l "$@" | grep '^[a-z]' >&2
1264 testdpkginstalled
() {
1265 testdpkgstatus
'ii' "$#" "$@"
1268 testdpkgnotinstalled
() {
1269 testdpkgstatus
'ii' '0' "$@"
1273 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1274 if [ -n "$1" ]; then
1275 msgtest
'Test for correctly marked as auto-installed' "$*"
1276 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1278 msgtest
'Test for correctly marked as auto-installed' 'no package'
1279 echo -n > $COMPAREFILE
1281 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1289 if [ "$1" = 'grep' ]; then
1290 while [ -n "$2" ]; do shift; done
1291 echo "#### Complete file: $1 ####"
1292 cat >&2 "$1" || true
1293 echo '#### grep output ####'
1294 elif [ "$1" = 'test' ]; then
1295 # doesn't support ! or non-file flags
1296 msgfailoutputstatfile
() {
1297 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1298 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1299 echo "#### stat(2) of file: $2 ####"
1303 msgfailoutputstatfile
"$2" "$3"
1304 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1306 msgfailoutputstatfile
"$2" "$3"
1308 echo '#### test output ####'
1315 if [ "$1" = '--nomsg' ]; then
1318 msgtest
'Test for successful execution of' "$*"
1320 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1321 if "$@" >${OUTPUT} 2>&1; then
1322 if expr match
"$1" '^apt.*' >/dev
/null
; then
1323 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1324 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1325 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1326 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1335 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1337 aptautotest
'testsuccess' "$@"
1340 if [ "$1" = '--nomsg' ]; then
1343 msgtest
'Test for successful execution with warnings of' "$*"
1345 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1346 if "$@" >${OUTPUT} 2>&1; then
1347 if expr match
"$1" '^apt.*' >/dev
/null
; then
1348 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1349 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1350 elif grep -q -E '^E: ' "$OUTPUT"; then
1351 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1352 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1353 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1364 msgfail
"exitcode $EXITCODE"
1366 aptautotest
'testwarning' "$@"
1369 if [ "$1" = '--nomsg' ]; then
1372 msgtest
'Test for failure in execution of' "$*"
1374 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1375 if "$@" >${OUTPUT} 2>&1; then
1377 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1380 if expr match
"$1" '^apt.*' >/dev
/null
; then
1381 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1382 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1383 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1384 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1392 aptautotest
'testfailure' "$@"
1395 testsuccessequal
() {
1399 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
1401 testwarningequal
() {
1405 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
1407 testfailureequal
() {
1411 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
1418 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1419 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output" 2>&1 || true
1420 if echo "$CMP" | checkdiff
- "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output"; then
1423 echo '### Complete output ###'
1424 cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1430 msgtest
"Test that file $1 has $2 $3" "$4"
1431 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1436 echo -n >&2 "stat(1) reports for $2: "
1437 stat
--format "$2" "$1"
1441 testaccessrights
() {
1442 testfilestats
"$1" '%a' '=' "$2"
1445 testwebserverlaststatuscode
() {
1446 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1447 local STATUS
='downloaded/webserverstatus-statusfile.log'
1448 rm -f "$DOWNLOG" "$STATUS"
1449 msgtest
'Test last status code from the webserver was' "$1"
1450 if downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1454 if [ -n "$2" ]; then
1456 echo >&2 '#### Additionally provided output files contain:'
1459 echo >&2 '#### Download log of the status code:'
1461 msgfail
"Status was $(cat "$STATUS")"
1466 echo "STOPPED execution. Press enter to continue"
1471 listcurrentlistsdirectory
() {
1473 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1474 stat
--format '%U:%G:%a:%n' "$line"
1476 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1477 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1482 ### convinience hacks ###
1484 # creating some directories by hand is a tedious task, so make it look simple
1485 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1486 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1487 # only the last directory created by mkdir is effected by the -m !
1488 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1489 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1490 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1491 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1492 if [ "$(id -u)" = '0' ]; then
1493 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1500 ### The following tests are run by most test methods automatically to check
1501 ### general things about commands executed without writing the test every time.
1507 local AUTOTEST
="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1508 if command -v $AUTOTEST >/dev
/null
; then
1510 # save and restore the *.output files from other tests
1511 # as we might otherwise override them in these automatic tests
1512 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1513 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before
1514 mkdir ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1515 $AUTOTEST "$TESTCALL" "$@"
1516 rm -rf ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1517 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
${TMPWORKINGDIRECTORY}/rootdir
/tmp
-aptautotest
1518 mv ${TMPWORKINGDIRECTORY}/rootdir
/tmp
-before ${TMPWORKINGDIRECTORY}/rootdir
/tmp
1522 aptautotest_aptget_update
() {
1523 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1524 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1525 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1526 # all copied files are properly chmodded
1527 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1528 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1530 if [ "$1" = 'testsuccess' ]; then
1531 # failure cases can retain partial files and such
1532 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1535 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1536 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1538 testaptautotestnodpkgwarning
() {
1540 while [ -n "$2" ]; do
1541 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi
1544 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1547 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1548 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1549 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1550 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1551 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1552 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }