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.
 
 
 
 
 
 

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