You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1867 lines
61 KiB

  1. #!/bin/sh -- # no runable script, just for vi
  2. EXIT_CODE=0
  3. while [ -n "$1" ]; do
  4. if [ "$1" = "-q" ]; then
  5. export MSGLEVEL=2
  6. elif [ "$1" = "-v" ]; then
  7. export MSGLEVEL=4
  8. elif [ "$1" = '--color=no' ]; then
  9. export MSGCOLOR='NO'
  10. elif [ "$1" = '--color=yes' ]; then
  11. export MSGCOLOR='YES'
  12. elif [ "$1" = '--color' ]; then
  13. export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')"
  14. shift
  15. elif [ "$1" = '--level' ]; then
  16. export MSGLEVEL=$2
  17. shift
  18. else
  19. echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
  20. fi
  21. shift
  22. done
  23. export MSGLEVEL="${MSGLEVEL:-3}"
  24. # we all like colorful messages
  25. if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
  26. if [ ! -t 1 ]; then # but check that we output to a terminal
  27. export MSGCOLOR='NO'
  28. fi
  29. fi
  30. if [ "$MSGCOLOR" != 'NO' ]; then
  31. CERROR="\033[1;31m" # red
  32. CWARNING="\033[1;33m" # yellow
  33. CMSG="\033[1;32m" # green
  34. CINFO="\033[1;96m" # light blue
  35. CDEBUG="\033[1;94m" # blue
  36. CNORMAL="\033[0;39m" # default system console color
  37. CDONE="\033[1;32m" # green
  38. CPASS="\033[1;32m" # green
  39. CFAIL="\033[1;31m" # red
  40. CCMD="\033[1;35m" # pink
  41. fi
  42. msgprintf() {
  43. local START="$1"
  44. local MIDDLE="$2"
  45. local END="$3"
  46. shift 3
  47. if [ -n "$1" ]; then
  48. printf "$START " "$1"
  49. shift
  50. while [ -n "$1" ]; do
  51. printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')"
  52. shift
  53. done
  54. fi
  55. printf "${END}"
  56. }
  57. msgdie() { msgprintf "${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
  58. msgwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
  59. msgmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
  60. msginfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
  61. msgdebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
  62. msgdone() { msgprintf "${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
  63. msgnwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
  64. msgnmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
  65. msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
  66. msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
  67. msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
  68. msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
  69. msgreportheader() {
  70. if [ -n "$MSGTEST_MSG" ]; then
  71. test "$1" != 'msgfailoutput' || echo
  72. if [ -n "$MSGTEST_MSGMSG" ]; then
  73. echo "$MSGTEST_MSGMSG"
  74. fi
  75. if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
  76. echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
  77. fi
  78. echo -n "$MSGTEST_MSG"
  79. unset MSGTEST_MSG
  80. fi
  81. }
  82. msgskip() {
  83. msgreportheader 'msgskip'
  84. if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
  85. else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
  86. }
  87. msgfail() {
  88. msgreportheader 'msgfail'
  89. if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
  90. else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
  91. if [ -n "$APT_DEBUG_TESTS" ]; then
  92. $SHELL
  93. fi
  94. EXIT_CODE=$((EXIT_CODE+1));
  95. }
  96. MSGGROUP_LEVEL=0
  97. msggroup() {
  98. if [ -n "$1" ]; then
  99. if [ $MSGGROUP_LEVEL = 0 ]; then
  100. MSGTEST_GRP='NEXT'
  101. fi
  102. MSGGROUP_LEVEL=$((MSGGROUP_LEVEL+1));
  103. else
  104. MSGGROUP_LEVEL=$((MSGGROUP_LEVEL-1));
  105. if [ $MSGGROUP_LEVEL = 0 ]; then
  106. unset MSGTEST_GRP
  107. fi
  108. fi
  109. }
  110. # enable / disable Debugging
  111. if [ $MSGLEVEL -le 0 ]; then
  112. msgdie() { true; }
  113. fi
  114. if [ $MSGLEVEL -le 1 ]; then
  115. msgwarn() { true; }
  116. msgnwarn() { true; }
  117. fi
  118. if [ $MSGLEVEL -le 2 ]; then
  119. msgmsg() {
  120. MSGTEST_MSGMSG="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
  121. }
  122. msgnmsg() { true; }
  123. msgtest() {
  124. MSGTEST_MSG="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
  125. if [ "$MSGTEST_GRP" = 'NEXT' ]; then
  126. MSGTEST_GRP="$MSGTEST_MSG"
  127. fi
  128. }
  129. msgpass() { printf " ${CPASS}P${CNORMAL}"; }
  130. fi
  131. if [ $MSGLEVEL -le 3 ]; then
  132. msginfo() { true; }
  133. msgninfo() { true; }
  134. fi
  135. if [ $MSGLEVEL -le 4 ]; then
  136. msgdebug() { true; }
  137. msgndebug() { true; }
  138. fi
  139. msgdone() {
  140. if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
  141. [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
  142. [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
  143. [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
  144. [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
  145. true;
  146. else
  147. printf "${CDONE}DONE${CNORMAL}\n";
  148. fi
  149. }
  150. getaptconfig() {
  151. if [ -f ./aptconfig.conf ]; then
  152. echo "$(readlink -f ./aptconfig.conf)"
  153. elif [ -f ../aptconfig.conf ]; then
  154. echo "$(readlink -f ../aptconfig.conf)"
  155. elif [ -f ../../aptconfig.conf ]; then
  156. echo "$(readlink -f ../../aptconfig.conf)"
  157. elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
  158. echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
  159. fi
  160. }
  161. runapt() {
  162. msgdebug "Executing: ${CCMD}$*${CDEBUG} "
  163. local CMD="$1"
  164. shift
  165. case "$CMD" in
  166. sh|aptitude|*/*|command) ;;
  167. *) CMD="${BUILDDIRECTORY}/$CMD";;
  168. esac
  169. MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${LIBRARYPATH} "$CMD" "$@"
  170. }
  171. aptconfig() { runapt apt-config "$@"; }
  172. aptcache() { runapt apt-cache "$@"; }
  173. aptcdrom() { runapt apt-cdrom "$@"; }
  174. aptget() { runapt apt-get "$@"; }
  175. aptftparchive() { runapt apt-ftparchive "$@"; }
  176. aptkey() { runapt apt-key "$@"; }
  177. aptmark() { runapt apt-mark "$@"; }
  178. aptsortpkgs() { runapt apt-sortpkgs "$@"; }
  179. apt() { runapt apt "$@"; }
  180. apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
  181. aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
  182. aptitude() { runapt aptitude "$@"; }
  183. aptextracttemplates() { runapt apt-extracttemplates "$@"; }
  184. aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; }
  185. aptdumpsolver() { runapt "${APTDUMPSOLVER}" "$@"; }
  186. dpkg() {
  187. "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
  188. }
  189. dpkgcheckbuilddeps() {
  190. command dpkg-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
  191. }
  192. gdb() {
  193. local CMD
  194. case "$1" in
  195. aptget) CMD="apt-get";;
  196. aptcache) CMD="apt-cache";;
  197. aptcdrom) CMD="apt-cdrom";;
  198. aptconfig) CMD="apt-config";;
  199. aptmark) CMD="apt-mark";;
  200. apthelper) CMD="apt-helper";;
  201. aptftparchive) CMD="apt-ftparchive";;
  202. dpkg) shift; runapt "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
  203. *) CMD="$1";;
  204. esac
  205. shift
  206. if [ "${CMD##*/}" = "$CMD" ]; then
  207. CMD="${BUILDDIRECTORY}/${CMD}"
  208. fi
  209. runapt command gdb --quiet -ex run "$CMD" --args "$CMD" "$@"
  210. }
  211. exitwithstatus() {
  212. # error if we about to overflow, but ...
  213. # "255 failures ought to be enough for everybody"
  214. if [ $EXIT_CODE -gt 255 ]; then
  215. msgdie "Total failure count $EXIT_CODE too big"
  216. fi
  217. exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
  218. }
  219. shellsetedetector() {
  220. local exit_status=$?
  221. if [ "$exit_status" != '0' ]; then
  222. printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
  223. if [ "$EXIT_CODE" = '0' ]; then
  224. EXIT_CODE="$exit_status"
  225. fi
  226. fi
  227. }
  228. addtrap() {
  229. if [ "$1" = 'prefix' ]; then
  230. CURRENTTRAP="$2 $CURRENTTRAP"
  231. else
  232. CURRENTTRAP="$CURRENTTRAP $1"
  233. fi
  234. trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  235. }
  236. setupenvironment() {
  237. # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
  238. if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
  239. unset TMPDIR
  240. fi
  241. TMPWORKINGDIRECTORY="$(mktemp -d)"
  242. addtrap "cd /; rm -rf \"$TMPWORKINGDIRECTORY\";"
  243. msgninfo "Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
  244. mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
  245. if [ "$(id -u)" = '0' ]; then
  246. # relax permissions so that running as root with user switching works
  247. umask 022
  248. chmod 711 "$TMPWORKINGDIRECTORY"
  249. chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded"
  250. fi
  251. TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
  252. # allow overriding the default BUILDDIR location
  253. SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
  254. BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
  255. LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
  256. METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
  257. APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
  258. APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
  259. APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
  260. APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
  261. test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
  262. # -----
  263. cd "$TMPWORKINGDIRECTORY"
  264. mkdir rootdir aptarchive keys
  265. cd rootdir
  266. mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
  267. mkdir -p usr/bin var/cache var/lib var/log tmp
  268. mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
  269. touch var/lib/dpkg/available
  270. mkdir -p usr/lib/apt
  271. ln -s "${METHODSDIR}" usr/lib/apt/methods
  272. if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
  273. mkdir -p usr/lib/apt/solvers
  274. ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump
  275. ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt
  276. echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc/apt/apt.conf.d/externalsolver.conf
  277. fi
  278. # use the autoremove from the BUILDDIRECTORY if its there, otherwise
  279. # system
  280. if [ -e "${BUILDDIRECTORY}/../../debian/apt.conf.autoremove" ]; then
  281. ln -s "${BUILDDIRECTORY}/../../debian/apt.conf.autoremove" etc/apt/apt.conf.d/01autoremove
  282. else
  283. ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
  284. fi
  285. cd ..
  286. local BASENAME="${0##*/}"
  287. local PACKAGESFILE="Packages-${BASENAME#*-}"
  288. if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
  289. cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
  290. fi
  291. local SOURCESSFILE="Sources-${BASENAME#*-}"
  292. if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
  293. cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
  294. fi
  295. find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
  296. chmod 644 keys/*
  297. ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  298. echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
  299. echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
  300. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  301. echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
  302. # either store apt-key were we can access it, even if we run it as a different user
  303. #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
  304. #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
  305. #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
  306. # destroys coverage reporting though, so we disable changing user for the calling gpgv
  307. echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
  308. if [ "$(id -u)" = '0' ]; then
  309. echo 'Binary::gpgv::Debug::NoDropPrivs "true";' >>aptconfig.conf
  310. fi
  311. cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
  312. #!/bin/sh
  313. set -e
  314. if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
  315. if [ -n "\$LD_LIBRARY_PATH" ]; then
  316. export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\${LD_LIBRARY_PATH}"
  317. else
  318. export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
  319. fi
  320. if [ -n "\$LD_PRELOAD" ]; then
  321. export LD_PRELOAD="noopchroot.so \${LD_PRELOAD}"
  322. else
  323. export LD_PRELOAD="noopchroot.so"
  324. fi
  325. fi
  326. EOF
  327. cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
  328. cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
  329. exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
  330. --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
  331. --force-not-root --force-bad-path "\$@"
  332. EOF
  333. cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF
  334. exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
  335. --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
  336. --force-not-root --force-bad-path "\$@"
  337. EOF
  338. chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
  339. echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg
  340. {
  341. if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
  342. echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
  343. fi
  344. echo 'quiet "0";'
  345. echo 'quiet::NoUpdate "true";'
  346. echo 'quiet::NoStatistic "true";'
  347. # too distracting for users, but helpful to detect changes
  348. echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
  349. echo 'Acquire::Progress::Diffpercent "true";'
  350. # in testcases, it can appear as if localhost has a rotation setup,
  351. # hide this as we can't really deal with it properly
  352. echo 'Acquire::Failure::ShowIP "false";'
  353. # fakeroot can't fake everything, so disabled in production but good for tests
  354. echo 'APT::Sandbox::Verify "true";'
  355. } >> aptconfig.conf
  356. cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
  357. if [ "$(id -u)" = '0' ]; then
  358. chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
  359. fi
  360. echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https
  361. echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
  362. echo 'Acquire::Connect::AddrConfig "false";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
  363. configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
  364. confighashes 'SHA1' # these are tests, not security best-practices
  365. # create some files in /tmp and look at user/group to get what this means
  366. TEST_DEFAULT_USER="$(id -un)"
  367. if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
  368. TEST_DEFAULT_GROUP='root'
  369. else
  370. TEST_DEFAULT_GROUP="$(id -gn)"
  371. fi
  372. # cleanup the environment a bit
  373. # prefer our apt binaries over the system apt binaries
  374. export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
  375. export LC_ALL=C.UTF-8
  376. unset LANGUAGE APT_CONFIG
  377. unset GREP_OPTIONS DEB_BUILD_PROFILES
  378. unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
  379. msgdone "info"
  380. }
  381. getarchitecture() {
  382. if [ "$1" = "native" -o -z "$1" ]; then
  383. eval `aptconfig shell ARCH APT::Architecture`
  384. if [ -n "$ARCH" ]; then
  385. echo $ARCH
  386. else
  387. dpkg --print-architecture
  388. fi
  389. else
  390. echo $1
  391. fi
  392. }
  393. getarchitectures() {
  394. aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
  395. }
  396. getarchitecturesfromcommalist() {
  397. echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
  398. }
  399. configarchitecture() {
  400. {
  401. echo "APT::Architecture \"$(getarchitecture $1)\";"
  402. while [ -n "$1" ]; do
  403. echo "APT::Architectures:: \"$(getarchitecture $1)\";"
  404. shift
  405. done
  406. } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
  407. configdpkg
  408. }
  409. configdpkg() {
  410. if [ ! -e rootdir/var/lib/dpkg/status ]; then
  411. local BASENAME="${0##*/}"
  412. local STATUSFILE="status-${BASENAME#*-}"
  413. if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
  414. cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
  415. else
  416. echo -n > rootdir/var/lib/dpkg/status
  417. fi
  418. fi
  419. rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
  420. if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
  421. local ARCHS="$(getarchitectures)"
  422. if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
  423. DPKGARCH="$(dpkg --print-architecture)"
  424. for ARCH in ${ARCHS}; do
  425. if [ "${ARCH}" != "${DPKGARCH}" ]; then
  426. if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
  427. # old-style used e.g. in Ubuntu-P – and as it seems travis
  428. echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  429. echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  430. fi
  431. fi
  432. done
  433. if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
  434. # dpkg doesn't really check the version as long as it is fully installed,
  435. # but just to be sure we choose one above the required version
  436. insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
  437. fi
  438. fi
  439. fi
  440. }
  441. configdpkgnoopchroot() {
  442. # create a library to noop chroot() and rewrite maintainer script executions
  443. # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
  444. # chroot directory dpkg could chroot into to execute the maintainer scripts
  445. msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
  446. cat > noopchroot.c << EOF
  447. #define _GNU_SOURCE
  448. #include <stdio.h>
  449. #include <stdlib.h>
  450. #include <string.h>
  451. #include <dlfcn.h>
  452. static char * chrootdir = NULL;
  453. int chroot(const char *path) {
  454. printf("WARNING: CHROOTing to %s was ignored!\n", path);
  455. free(chrootdir);
  456. chrootdir = strdup(path);
  457. return 0;
  458. }
  459. int execvp(const char *file, char *const argv[]) {
  460. static int (*func_execvp) (const char *, char * const []) = NULL;
  461. if (func_execvp == NULL)
  462. func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
  463. if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
  464. return func_execvp(file, argv);
  465. printf("REWRITE execvp call %s into %s\n", file, chrootdir);
  466. char *newfile;
  467. if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) {
  468. perror("asprintf");
  469. return -1;
  470. }
  471. char const * const baseadmindir = "/var/lib/dpkg";
  472. char *admindir;
  473. if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) {
  474. perror("asprintf");
  475. return -1;
  476. }
  477. setenv("DPKG_ADMINDIR", admindir, 1);
  478. return func_execvp(newfile, argv);
  479. }
  480. EOF
  481. testsuccess --nomsg gcc -Wall -fPIC -shared -o noopchroot.so noopchroot.c -ldl
  482. }
  483. configcompression() {
  484. while [ -n "$1" ]; do
  485. case "$1" in
  486. '.') printf ".\t.\tcat\n";;
  487. 'gz') printf "gzip\tgz\tgzip\n";;
  488. 'bz2') printf "bzip2\tbz2\tbzip2\n";;
  489. 'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
  490. 'xz') printf "xz\txz\txz\n";;
  491. *) printf "$1\t$1\t$1\n";;
  492. esac
  493. shift
  494. done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
  495. }
  496. confighashes() {
  497. {
  498. echo 'APT::FTPArchive {'
  499. {
  500. while [ -n "$1" ]; do
  501. printf "$1" | tr 'a-z' 'A-Z'
  502. printf "\t\"true\";\n"
  503. shift
  504. done
  505. for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
  506. printf "$h\t\"false\";\n"
  507. done
  508. } | awk '!x[$1]++'
  509. echo '};'
  510. } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf"
  511. }
  512. forcecompressor() {
  513. COMPRESSOR="$1"
  514. COMPRESSOR_CMD="$1"
  515. case $COMPRESSOR in
  516. gzip) COMPRESS='gz';;
  517. bzip2) COMPRESS='bz2';;
  518. lzma) COMPRESS='lzma';;
  519. xz) COMPRESS='xz';;
  520. *) msgdie "Compressor $COMPRESSOR is unknown to framework, so can't be forced by forcecompressor!";;
  521. esac
  522. local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
  523. echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
  524. Dir::Bin::uncompressed \"/does/not/exist\";
  525. Dir::Bin::gzip \"/does/not/exist\";
  526. Dir::Bin::bzip2 \"/does/not/exist\";
  527. Dir::Bin::lzma \"/does/not/exist\";
  528. Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
  529. if [ -e "/bin/${COMPRESSOR}" ]; then
  530. echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
  531. elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
  532. echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
  533. elif [ "${COMPRESSOR}" = 'lzma' ]; then
  534. echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
  535. COMPRESSOR_CMD='xz --format=lzma'
  536. else
  537. msgtest 'Test for availability of compressor' "${COMPRESSOR}"
  538. msgfail "${COMPRESSOR} not available"
  539. fi
  540. }
  541. setupsimplenativepackage() {
  542. local NAME="$1"
  543. local ARCH="$2"
  544. local VERSION="$3"
  545. local RELEASE="${4:-unstable}"
  546. local DEPENDENCIES="$5"
  547. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  548. If you find such a package installed on your system,
  549. something went horribly wrong! They are autogenerated
  550. und used only by testcases and serve no other purpose…"}"
  551. local SECTION="${7:-others}"
  552. local DISTSECTION
  553. if [ "$SECTION" = "${SECTION#*/}" ]; then
  554. DISTSECTION="main"
  555. else
  556. DISTSECTION="${SECTION%/*}"
  557. fi
  558. local BUILDDIR=incoming/${NAME}-${VERSION}
  559. mkdir -p ${BUILDDIR}/debian/source
  560. cd ${BUILDDIR}
  561. echo "* most suckless software product ever" > FEATURES
  562. test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
  563. test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
  564. * Initial release
  565. -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
  566. test -e debian/control || echo "Source: $NAME
  567. Section: $SECTION
  568. Priority: optional
  569. Maintainer: Joe Sixpack <joe@example.org>
  570. Build-Depends: debhelper (>= 7)
  571. Standards-Version: 3.9.1
  572. Package: $NAME" > debian/control
  573. if [ "$ARCH" = 'all' ]; then
  574. echo "Architecture: all" >> debian/control
  575. else
  576. echo "Architecture: any" >> debian/control
  577. fi
  578. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
  579. echo "Description: $DESCRIPTION" >> debian/control
  580. test -e debian/compat || echo "7" > debian/compat
  581. test -e debian/source/format || echo "3.0 (native)" > debian/source/format
  582. test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
  583. cd - > /dev/null
  584. }
  585. buildsimplenativepackage() {
  586. local NAME="$1"
  587. local NM
  588. if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
  589. NM="$(echo "$NAME" | cut -c 1-4)"
  590. else
  591. NM="$(echo "$NAME" | cut -c 1)"
  592. fi
  593. local ARCH="$2"
  594. local VERSION="$3"
  595. local RELEASE="${4:-unstable}"
  596. local DEPENDENCIES="$5"
  597. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  598. If you find such a package installed on your system,
  599. something went horribly wrong! They are autogenerated
  600. und used only by testcases and serve no other purpose…"}"
  601. local SECTION="${7:-others}"
  602. local PRIORITY="${8:-optional}"
  603. local FILE_TREE="$9"
  604. local COMPRESS_TYPE="${10:-gzip}"
  605. local DISTSECTION
  606. if [ "$SECTION" = "${SECTION#*/}" ]; then
  607. DISTSECTION="main"
  608. else
  609. DISTSECTION="${SECTION%/*}"
  610. fi
  611. local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
  612. msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
  613. mkdir -p "$BUILDDIR/debian/source"
  614. echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
  615. echo "#!/bin/sh
  616. echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
  617. echo "Copyleft by Joe Sixpack $(date +%Y)" > "${BUILDDIR}/debian/copyright"
  618. echo "$NAME ($VERSION) $RELEASE; urgency=low
  619. * Initial release
  620. -- Joe Sixpack <joe@example.org> $(date -R)" > "${BUILDDIR}/debian/changelog"
  621. {
  622. echo "Source: $NAME
  623. Priority: $PRIORITY
  624. Maintainer: Joe Sixpack <joe@example.org>
  625. Standards-Version: 3.9.3"
  626. if [ "$SECTION" != '<none>' ]; then
  627. echo "Section: $SECTION"
  628. fi
  629. local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
  630. test -z "$BUILDDEPS" || echo "$BUILDDEPS"
  631. echo "
  632. Package: $NAME"
  633. if [ "$ARCH" = 'all' ]; then
  634. echo "Architecture: all"
  635. else
  636. echo "Architecture: any"
  637. fi
  638. local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
  639. test -z "$DEPS" || echo "$DEPS"
  640. echo "Description: $DESCRIPTION"
  641. } > "${BUILDDIR}/debian/control"
  642. echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
  643. cd "${BUILDDIR}/.."
  644. testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
  645. cd - >/dev/null
  646. sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
  647. | while read SRC; do
  648. echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
  649. # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
  650. # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
  651. # adv --yes --default-key 'Joe Sixpack' \
  652. # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  653. # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  654. # fi
  655. done
  656. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  657. msgtest "Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
  658. rm -rf "${BUILDDIR}/debian/tmp"
  659. mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
  660. cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
  661. cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
  662. if [ -n "$FILE_TREE" ]; then
  663. cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
  664. fi
  665. (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
  666. (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
  667. local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
  668. # ensure the right permissions as dpkg-deb insists
  669. chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
  670. testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
  671. echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
  672. done
  673. local CHANGEPATH="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
  674. mkdir -p "$CHANGEPATH"
  675. cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
  676. rm -rf "${BUILDDIR}"
  677. msgdone "info"
  678. }
  679. buildpackage() {
  680. local BUILDDIR=$1
  681. local RELEASE=$2
  682. local SECTION=$3
  683. local ARCH=$(getarchitecture $4)
  684. local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
  685. local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
  686. msgtest "Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
  687. cd "$BUILDDIR"
  688. if [ "$ARCH" = "all" ]; then
  689. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  690. fi
  691. testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
  692. cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
  693. local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
  694. local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
  695. cd - > /dev/null
  696. for PKG in $PKGS; do
  697. echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
  698. done
  699. for SRC in $SRCS; do
  700. echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
  701. done
  702. }
  703. buildaptarchive() {
  704. if [ -d incoming ]; then
  705. buildaptarchivefromincoming "$@"
  706. else
  707. buildaptarchivefromfiles "$@"
  708. fi
  709. }
  710. createaptftparchiveconfig() {
  711. local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
  712. local COMPRESSORS="${COMPRESSORS%* }"
  713. local ARCHS="$(getarchitectures)"
  714. cat > ftparchive.conf <<EOF
  715. Dir {
  716. ArchiveDir "$(readlink -f .)";
  717. CacheDir "$(readlink -f ..)";
  718. FileListDir "$(readlink -f pool/)";
  719. };
  720. Default {
  721. Packages::Compress "$COMPRESSORS";
  722. Sources::Compress "$COMPRESSORS";
  723. Contents::Compress "$COMPRESSORS";
  724. Translation::Compress "$COMPRESSORS";
  725. LongDescription "false";
  726. };
  727. TreeDefault {
  728. Directory "pool/";
  729. SrcDirectory "pool/";
  730. };
  731. EOF
  732. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  733. cat <<EOF
  734. tree "dists/$DIST" {
  735. Architectures "$ARCHS all source";
  736. FileList "${DIST}.\$(SECTION).pkglist";
  737. SourceFileList "${DIST}.\$(SECTION).srclist";
  738. Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
  739. };
  740. EOF
  741. done >> ftparchive.conf
  742. }
  743. buildaptftparchivedirectorystructure() {
  744. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  745. for DIST in $DISTS; do
  746. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  747. for SECTION in $SECTIONS; do
  748. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  749. for ARCH in $ARCHS; do
  750. mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
  751. done
  752. mkdir -p "dists/${DIST}/${SECTION}/source"
  753. mkdir -p "dists/${DIST}/${SECTION}/i18n"
  754. done
  755. done
  756. }
  757. insertpackage() {
  758. local RELEASES="$1"
  759. local NAME="$2"
  760. local ARCH="$3"
  761. local VERSION="$4"
  762. local DEPENDENCIES="$5"
  763. local PRIORITY="${6:-optional}"
  764. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
  765. If you find such a package installed on your system,
  766. something went horribly wrong! They are autogenerated
  767. und used only by testcases and serve no other purpose…"}"
  768. local ARCHS=""
  769. for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
  770. if [ "$RELEASE" = 'installed' ]; then
  771. insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
  772. continue
  773. fi
  774. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  775. if [ "$arch" = 'none' ]; then
  776. ARCHS="$(getarchitectures)"
  777. else
  778. ARCHS="$arch"
  779. fi
  780. for BUILDARCH in $ARCHS; do
  781. local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
  782. mkdir -p "$PPATH"
  783. {
  784. echo "Package: $NAME
  785. Priority: $PRIORITY
  786. Section: other
  787. Installed-Size: 42
  788. Maintainer: Joe Sixpack <joe@example.org>"
  789. test "$arch" = 'none' || echo "Architecture: $arch"
  790. echo "Version: $VERSION
  791. Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
  792. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
  793. echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
  794. echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
  795. echo
  796. } >> "${PPATH}/Packages"
  797. done
  798. done
  799. mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
  800. touch "aptarchive/dists/${RELEASE}/main/source/Sources"
  801. echo "Package: $NAME
  802. Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
  803. Description-en: $DESCRIPTION
  804. " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
  805. done
  806. }
  807. insertsource() {
  808. local RELEASE="$1"
  809. local NAME="$2"
  810. local ARCH="$3"
  811. local VERSION="$4"
  812. local DEPENDENCIES="$5"
  813. local BINARY="${6:-$NAME}"
  814. local ARCHS=""
  815. local SPATH="aptarchive/dists/${RELEASE}/main/source"
  816. mkdir -p $SPATH
  817. local FILE="${SPATH}/Sources"
  818. local DSCFILE="${NAME}_${VERSION}.dsc"
  819. local TARFILE="${NAME}_${VERSION}.tar.gz"
  820. echo "Package: $NAME
  821. Binary: $BINARY
  822. Version: $VERSION
  823. Maintainer: Joe Sixpack <joe@example.org>
  824. Architecture: $ARCH" >> $FILE
  825. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
  826. echo "Files:
  827. $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  828. $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
  829. Checksums-Sha256:
  830. $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  831. $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
  832. " >> "$FILE"
  833. }
  834. insertinstalledpackage() {
  835. local NAME="$1"
  836. local ARCH="$2"
  837. local VERSION="$3"
  838. local DEPENDENCIES="$4"
  839. local PRIORITY="${5:-optional}"
  840. local STATUS="${6:-install ok installed}"
  841. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
  842. If you find such a package installed on your system,
  843. something went horribly wrong! They are autogenerated
  844. und used only by testcases and serve no other purpose…"}"
  845. local FILE='rootdir/var/lib/dpkg/status'
  846. local INFO='rootdir/var/lib/dpkg/info'
  847. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  848. echo "Package: $NAME
  849. Status: $STATUS
  850. Priority: $PRIORITY
  851. Section: other
  852. Installed-Size: 42
  853. Maintainer: Joe Sixpack <joe@example.org>
  854. Version: $VERSION" >> "$FILE"
  855. test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
  856. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
  857. echo "Description: $DESCRIPTION" >> "$FILE"
  858. echo >> "$FILE"
  859. if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
  860. echo -n > "${INFO}/${NAME}:${arch}.list"
  861. else
  862. echo -n > "${INFO}/${NAME}.list"
  863. fi
  864. done
  865. }
  866. buildaptarchivefromincoming() {
  867. msginfo "Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
  868. cd aptarchive
  869. [ -e pool ] || ln -s ../incoming pool
  870. [ -e ftparchive.conf ] || createaptftparchiveconfig
  871. [ -e dists ] || buildaptftparchivedirectorystructure
  872. msgninfo "\tGenerate Packages, Sources and Contents files… "
  873. testsuccess aptftparchive generate ftparchive.conf
  874. cd - > /dev/null
  875. msgdone "info"
  876. generatereleasefiles "$@"
  877. }
  878. buildaptarchivefromfiles() {
  879. msginfo "Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
  880. local DIR='aptarchive'
  881. if [ -d "${DIR}/dists" ]; then DIR="${DIR}/dists"; fi
  882. find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
  883. msgninfo "\t${line} file… "
  884. compressfile "$line" "$1"
  885. msgdone "info"
  886. done
  887. generatereleasefiles "$@"
  888. }
  889. compressfile() {
  890. cat "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | while read compressor extension command; do
  891. if [ "$compressor" = '.' ]; then
  892. if [ -n "$2" ]; then
  893. touch -d "$2" "$1"
  894. fi
  895. continue
  896. fi
  897. cat "$1" | $command > "${1}.${extension}"
  898. if [ -n "$2" ]; then
  899. touch -d "$2" "${1}.${extension}"
  900. fi
  901. done
  902. }
  903. # can be overridden by testcases for their pleasure
  904. getcodenamefromsuite() {
  905. case "$1" in
  906. unstable) echo 'sid';;
  907. *) echo -n "$1";;
  908. esac
  909. }
  910. getreleaseversionfromsuite() { true; }
  911. getlabelfromsuite() { true; }
  912. getoriginfromsuite() { true; }
  913. getarchitecturesfromreleasefile() { echo "all $(getarchitectures)"; }
  914. aptftparchiverelease() {
  915. aptftparchive -qq release "$@" | sed -e '/0 Release$/ d' # remove the self reference
  916. }
  917. generatereleasefiles() {
  918. # $1 is the Date header and $2 is the ValidUntil header to be set
  919. # both should be given in notation date/touch can understand
  920. local DATE="$1"
  921. local VALIDUNTIL="$2"
  922. if [ -e aptarchive/dists ]; then
  923. msgninfo "\tGenerate Release files for dists… "
  924. for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
  925. local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
  926. local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
  927. local CODENAME="$(getcodenamefromsuite $SUITE)"
  928. local VERSION="$(getreleaseversionfromsuite $SUITE)"
  929. local LABEL="$(getlabelfromsuite $SUITE)"
  930. local ORIGIN="$(getoriginfromsuite $SUITE)"
  931. aptftparchiverelease "$dir" \
  932. -o APT::FTPArchive::Release::Suite="${SUITE}" \
  933. -o APT::FTPArchive::Release::Codename="${CODENAME}" \
  934. -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
  935. -o APT::FTPArchive::Release::Label="${LABEL}" \
  936. -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
  937. -o APT::FTPArchive::Release::Version="${VERSION}" \
  938. > "$dir/Release"
  939. if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
  940. sed -i '/^Date: / a\
  941. NotAutomatic: yes' "$dir/Release"
  942. fi
  943. done
  944. else
  945. msgninfo "\tGenerate Release files for flat… "
  946. aptftparchiverelease ./aptarchive > aptarchive/Release
  947. fi
  948. if [ -n "$DATE" -a "$DATE" != "now" ]; then
  949. for release in $(find ./aptarchive -name 'Release'); do
  950. sed -i "s/^Date: .*$/Date: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
  951. touch -d "$DATE" "$release"
  952. done
  953. fi
  954. if [ -n "$VALIDUNTIL" ]; then
  955. sed -i "/^Date: / a\
  956. Valid-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
  957. fi
  958. msgdone "info"
  959. }
  960. setupdistsaptarchive() {
  961. local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
  962. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  963. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  964. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  965. SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  966. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  967. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
  968. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
  969. msgdone "info"
  970. done
  971. }
  972. setupflataptarchive() {
  973. local APTARCHIVE="$(readlink -f ./aptarchive)"
  974. local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
  975. if [ -f "${APTARCHIVE}/Packages" ]; then
  976. msgninfo "\tadd deb sources.list line… "
  977. echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
  978. msgdone 'info'
  979. else
  980. rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
  981. fi
  982. if [ -f "${APTARCHIVE}/Sources" ]; then
  983. msgninfo "\tadd deb-src sources.list line… "
  984. echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
  985. msgdone 'info'
  986. else
  987. rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
  988. fi
  989. }
  990. setupaptarchive() {
  991. local NOUPDATE=0
  992. if [ "$1" = '--no-update' ]; then
  993. NOUPDATE=1
  994. shift
  995. fi
  996. buildaptarchive "$@"
  997. if [ -e aptarchive/dists ]; then
  998. setupdistsaptarchive
  999. else
  1000. setupflataptarchive
  1001. fi
  1002. signreleasefiles 'Joe Sixpack'
  1003. if [ "1" != "$NOUPDATE" ]; then
  1004. testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
  1005. fi
  1006. }
  1007. signreleasefiles() {
  1008. local SIGNER="${1:-Joe Sixpack}"
  1009. local REPODIR="${2:-aptarchive}"
  1010. local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
  1011. local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
  1012. msgninfo "\tSign archive with $SIGNER key $KEY… "
  1013. local REXKEY='keys/rexexpired'
  1014. local SECEXPIREBAK="${REXKEY}.sec.bak"
  1015. local PUBEXPIREBAK="${REXKEY}.pub.bak"
  1016. if [ "${SIGNER}" = 'Rex Expired' ]; then
  1017. # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
  1018. # option doesn't exist anymore (and using faketime would add a new obscure dependency)
  1019. # therefore we 'temporary' make the key not expired and restore a backup after signing
  1020. cp "${REXKEY}.sec" "$SECEXPIREBAK"
  1021. cp "${REXKEY}.pub" "$PUBEXPIREBAK"
  1022. local SECUNEXPIRED="${REXKEY}.sec.unexpired"
  1023. local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
  1024. if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
  1025. cp "$SECUNEXPIRED" "${REXKEY}.sec"
  1026. cp "$PUBUNEXPIRED" "${REXKEY}.pub"
  1027. else
  1028. if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
  1029. cat setexpire.gpg
  1030. exit 1
  1031. fi
  1032. cp "${REXKEY}.sec" "$SECUNEXPIRED"
  1033. cp "${REXKEY}.pub" "$PUBUNEXPIRED"
  1034. fi
  1035. fi
  1036. for RELEASE in $(find "${REPODIR}/" -name Release); do
  1037. $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
  1038. local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
  1039. $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
  1040. # we might have set a specific date for the Release file, so copy it
  1041. touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg" "${INRELEASE}"
  1042. done
  1043. if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
  1044. mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
  1045. mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
  1046. fi
  1047. msgdone 'info'
  1048. }
  1049. redatereleasefiles() {
  1050. local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
  1051. for release in $(find aptarchive/ -name 'Release'); do
  1052. sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
  1053. touch -d "$DATE" "$release"
  1054. done
  1055. signreleasefiles "${2:-Joe Sixpack}"
  1056. }
  1057. webserverconfig() {
  1058. local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
  1059. local NOCHECK=false
  1060. if [ "$1" = '--no-check' ]; then
  1061. NOCHECK=true
  1062. shift
  1063. fi
  1064. local DOWNLOG='rootdir/tmp/download-testfile.log'
  1065. local STATUS='downloaded/webserverconfig.status'
  1066. rm -f "$STATUS" "$DOWNLOG"
  1067. # very very basic URI encoding
  1068. local URI
  1069. if [ -n "$2" ]; then
  1070. msgtest "Set webserver config option '${1}' to" "$2"
  1071. URI="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
  1072. else
  1073. msgtest 'Clear webserver config option' "${1}"
  1074. URI="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
  1075. fi
  1076. if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
  1077. msgpass
  1078. else
  1079. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
  1080. cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
  1081. msgfailoutput '' "$OUTPUT"
  1082. fi
  1083. $NOCHECK || testwebserverlaststatuscode '200'
  1084. }
  1085. rewritesourceslist() {
  1086. local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
  1087. local APTARCHIVE2="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
  1088. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  1089. sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
  1090. -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
  1091. -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
  1092. done
  1093. }
  1094. # wait for up to 10s for a pid file to appear to avoid possible race
  1095. # when a helper is started and dosn't write the PID quick enough
  1096. waitforpidfile() {
  1097. local PIDFILE="$1"
  1098. for i in $(seq 10); do
  1099. if test -s "$PIDFILE"; then
  1100. return 0
  1101. fi
  1102. sleep 1
  1103. done
  1104. msgdie "waiting for $PIDFILE failed"
  1105. return 1
  1106. }
  1107. changetowebserver() {
  1108. local REWRITE='no'
  1109. if [ "$1" != '--no-rewrite' ]; then
  1110. REWRITE='yes'
  1111. else
  1112. shift
  1113. fi
  1114. if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
  1115. cd aptarchive
  1116. local LOG="webserver.log"
  1117. if ! aptwebserver --port 0 -o aptwebserver::fork=1 -o aptwebserver::portfile='aptwebserver.port' "$@" >$LOG 2>&1 ; then
  1118. cat "$LOG"
  1119. false
  1120. fi
  1121. waitforpidfile aptwebserver.pid
  1122. local PID="$(cat aptwebserver.pid)"
  1123. if [ -z "$PID" ]; then
  1124. msgdie 'Could not fork aptwebserver successfully'
  1125. fi
  1126. addtrap "kill $PID;"
  1127. waitforpidfile aptwebserver.port
  1128. APTHTTPPORT="$(cat aptwebserver.port)"
  1129. if [ -z "$APTHTTPPORT" ]; then
  1130. msgdie 'Could not get port for aptwebserver successfully'
  1131. fi
  1132. cd - > /dev/null
  1133. else
  1134. msgdie 'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
  1135. fi
  1136. if [ "$REWRTE" != 'yes' ]; then
  1137. rewritesourceslist "http://localhost:${APTHTTPPORT}/"
  1138. fi
  1139. }
  1140. changetohttpswebserver() {
  1141. if ! command -v stunnel4 >/dev/null 2>&1; then
  1142. msgdie 'You need to install stunnel4 for https testcases'
  1143. fi
  1144. if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
  1145. changetowebserver --no-rewrite "$@"
  1146. fi
  1147. echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
  1148. cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
  1149. output = /dev/null
  1150. [https]
  1151. accept = 0
  1152. connect = $APTHTTPPORT
  1153. " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
  1154. stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
  1155. waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
  1156. local PID="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
  1157. if [ -z "$PID" ]; then
  1158. msgdie 'Could not fork stunnel4 successfully'
  1159. fi
  1160. addtrap 'prefix' "kill ${PID};"
  1161. APTHTTPSPORT="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
  1162. webserverconfig 'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
  1163. rewritesourceslist "https://localhost:${APTHTTPSPORT}/"
  1164. }
  1165. changetocdrom() {
  1166. mkdir -p rootdir/media/cdrom/.disk
  1167. local CD="$(readlink -f rootdir/media/cdrom)"
  1168. cat > rootdir/etc/apt/apt.conf.d/00cdrom <<EOF
  1169. acquire::cdrom::mount "${CD}";
  1170. acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
  1171. acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
  1172. acquire::cdrom::autodetect 0;
  1173. EOF
  1174. echo -n "$1" > "${CD}/.disk/info"
  1175. if [ ! -d aptarchive/dists ]; then
  1176. msgdie 'Flat file archive cdroms can not be created currently'
  1177. return 1
  1178. fi
  1179. mv aptarchive/dists "$CD"
  1180. ln -s "$(readlink -f ./incoming)" "$CD/pool"
  1181. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  1182. # start with an unmounted disk
  1183. mv "${CD}" "${CD}-unmounted"
  1184. # we don't want the disk to be modifiable
  1185. addtrap 'prefix' "chmod -f -R +w \"$PWD/rootdir/media/cdrom/dists/\" \"$PWD/rootdir/media/cdrom-unmounted/dists/\" || true;"
  1186. chmod -R 555 rootdir/media/cdrom-unmounted/dists
  1187. }
  1188. downloadfile() {
  1189. local PROTO="${1%%:*}"
  1190. if ! apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \
  1191. download-file "$1" "$2" "$3" 2>&1 ; then
  1192. return 1
  1193. fi
  1194. # only if the file exists the download was successful
  1195. if [ -r "$2" ]; then
  1196. return 0
  1197. else
  1198. return 1
  1199. fi
  1200. }
  1201. checkdiff() {
  1202. local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  1203. if [ -n "$DIFFTEXT" ]; then
  1204. echo >&2
  1205. echo >&2 "$DIFFTEXT"
  1206. return 1
  1207. else
  1208. return 0
  1209. fi
  1210. }
  1211. testoutputequal() {
  1212. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
  1213. local COMPAREFILE="$1"
  1214. shift
  1215. if "$@" 2>&1 | checkdiff "$COMPAREFILE" - >"$OUTPUT" 2>&1; then
  1216. msgpass
  1217. else
  1218. echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
  1219. cat "$COMPAREFILE" >>"${OUTPUT}"
  1220. msgfailoutput '' "$OUTPUT" "$@"
  1221. fi
  1222. }
  1223. testfileequal() {
  1224. msggroup 'testfileequal'
  1225. local MSG='Test for correctness of file'
  1226. if [ "$1" = '--nomsg' ]; then
  1227. MSG=''
  1228. shift
  1229. fi
  1230. local FILE="$1"
  1231. shift
  1232. if [ -n "$MSG" ]; then
  1233. msgtest "$MSG" "$FILE"
  1234. fi
  1235. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
  1236. if [ -z "$*" ]; then
  1237. testoutputequal "$FILE" echo -n ''
  1238. else
  1239. testoutputequal "$FILE" echo "$*"
  1240. fi
  1241. msggroup
  1242. }
  1243. testempty() {
  1244. msggroup 'testempty'
  1245. msgtest "Test for no output of" "$*"
  1246. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
  1247. if ("$@" >"$COMPAREFILE" 2>&1 || true) && test ! -s "$COMPAREFILE"; then
  1248. msgpass
  1249. else
  1250. msgfailoutput '' "$COMPAREFILE" "$@"
  1251. fi
  1252. aptautotest 'testempty' "$@"
  1253. msggroup
  1254. }
  1255. testnotempty() {
  1256. msggroup 'testnotempty'
  1257. msgtest "Test for some output of" "$*"
  1258. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
  1259. if ("$@" >"$COMPAREFILE" 2>&1 || true) && test -s "$COMPAREFILE"; then
  1260. msgpass
  1261. else
  1262. msgfailoutput '' "$COMPAREFILE" "$@"
  1263. fi
  1264. aptautotest 'testnotempty' "$@"
  1265. msggroup
  1266. }
  1267. testequal() {
  1268. msggroup 'testequal'
  1269. local MSG='Test of equality of'
  1270. if [ "$1" = '--nomsg' ]; then
  1271. MSG=''
  1272. shift
  1273. fi
  1274. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
  1275. echo "$1" > "$COMPAREFILE"
  1276. shift
  1277. if [ -n "$MSG" ]; then
  1278. msgtest "$MSG" "$*"
  1279. fi
  1280. testoutputequal "$COMPAREFILE" "$@"
  1281. aptautotest 'testequal' "$@"
  1282. msggroup
  1283. }
  1284. testequalor2() {
  1285. msggroup 'testequalor2'
  1286. local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
  1287. local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
  1288. local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
  1289. echo "$1" > "$COMPAREFILE1"
  1290. echo "$2" > "$COMPAREFILE2"
  1291. shift 2
  1292. msgtest "Test for equality OR of" "$*"
  1293. "$@" >"$COMPAREAGAINST" 2>&1 || true
  1294. if checkdiff "$COMPAREFILE1" "$COMPAREAGAINST" >/dev/null 2>&1 || \
  1295. checkdiff "$COMPAREFILE2" "$COMPAREAGAINST" >/dev/null 2>&1
  1296. then
  1297. msgpass
  1298. else
  1299. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
  1300. echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
  1301. checkdiff "$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
  1302. echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
  1303. checkdiff "$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
  1304. msgfailoutput '' "$OUTPUT"
  1305. fi
  1306. aptautotest 'testequalor2' "$@"
  1307. msggroup
  1308. }
  1309. testshowvirtual() {
  1310. msggroup 'testshowvirtual'
  1311. local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
  1312. local PACKAGE="$1"
  1313. shift
  1314. while [ -n "$1" ]; do
  1315. VIRTUAL="${VIRTUAL}
  1316. N: Can't select versions from package '$1' as it is purely virtual"
  1317. PACKAGE="${PACKAGE} $1"
  1318. shift
  1319. done
  1320. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  1321. VIRTUAL="${VIRTUAL}
  1322. N: No packages found"
  1323. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
  1324. local ARCH="$(getarchitecture 'native')"
  1325. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
  1326. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
  1327. testoutputequal "$COMPAREFILE" aptcache show "$PACKAGE"
  1328. msggroup
  1329. }
  1330. testnopackage() {
  1331. msggroup 'testnopackage'
  1332. msgtest "Test for non-existent packages" "apt-cache show $*"
  1333. local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
  1334. if [ -n "$SHOWPKG" ]; then
  1335. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
  1336. echo "$SHOWPKG" >"$OUTPUT"
  1337. msgfailoutput '' "$OUTPUT"
  1338. else
  1339. msgpass
  1340. fi
  1341. msggroup
  1342. }
  1343. testnosrcpackage() {
  1344. msggroup 'testnosrcpackage'
  1345. msgtest "Test for non-existent source packages" "apt-cache showsrc $*"
  1346. local SHOWPKG="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
  1347. if [ -n "$SHOWPKG" ]; then
  1348. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
  1349. echo "$SHOWPKG" >"$OUTPUT"
  1350. msgfailoutput '' "$OUTPUT"
  1351. else
  1352. msgpass
  1353. fi
  1354. msggroup
  1355. }
  1356. testdpkgstatus() {
  1357. msggroup 'testdpkgstatus'
  1358. local STATE="$1"
  1359. local NR="$2"
  1360. shift 2
  1361. msgtest "Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
  1362. local PKGS="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
  1363. if [ "$PKGS" != $NR ]; then
  1364. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
  1365. echo "$PKGS" >"$OUTPUT"
  1366. dpkg -l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
  1367. msgfailoutput '' "$OUTPUT"
  1368. else
  1369. msgpass
  1370. fi
  1371. msggroup
  1372. }
  1373. testdpkginstalled() {
  1374. msggroup 'testdpkginstalled'
  1375. testdpkgstatus 'ii' "$#" "$@"
  1376. msggroup
  1377. }
  1378. testdpkgnotinstalled() {
  1379. msggroup 'testdpkgnotinstalled'
  1380. testdpkgstatus 'ii' '0' "$@"
  1381. msggroup
  1382. }
  1383. testmarkedauto() {
  1384. msggroup 'testmarkedauto'
  1385. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
  1386. if [ -n "$1" ]; then
  1387. msgtest 'Test for correctly marked as auto-installed' "$*"
  1388. while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
  1389. else
  1390. msgtest 'Test for correctly marked as auto-installed' 'no package'
  1391. echo -n > "$COMPAREFILE"
  1392. fi
  1393. testoutputequal "$COMPAREFILE" aptmark showauto
  1394. msggroup
  1395. }
  1396. testmarkedmanual() {
  1397. msggroup 'testmarkedmanual'
  1398. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
  1399. if [ -n "$1" ]; then
  1400. msgtest 'Test for correctly marked as manually installed' "$*"
  1401. while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
  1402. else
  1403. msgtest 'Test for correctly marked as manually installed' 'no package'
  1404. echo -n > "$COMPAREFILE"
  1405. fi
  1406. testoutputequal "$COMPAREFILE" aptmark showmanual
  1407. msggroup
  1408. }
  1409. msgfailoutput() {
  1410. msgreportheader 'msgfailoutput'
  1411. local MSG="$1"
  1412. local OUTPUT="$2"
  1413. shift 2
  1414. if [ "$1" = 'grep' ]; then
  1415. echo >&2
  1416. while [ -n "$2" ]; do shift; done
  1417. echo "#### Complete file: $1 ####"
  1418. cat >&2 "$1" || true
  1419. echo '#### grep output ####'
  1420. elif [ "$1" = 'test' ]; then
  1421. echo >&2
  1422. # doesn't support ! or non-file flags
  1423. msgfailoutputstatfile() {
  1424. local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$'
  1425. if expr match "$1" "$FILEFLAGS" >/dev/null; then
  1426. echo "#### stat(2) of file: $2 ####"
  1427. stat "$2" || true
  1428. if test -d "$2"; then
  1429. echo "#### The directory contains: $2 ####"
  1430. ls >&2 "$2" || true
  1431. elif test -e "$2"; then
  1432. echo "#### Complete file: $2 ####"
  1433. cat >&2 "$2" || true
  1434. fi
  1435. fi
  1436. }
  1437. msgfailoutputstatfile "$2" "$3"
  1438. while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
  1439. shift 3
  1440. msgfailoutputstatfile "$2" "$3"
  1441. done
  1442. echo '#### test output ####'
  1443. fi
  1444. cat >&2 "$OUTPUT"
  1445. msgfail "$MSG"
  1446. }
  1447. testsuccesswithglobalerror() {
  1448. local TYPE="$1"
  1449. local ERRORS="$2"
  1450. shift 2
  1451. msggroup "$TYPE"
  1452. if [ "$1" = '--nomsg' ]; then
  1453. shift
  1454. else
  1455. msgtest 'Test for successful execution of' "$*"
  1456. fi
  1457. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
  1458. if "$@" >"${OUTPUT}" 2>&1; then
  1459. if expr match "$1" '^apt.*' >/dev/null; then
  1460. if grep -q -E ' runtime error: ' "$OUTPUT"; then
  1461. msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
  1462. elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
  1463. if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
  1464. if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
  1465. | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then
  1466. msgpass
  1467. else
  1468. msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
  1469. fi
  1470. else
  1471. msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
  1472. fi
  1473. elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
  1474. if grep -q -E "^N: " "$OUTPUT"; then
  1475. msgpass
  1476. else
  1477. msgfailoutput 'successful run, but output had no notices' "$OUTPUT" "$@"
  1478. fi
  1479. else
  1480. msgpass
  1481. fi
  1482. else
  1483. msgpass
  1484. fi
  1485. else
  1486. local EXITCODE=$?
  1487. msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
  1488. fi
  1489. aptautotest "$TYPE" "$@"
  1490. msggroup
  1491. }
  1492. testsuccesswithnotice() {
  1493. testsuccesswithglobalerror 'testsuccesswithnotice' 'WE' "$@"
  1494. }
  1495. testsuccess() {
  1496. testsuccesswithglobalerror 'testsuccess' 'NWE' "$@"
  1497. }
  1498. testwarning() {
  1499. msggroup 'testwarning'
  1500. if [ "$1" = '--nomsg' ]; then
  1501. shift
  1502. else
  1503. msgtest 'Test for successful execution with warnings of' "$*"
  1504. fi
  1505. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
  1506. if "$@" >"${OUTPUT}" 2>&1; then
  1507. if expr match "$1" '^apt.*' >/dev/null; then
  1508. if grep -q -E ' runtime error: ' "$OUTPUT"; then
  1509. msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
  1510. elif grep -q -E '^E: ' "$OUTPUT"; then
  1511. msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@"
  1512. elif ! grep -q -E '^W: ' "$OUTPUT"; then
  1513. msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@"
  1514. else
  1515. msgpass
  1516. fi
  1517. else
  1518. msgpass
  1519. fi
  1520. else
  1521. local EXITCODE=$?
  1522. msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
  1523. fi
  1524. aptautotest 'testwarning' "$@"
  1525. msggroup
  1526. }
  1527. testfailure() {
  1528. msggroup 'testfailure'
  1529. if [ "$1" = '--nomsg' ]; then
  1530. shift
  1531. else
  1532. msgtest 'Test for failure in execution of' "$*"
  1533. fi
  1534. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
  1535. if "$@" >"${OUTPUT}" 2>&1; then
  1536. local EXITCODE=$?
  1537. msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
  1538. else
  1539. local EXITCODE=$?
  1540. if expr match "$1" '^apt.*' >/dev/null; then
  1541. if [ "$1" = 'aptkey' ]; then
  1542. if grep -q -E " Can't check signature: " "$OUTPUT" || \
  1543. grep -q -E " BAD signature from " "$OUTPUT"; then
  1544. msgpass
  1545. else
  1546. msgfailoutput "run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
  1547. fi
  1548. else
  1549. if grep -q -E ' runtime error: ' "$OUTPUT"; then
  1550. msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
  1551. elif grep -q -E '==ERROR' "$OUTPUT"; then
  1552. msgfailoutput 'compiler sanitizers reported errors' "$OUTPUT" "$@"
  1553. elif ! grep -q -E '^E: ' "$OUTPUT"; then
  1554. msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
  1555. else
  1556. msgpass
  1557. fi
  1558. fi
  1559. else
  1560. msgpass
  1561. fi
  1562. fi
  1563. aptautotest 'testfailure' "$@"
  1564. msggroup
  1565. }
  1566. testreturnstateequal() {
  1567. local STATE="$1"
  1568. if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
  1569. local STATE="$2"
  1570. local TYPE="$3"
  1571. shift 3
  1572. msggroup "${STATE}equal"
  1573. if [ "$1" != '--nomsg' ]; then
  1574. local CMP="$1"
  1575. shift
  1576. testsuccesswithglobalerror "$STATE" "$TYPE" "$@"
  1577. testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
  1578. else
  1579. local CMP="$2"
  1580. shift 2
  1581. testsuccesswithglobalerror "$STATE" "$TYPE" "$@"
  1582. testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
  1583. fi
  1584. else
  1585. msggroup "${STATE}equal"
  1586. if [ "$2" != '--nomsg' ]; then
  1587. local CMP="$2"
  1588. shift 2
  1589. "$STATE" "$@"
  1590. testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
  1591. else
  1592. local CMP="$3"
  1593. shift 3
  1594. "$STATE" --nomsg "$@"
  1595. testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
  1596. fi
  1597. fi
  1598. msggroup
  1599. }
  1600. testsuccessequal() {
  1601. # we compare output, so we know perfectly well about N:
  1602. testreturnstateequal 'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
  1603. }
  1604. testwarningequal() {
  1605. testreturnstateequal 'testwarning' "$@"
  1606. }
  1607. testfailureequal() {
  1608. testreturnstateequal 'testfailure' "$@"
  1609. }
  1610. testfailuremsg() {
  1611. msggroup 'testfailuremsg'
  1612. local CMP="$1"
  1613. shift
  1614. testfailure "$@"
  1615. msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
  1616. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
  1617. grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
  1618. testoutputequal "$COMPAREFILE" echo "$CMP"
  1619. msggroup
  1620. }
  1621. testwarningmsg() {
  1622. msggroup 'testwarningmsg'
  1623. local CMP="$1"
  1624. shift
  1625. testwarning "$@"
  1626. msgtest 'Check that the output of the previous warned command has expected' 'warnings'
  1627. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
  1628. grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
  1629. testoutputequal "$COMPAREFILE" echo "$CMP"
  1630. msggroup
  1631. }
  1632. testfilestats() {
  1633. msggroup 'testfilestats'
  1634. msgtest "Test that file $1 has $2 $3" "$4"
  1635. if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
  1636. msgpass
  1637. else
  1638. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
  1639. {
  1640. ls -ld "$1" || true
  1641. echo -n "stat(1) reports for $2: "
  1642. stat --format "$2" "$1" || true
  1643. } >"$OUTPUT" 2>&1
  1644. msgfailoutput '' "$OUTPUT"
  1645. fi
  1646. msggroup
  1647. }
  1648. testaccessrights() {
  1649. msggroup 'testaccessrights'
  1650. testfilestats "$1" '%a' '=' "$2"
  1651. msggroup
  1652. }
  1653. testwebserverlaststatuscode() {
  1654. msggroup 'testwebserverlaststatuscode'
  1655. local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
  1656. local STATUS='downloaded/webserverstatus-statusfile.log'
  1657. rm -f "$DOWNLOG" "$STATUS"
  1658. msgtest 'Test last status code from the webserver was' "$1"
  1659. if downloadfile "http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
  1660. msgpass
  1661. else
  1662. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
  1663. {
  1664. if [ -n "$2" ]; then
  1665. shift
  1666. echo >&2 '#### Additionally provided output files contain:'
  1667. cat >&2 "$@"
  1668. fi
  1669. echo >&2 '#### Download log of the status code:'
  1670. cat >&2 "$DOWNLOG"
  1671. } >"$OUTPUT" 2>&1
  1672. msgfailoutput "Status was $(cat "$STATUS")" "$OUTPUT"
  1673. fi
  1674. msggroup
  1675. }
  1676. pause() {
  1677. echo "STOPPED execution. Press enter to continue"
  1678. local IGNORE
  1679. read IGNORE
  1680. }
  1681. listcurrentlistsdirectory() {
  1682. {
  1683. find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
  1684. stat --format '%U:%G:%a:%n' "$line"
  1685. done
  1686. find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
  1687. stat --format '%U:%G:%a:%s:%y:%n' "$line"
  1688. done
  1689. } | sort
  1690. }
  1691. ### convenience hacks ###
  1692. mkdir() {
  1693. # creating some directories by hand is a tedious task, so make it look simple
  1694. local PARAMS="$*"
  1695. if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
  1696. # only the last directory created by mkdir is effected by the -m !
  1697. command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
  1698. command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
  1699. command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
  1700. touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
  1701. if [ "$(id -u)" = '0' ]; then
  1702. chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
  1703. fi
  1704. else
  1705. command mkdir "$@"
  1706. fi
  1707. }
  1708. ### The following tests are run by most test methods automatically to check
  1709. ### general things about commands executed without writing the test every time.
  1710. aptautotest() {
  1711. local TESTCALL="$1"
  1712. local CMD="$2"
  1713. local FIRSTOPT="$3"
  1714. local AUTOTEST="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d '-')"
  1715. if command -v $AUTOTEST >/dev/null; then
  1716. shift 3
  1717. # save and restore the *.output files from other tests
  1718. # as we might otherwise override them in these automatic tests
  1719. rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
  1720. mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
  1721. mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
  1722. $AUTOTEST "$TESTCALL" "$@"
  1723. rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
  1724. mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
  1725. mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
  1726. fi
  1727. }
  1728. aptautotest_aptget_update() {
  1729. local TESTCALL="$1"
  1730. while [ -n "$2" ]; do
  1731. if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
  1732. shift
  1733. done
  1734. if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
  1735. testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
  1736. testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
  1737. # all copied files are properly chmodded
  1738. local backupIFS="$IFS"
  1739. IFS="$(printf "\n\b")"
  1740. for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
  1741. testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
  1742. done
  1743. IFS="$backupIFS"
  1744. if [ "$TESTCALL" = 'testsuccess' ]; then
  1745. # failure cases can retain partial files and such
  1746. testempty find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \( -name 'lock' -o -name '*.FAILED' \)
  1747. fi
  1748. }
  1749. aptautotest_apt_update() { aptautotest_aptget_update "$@"; }
  1750. aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; }
  1751. testaptautotestnodpkgwarning() {
  1752. local TESTCALL="$1"
  1753. while [ -n "$2" ]; do
  1754. if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi # simulation mode
  1755. if expr match "$2" '^-dy\?' >/dev/null 2>&1; then return; fi # download-only mode
  1756. shift
  1757. done
  1758. testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
  1759. }
  1760. aptautotest_aptget_install() { testaptautotestnodpkgwarning "$@"; }
  1761. aptautotest_aptget_remove() { testaptautotestnodpkgwarning "$@"; }
  1762. aptautotest_aptget_purge() { testaptautotestnodpkgwarning "$@"; }
  1763. aptautotest_apt_install() { testaptautotestnodpkgwarning "$@"; }
  1764. aptautotest_apt_remove() { testaptautotestnodpkgwarning "$@"; }
  1765. aptautotest_apt_purge() { testaptautotestnodpkgwarning "$@"; }