framework 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. #!/bin/sh -- # no runable script, just for vi
  2. EXIT_CODE=0
  3. # we all like colorful messages
  4. if [ "$MSGCOLOR" != 'NO' ]; then
  5. if [ ! -t 1 ]; then # but check that we output to a terminal
  6. export MSGCOLOR='NO'
  7. fi
  8. fi
  9. if [ "$MSGCOLOR" != 'NO' ]; then
  10. CERROR="\033[1;31m" # red
  11. CWARNING="\033[1;33m" # yellow
  12. CMSG="\033[1;32m" # green
  13. CINFO="\033[1;96m" # light blue
  14. CDEBUG="\033[1;94m" # blue
  15. CNORMAL="\033[0;39m" # default system console color
  16. CDONE="\033[1;32m" # green
  17. CPASS="\033[1;32m" # green
  18. CFAIL="\033[1;31m" # red
  19. CCMD="\033[1;35m" # pink
  20. fi
  21. msgprintf() {
  22. local START="$1"
  23. local MIDDLE="$2"
  24. local END="$3"
  25. shift 3
  26. if [ -n "$1" ]; then
  27. printf "$START " "$1"
  28. shift
  29. while [ -n "$1" ]; do
  30. printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')"
  31. shift
  32. done
  33. fi
  34. printf "${END}"
  35. }
  36. msgdie() { msgprintf "${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
  37. msgwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
  38. msgmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
  39. msginfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
  40. msgdebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
  41. msgdone() { msgprintf "${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
  42. msgnwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
  43. msgnmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
  44. msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
  45. msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
  46. msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
  47. msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
  48. msgskip() {
  49. if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
  50. else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
  51. }
  52. msgfail() {
  53. if [ $# -gt 0 ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
  54. else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
  55. if [ -n "$APT_DEBUG_TESTS" ]; then
  56. $SHELL
  57. fi
  58. EXIT_CODE=$((EXIT_CODE+1));
  59. }
  60. # enable / disable Debugging
  61. MSGLEVEL=${MSGLEVEL:-3}
  62. if [ $MSGLEVEL -le 0 ]; then
  63. msgdie() { true; }
  64. fi
  65. if [ $MSGLEVEL -le 1 ]; then
  66. msgwarn() { true; }
  67. msgnwarn() { true; }
  68. fi
  69. if [ $MSGLEVEL -le 2 ]; then
  70. msgmsg() { true; }
  71. msgnmsg() { true; }
  72. msgtest() { true; }
  73. msgpass() { printf " ${CPASS}P${CNORMAL}"; }
  74. fi
  75. if [ $MSGLEVEL -le 3 ]; then
  76. msginfo() { true; }
  77. msgninfo() { true; }
  78. fi
  79. if [ $MSGLEVEL -le 4 ]; then
  80. msgdebug() { true; }
  81. msgndebug() { true; }
  82. fi
  83. msgdone() {
  84. if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
  85. [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
  86. [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
  87. [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
  88. [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
  89. true;
  90. else
  91. printf "${CDONE}DONE${CNORMAL}\n";
  92. fi
  93. }
  94. getaptconfig() {
  95. if [ -f ./aptconfig.conf ]; then
  96. echo "./aptconfig.conf"
  97. elif [ -f ../aptconfig.conf ]; then
  98. echo "../aptconfig.conf"
  99. fi
  100. }
  101. runapt() {
  102. msgdebug "Executing: ${CCMD}$*${CDEBUG} "
  103. local CMD="$1"
  104. shift
  105. case $CMD in
  106. sh|aptitude|*/*|command) ;;
  107. *) CMD="${BUILDDIRECTORY}/$CMD";;
  108. esac
  109. MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
  110. }
  111. aptconfig() { runapt apt-config "$@"; }
  112. aptcache() { runapt apt-cache "$@"; }
  113. aptcdrom() { runapt apt-cdrom "$@"; }
  114. aptget() { runapt apt-get "$@"; }
  115. aptftparchive() { runapt apt-ftparchive "$@"; }
  116. aptkey() { runapt apt-key "$@"; }
  117. aptmark() { runapt apt-mark "$@"; }
  118. aptsortpkgs() { runapt apt-sortpkgs "$@"; }
  119. apt() { runapt apt "$@"; }
  120. apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
  121. aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
  122. aptitude() { runapt aptitude "$@"; }
  123. aptextracttemplates() { runapt apt-extracttemplates "$@"; }
  124. aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; }
  125. dpkg() {
  126. command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
  127. }
  128. dpkgcheckbuilddeps() {
  129. command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
  130. }
  131. gdb() {
  132. local CMD="$1"
  133. shift
  134. runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
  135. }
  136. exitwithstatus() {
  137. # error if we about to overflow, but ...
  138. # "255 failures ought to be enough for everybody"
  139. if [ $EXIT_CODE -gt 255 ]; then
  140. msgdie "Total failure count $EXIT_CODE too big"
  141. fi
  142. exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
  143. }
  144. shellsetedetector() {
  145. local exit_status=$?
  146. if [ "$exit_status" != '0' ]; then
  147. printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
  148. if [ "$EXIT_CODE" = '0' ]; then
  149. EXIT_CODE="$exit_status"
  150. fi
  151. fi
  152. }
  153. addtrap() {
  154. if [ "$1" = 'prefix' ]; then
  155. CURRENTTRAP="$2 $CURRENTTRAP"
  156. else
  157. CURRENTTRAP="$CURRENTTRAP $1"
  158. fi
  159. trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  160. }
  161. setupenvironment() {
  162. # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
  163. if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
  164. unset TMPDIR
  165. fi
  166. TMPWORKINGDIRECTORY=$(mktemp -d)
  167. addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
  168. msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
  169. mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
  170. if [ "$(id -u)" = '0' ]; then
  171. # relax permissions so that running as root with user switching works
  172. umask 022
  173. chmod 711 "$TMPWORKINGDIRECTORY"
  174. chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded"
  175. fi
  176. TESTDIRECTORY=$(readlink -f $(dirname $0))
  177. # allow overriding the default BUILDDIR location
  178. BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
  179. LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
  180. METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
  181. APTHELPERBINDIR=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
  182. APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
  183. APTINTERNALSOLVER=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
  184. test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
  185. # -----
  186. cd $TMPWORKINGDIRECTORY
  187. mkdir rootdir aptarchive keys
  188. cd rootdir
  189. mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
  190. mkdir -p usr/bin var/cache var/lib/apt var/log tmp
  191. mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
  192. touch var/lib/dpkg/available
  193. mkdir -p usr/lib/apt
  194. ln -s ${METHODSDIR} usr/lib/apt/methods
  195. if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
  196. mkdir -p usr/lib/apt/solvers
  197. ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump
  198. ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt
  199. echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc/apt/apt.conf.d/externalsolver.conf
  200. fi
  201. # use the autoremove from the BUILDDIRECTORY if its there, otherwise
  202. # system
  203. if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
  204. ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
  205. else
  206. ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
  207. fi
  208. cd ..
  209. local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
  210. if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
  211. cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
  212. fi
  213. local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
  214. if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
  215. cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
  216. fi
  217. cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
  218. chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
  219. ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  220. echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
  221. echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
  222. echo "Debug::NoLocking \"true\";" >> aptconfig.conf
  223. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  224. echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
  225. # store apt-key were we can access it, even if we run it as a different user
  226. # destroys coverage reporting though, so just do it for root for now
  227. if [ "$(id -u)" = '0' ]; then
  228. cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
  229. chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
  230. echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
  231. else
  232. echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
  233. fi
  234. echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
  235. echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
  236. echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
  237. echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
  238. echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
  239. if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
  240. echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
  241. fi
  242. echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
  243. echo 'quiet::NoUpdate "true";' >> aptconfig.conf
  244. echo 'quiet::NoStatistic "true";' >> aptconfig.conf
  245. # too distracting for users, but helpful to detect changes
  246. echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
  247. # in testcases, it can appear as if localhost has a rotation setup,
  248. # hide this as we can't really deal with it properly
  249. echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
  250. cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
  251. if [ "$(id -u)" = '0' ]; then
  252. chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
  253. fi
  254. echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https
  255. echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
  256. configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
  257. # Acquire::AllowInsecureRepositories=false is not yet the default
  258. # but we want it to be the default soon
  259. configallowinsecurerepositories "false";
  260. # cleanup the environment a bit
  261. # prefer our apt binaries over the system apt binaries
  262. export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
  263. export LC_ALL=C.UTF-8
  264. unset LANGUAGE APT_CONFIG
  265. unset GREP_OPTIONS DEB_BUILD_PROFILES
  266. msgdone "info"
  267. }
  268. getarchitecture() {
  269. if [ "$1" = "native" -o -z "$1" ]; then
  270. eval `aptconfig shell ARCH APT::Architecture`
  271. if [ -n "$ARCH" ]; then
  272. echo $ARCH
  273. else
  274. dpkg --print-architecture
  275. fi
  276. else
  277. echo $1
  278. fi
  279. }
  280. getarchitectures() {
  281. echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  282. }
  283. getarchitecturesfromcommalist() {
  284. echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
  285. }
  286. configarchitecture() {
  287. {
  288. echo "APT::Architecture \"$(getarchitecture $1)\";"
  289. while [ -n "$1" ]; do
  290. echo "APT::Architectures:: \"$(getarchitecture $1)\";"
  291. shift
  292. done
  293. } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
  294. configdpkg
  295. }
  296. configdpkg() {
  297. if [ ! -e rootdir/var/lib/dpkg/status ]; then
  298. local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
  299. if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
  300. cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
  301. else
  302. echo -n > rootdir/var/lib/dpkg/status
  303. fi
  304. fi
  305. rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
  306. if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
  307. local ARCHS="$(getarchitectures)"
  308. if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
  309. DPKGARCH="$(dpkg --print-architecture)"
  310. for ARCH in ${ARCHS}; do
  311. if [ "${ARCH}" != "${DPKGARCH}" ]; then
  312. if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
  313. # old-style used e.g. in Ubuntu-P – and as it seems travis
  314. echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  315. echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  316. fi
  317. fi
  318. done
  319. if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
  320. # dpkg doesn't really check the version as long as it is fully installed,
  321. # but just to be sure we choose one above the required version
  322. insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
  323. fi
  324. fi
  325. fi
  326. }
  327. configallowinsecurerepositories() {
  328. echo "Acquire::AllowInsecureRepositories \"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
  329. }
  330. configcompression() {
  331. while [ -n "$1" ]; do
  332. case "$1" in
  333. '.') printf ".\t.\tcat\n";;
  334. 'gz') printf "gzip\tgz\tgzip\n";;
  335. 'bz2') printf "bzip2\tbz2\tbzip2\n";;
  336. 'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
  337. 'xz') printf "xz\txz\txz\n";;
  338. *) printf "$1\t$1\t$1\n";;
  339. esac
  340. shift
  341. done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
  342. }
  343. forcecompressor() {
  344. COMPRESSOR="$1"
  345. COMPRESSOR_CMD="$1"
  346. case $COMPRESSOR in
  347. gzip) COMPRESS='gz';;
  348. bzip2) COMPRESS='bz2';;
  349. lzma) COMPRESS='lzma';;
  350. xz) COMPRESS='xz';;
  351. *) msgdie "Compressor $COMPRESSOR is unknown to framework, so can't be forced by forcecompressor!";;
  352. esac
  353. local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
  354. echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
  355. Dir::Bin::uncompressed \"/does/not/exist\";
  356. Dir::Bin::gzip \"/does/not/exist\";
  357. Dir::Bin::bzip2 \"/does/not/exist\";
  358. Dir::Bin::lzma \"/does/not/exist\";
  359. Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
  360. if [ -e "/bin/${COMPRESSOR}" ]; then
  361. echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
  362. elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
  363. echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
  364. elif [ "${COMPRESSOR}" = 'lzma' ]; then
  365. echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
  366. COMPRESSOR_CMD='xz --format=lzma'
  367. else
  368. msgtest 'Test for availability of compressor' "${COMPRESSOR}"
  369. msgfail
  370. fi
  371. }
  372. setupsimplenativepackage() {
  373. local NAME="$1"
  374. local ARCH="$2"
  375. local VERSION="$3"
  376. local RELEASE="${4:-unstable}"
  377. local DEPENDENCIES="$5"
  378. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  379. If you find such a package installed on your system,
  380. something went horribly wrong! They are autogenerated
  381. und used only by testcases and surf no other propose…"}"
  382. local SECTION="${7:-others}"
  383. local DISTSECTION
  384. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  385. DISTSECTION="main"
  386. else
  387. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  388. fi
  389. local BUILDDIR=incoming/${NAME}-${VERSION}
  390. mkdir -p ${BUILDDIR}/debian/source
  391. cd ${BUILDDIR}
  392. echo "* most suckless software product ever" > FEATURES
  393. test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
  394. test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
  395. * Initial release
  396. -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
  397. test -e debian/control || echo "Source: $NAME
  398. Section: $SECTION
  399. Priority: optional
  400. Maintainer: Joe Sixpack <joe@example.org>
  401. Build-Depends: debhelper (>= 7)
  402. Standards-Version: 3.9.1
  403. Package: $NAME" > debian/control
  404. if [ "$ARCH" = 'all' ]; then
  405. echo "Architecture: all" >> debian/control
  406. else
  407. echo "Architecture: any" >> debian/control
  408. fi
  409. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
  410. echo "Description: $DESCRIPTION" >> debian/control
  411. test -e debian/compat || echo "7" > debian/compat
  412. test -e debian/source/format || echo "3.0 (native)" > debian/source/format
  413. test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
  414. cd - > /dev/null
  415. }
  416. buildsimplenativepackage() {
  417. local NAME="$1"
  418. local ARCH="$2"
  419. local VERSION="$3"
  420. local RELEASE="${4:-unstable}"
  421. local DEPENDENCIES="$5"
  422. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  423. If you find such a package installed on your system,
  424. something went horribly wrong! They are autogenerated
  425. und used only by testcases and surf no other propose…"}"
  426. local SECTION="${7:-others}"
  427. local PRIORITY="${8:-optional}"
  428. local FILE_TREE="$9"
  429. local COMPRESS_TYPE="${10:-gzip}"
  430. local DISTSECTION
  431. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  432. DISTSECTION="main"
  433. else
  434. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  435. fi
  436. local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
  437. msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
  438. mkdir -p $BUILDDIR/debian/source
  439. echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
  440. echo "#!/bin/sh
  441. echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
  442. echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
  443. echo "$NAME ($VERSION) $RELEASE; urgency=low
  444. * Initial release
  445. -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
  446. echo "Source: $NAME
  447. Section: $SECTION
  448. Priority: $PRIORITY
  449. Maintainer: Joe Sixpack <joe@example.org>
  450. Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
  451. local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
  452. test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
  453. echo "
  454. Package: $NAME" >> ${BUILDDIR}/debian/control
  455. if [ "$ARCH" = 'all' ]; then
  456. echo "Architecture: all" >> ${BUILDDIR}/debian/control
  457. else
  458. echo "Architecture: any" >> ${BUILDDIR}/debian/control
  459. fi
  460. local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
  461. test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
  462. echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
  463. echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
  464. (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
  465. | while read SRC; do
  466. echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
  467. # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
  468. # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
  469. # adv --yes --default-key 'Joe Sixpack' \
  470. # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  471. # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  472. # fi
  473. done
  474. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  475. rm -rf ${BUILDDIR}/debian/tmp
  476. mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
  477. cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
  478. cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
  479. if [ -n "$FILE_TREE" ]; then
  480. cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
  481. fi
  482. (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
  483. (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
  484. local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
  485. # ensure the right permissions as dpkg-deb ensists
  486. chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
  487. if ! dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. >$LOG 2>&1; then
  488. cat $LOG
  489. false
  490. fi
  491. rm $LOG
  492. echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
  493. done
  494. mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
  495. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
  496. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
  497. rm -rf "${BUILDDIR}"
  498. msgdone "info"
  499. }
  500. buildpackage() {
  501. local BUILDDIR=$1
  502. local RELEASE=$2
  503. local SECTION=$3
  504. local ARCH=$(getarchitecture $4)
  505. local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
  506. local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
  507. msgninfo "Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
  508. cd $BUILDDIR
  509. if [ "$ARCH" = "all" ]; then
  510. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  511. fi
  512. if ! dpkg-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
  513. cat $BUILDLOG
  514. false
  515. fi
  516. local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
  517. local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
  518. cd - > /dev/null
  519. for PKG in $PKGS; do
  520. echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
  521. done
  522. for SRC in $SRCS; do
  523. echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
  524. done
  525. msgdone "info"
  526. }
  527. buildaptarchive() {
  528. if [ -d incoming ]; then
  529. buildaptarchivefromincoming "$@"
  530. else
  531. buildaptarchivefromfiles "$@"
  532. fi
  533. }
  534. createaptftparchiveconfig() {
  535. local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
  536. COMPRESSORS="${COMPRESSORS%* }"
  537. local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
  538. if [ -z "$ARCHS" ]; then
  539. # the pool is empty, so we will operate on faked packages - let us use the configured archs
  540. ARCHS="$(getarchitectures)"
  541. fi
  542. echo -n 'Dir {
  543. ArchiveDir "' >> ftparchive.conf
  544. echo -n $(readlink -f .) >> ftparchive.conf
  545. echo -n '";
  546. CacheDir "' >> ftparchive.conf
  547. echo -n $(readlink -f ..) >> ftparchive.conf
  548. echo -n '";
  549. FileListDir "' >> ftparchive.conf
  550. echo -n $(readlink -f pool/) >> ftparchive.conf
  551. echo -n '";
  552. };
  553. Default {
  554. Packages::Compress "'"$COMPRESSORS"'";
  555. Sources::Compress "'"$COMPRESSORS"'";
  556. Contents::Compress "'"$COMPRESSORS"'";
  557. Translation::Compress "'"$COMPRESSORS"'";
  558. LongDescription "false";
  559. };
  560. TreeDefault {
  561. Directory "pool/";
  562. SrcDirectory "pool/";
  563. };
  564. APT {
  565. FTPArchive {
  566. Release {
  567. Origin "joesixpack";
  568. Label "apttestcases";
  569. Suite "unstable";
  570. Description "repository with dummy packages";
  571. Architectures "' >> ftparchive.conf
  572. echo -n "$ARCHS" >> ftparchive.conf
  573. echo 'source";
  574. };
  575. };
  576. };' >> ftparchive.conf
  577. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  578. echo -n 'tree "dists/' >> ftparchive.conf
  579. echo -n "$DIST" >> ftparchive.conf
  580. echo -n '" {
  581. Architectures "' >> ftparchive.conf
  582. echo -n "$ARCHS" >> ftparchive.conf
  583. echo -n 'source";
  584. FileList "' >> ftparchive.conf
  585. echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
  586. echo -n '";
  587. SourceFileList "' >> ftparchive.conf
  588. echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
  589. echo -n '";
  590. Sections "' >> ftparchive.conf
  591. echo -n "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')" >> ftparchive.conf
  592. echo '";
  593. };' >> ftparchive.conf
  594. done
  595. }
  596. buildaptftparchivedirectorystructure() {
  597. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  598. for DIST in $DISTS; do
  599. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  600. for SECTION in $SECTIONS; do
  601. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  602. for ARCH in $ARCHS; do
  603. mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
  604. done
  605. mkdir -p dists/${DIST}/${SECTION}/source
  606. mkdir -p dists/${DIST}/${SECTION}/i18n
  607. done
  608. done
  609. }
  610. insertpackage() {
  611. local RELEASES="$1"
  612. local NAME="$2"
  613. local ARCH="$3"
  614. local VERSION="$4"
  615. local DEPENDENCIES="$5"
  616. local PRIORITY="${6:-optional}"
  617. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
  618. If you find such a package installed on your system,
  619. something went horribly wrong! They are autogenerated
  620. und used only by testcases and surf no other propose…"}"
  621. local ARCHS=""
  622. for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
  623. if [ "$RELEASE" = 'installed' ]; then
  624. insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
  625. continue
  626. fi
  627. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  628. if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
  629. ARCHS="$(getarchitectures)"
  630. else
  631. ARCHS="$arch"
  632. fi
  633. for BUILDARCH in $ARCHS; do
  634. local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
  635. mkdir -p $PPATH
  636. local FILE="${PPATH}/Packages"
  637. echo "Package: $NAME
  638. Priority: $PRIORITY
  639. Section: other
  640. Installed-Size: 42
  641. Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
  642. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  643. echo "Version: $VERSION
  644. Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
  645. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  646. echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
  647. echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
  648. echo >> $FILE
  649. done
  650. done
  651. mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
  652. touch aptarchive/dists/${RELEASE}/main/source/Sources
  653. echo "Package: $NAME
  654. Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
  655. Description-en: $DESCRIPTION
  656. " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
  657. done
  658. }
  659. insertsource() {
  660. local RELEASE="$1"
  661. local NAME="$2"
  662. local ARCH="$3"
  663. local VERSION="$4"
  664. local DEPENDENCIES="$5"
  665. local ARCHS=""
  666. local SPATH="aptarchive/dists/${RELEASE}/main/source"
  667. mkdir -p $SPATH
  668. local FILE="${SPATH}/Sources"
  669. echo "Package: $NAME
  670. Binary: $NAME
  671. Version: $VERSION
  672. Maintainer: Joe Sixpack <joe@example.org>
  673. Architecture: $ARCH" >> $FILE
  674. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  675. echo "Files:
  676. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
  677. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
  678. " >> $FILE
  679. }
  680. insertinstalledpackage() {
  681. local NAME="$1"
  682. local ARCH="$2"
  683. local VERSION="$3"
  684. local DEPENDENCIES="$4"
  685. local PRIORITY="${5:-optional}"
  686. local STATUS="${6:-install ok installed}"
  687. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
  688. If you find such a package installed on your system,
  689. something went horribly wrong! They are autogenerated
  690. und used only by testcases and surf no other propose…"}"
  691. local FILE='rootdir/var/lib/dpkg/status'
  692. local INFO='rootdir/var/lib/dpkg/info'
  693. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  694. echo "Package: $NAME
  695. Status: $STATUS
  696. Priority: $PRIORITY
  697. Section: other
  698. Installed-Size: 42
  699. Maintainer: Joe Sixpack <joe@example.org>
  700. Version: $VERSION" >> $FILE
  701. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  702. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  703. echo "Description: $DESCRIPTION" >> $FILE
  704. echo >> $FILE
  705. if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
  706. echo -n > ${INFO}/${NAME}:${arch}.list
  707. else
  708. echo -n > ${INFO}/${NAME}.list
  709. fi
  710. done
  711. }
  712. buildaptarchivefromincoming() {
  713. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
  714. cd aptarchive
  715. [ -e pool ] || ln -s ../incoming pool
  716. [ -e ftparchive.conf ] || createaptftparchiveconfig
  717. [ -e dists ] || buildaptftparchivedirectorystructure
  718. msgninfo "\tGenerate Packages, Sources and Contents files… "
  719. aptftparchive -qq generate ftparchive.conf
  720. cd - > /dev/null
  721. msgdone "info"
  722. generatereleasefiles "$@"
  723. }
  724. buildaptarchivefromfiles() {
  725. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
  726. find aptarchive -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
  727. msgninfo "\t${line} file… "
  728. compressfile "$line" "$1"
  729. msgdone "info"
  730. done
  731. generatereleasefiles "$@"
  732. }
  733. compressfile() {
  734. cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
  735. if [ "$compressor" = '.' ]; then
  736. if [ -n "$2" ]; then
  737. touch -d "$2" "$1"
  738. fi
  739. continue
  740. fi
  741. cat "$1" | $command > "${1}.${extension}"
  742. if [ -n "$2" ]; then
  743. touch -d "$2" "${1}.${extension}"
  744. fi
  745. done
  746. }
  747. # can be overridden by testcases for their pleasure
  748. getcodenamefromsuite() {
  749. case "$1" in
  750. unstable) echo 'sid';;
  751. *) echo -n "$1";;
  752. esac
  753. }
  754. getreleaseversionfromsuite() { true; }
  755. getlabelfromsuite() { true; }
  756. generatereleasefiles() {
  757. # $1 is the Date header and $2 is the ValidUntil header to be set
  758. # both should be given in notation date/touch can understand
  759. msgninfo "\tGenerate Release files… "
  760. if [ -e aptarchive/dists ]; then
  761. for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
  762. local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
  763. local CODENAME="$(getcodenamefromsuite $SUITE)"
  764. local VERSION="$(getreleaseversionfromsuite $SUITE)"
  765. local LABEL="$(getlabelfromsuite $SUITE)"
  766. if [ -n "$VERSION" ]; then
  767. VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
  768. fi
  769. if [ -n "$LABEL" ]; then
  770. LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
  771. fi
  772. aptftparchive -qq release $dir \
  773. -o APT::FTPArchive::Release::Suite="${SUITE}" \
  774. -o APT::FTPArchive::Release::Codename="${CODENAME}" \
  775. ${LABEL} \
  776. ${VERSION} \
  777. | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
  778. if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
  779. sed -i '/^Date: / a\
  780. NotAutomatic: yes' $dir/Release
  781. fi
  782. if [ -n "$1" -a "$1" != "now" ]; then
  783. sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
  784. fi
  785. if [ -n "$2" ]; then
  786. sed -i "/^Date: / a\
  787. Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
  788. fi
  789. done
  790. else
  791. aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
  792. fi
  793. if [ -n "$1" -a "$1" != "now" ]; then
  794. for release in $(find ./aptarchive -name 'Release'); do
  795. touch -d "$1" $release
  796. done
  797. fi
  798. msgdone "info"
  799. }
  800. setupdistsaptarchive() {
  801. local APTARCHIVE=$(readlink -f ./aptarchive)
  802. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  803. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  804. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  805. SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  806. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  807. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
  808. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
  809. msgdone "info"
  810. done
  811. }
  812. setupflataptarchive() {
  813. local APTARCHIVE=$(readlink -f ./aptarchive)
  814. if [ -f ${APTARCHIVE}/Packages ]; then
  815. msgninfo "\tadd deb sources.list line… "
  816. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  817. msgdone "info"
  818. else
  819. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  820. fi
  821. if [ -f ${APTARCHIVE}/Sources ]; then
  822. msgninfo "\tadd deb-src sources.list line… "
  823. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  824. msgdone "info"
  825. else
  826. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  827. fi
  828. }
  829. setupaptarchive() {
  830. local NOUPDATE=0
  831. if [ "$1" = '--no-update' ]; then
  832. NOUPDATE=1
  833. shift
  834. fi
  835. buildaptarchive "$@"
  836. if [ -e aptarchive/dists ]; then
  837. setupdistsaptarchive
  838. else
  839. setupflataptarchive
  840. fi
  841. signreleasefiles 'Joe Sixpack'
  842. if [ "1" != "$NOUPDATE" ]; then
  843. testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
  844. fi
  845. }
  846. signreleasefiles() {
  847. local SIGNER="${1:-Joe Sixpack}"
  848. local REPODIR="${2:-aptarchive}"
  849. local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
  850. local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
  851. msgninfo "\tSign archive with $SIGNER key $KEY… "
  852. local REXKEY='keys/rexexpired'
  853. local SECEXPIREBAK="${REXKEY}.sec.bak"
  854. local PUBEXPIREBAK="${REXKEY}.pub.bak"
  855. if [ "${SIGNER}" = 'Rex Expired' ]; then
  856. # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
  857. # option doesn't exist anymore (and using faketime would add a new obscure dependency)
  858. # therefore we 'temporary' make the key not expired and restore a backup after signing
  859. cp ${REXKEY}.sec $SECEXPIREBAK
  860. cp ${REXKEY}.pub $PUBEXPIREBAK
  861. local SECUNEXPIRED="${REXKEY}.sec.unexpired"
  862. local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
  863. if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
  864. cp $SECUNEXPIRED ${REXKEY}.sec
  865. cp $PUBUNEXPIRED ${REXKEY}.pub
  866. else
  867. if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
  868. cat setexpire.gpg
  869. exit 1
  870. fi
  871. cp ${REXKEY}.sec $SECUNEXPIRED
  872. cp ${REXKEY}.pub $PUBUNEXPIRED
  873. fi
  874. fi
  875. for RELEASE in $(find ${REPODIR}/ -name Release); do
  876. $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
  877. local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
  878. $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
  879. # we might have set a specific date for the Release file, so copy it
  880. touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
  881. done
  882. if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
  883. mv -f $SECEXPIREBAK ${REXKEY}.sec
  884. mv -f $PUBEXPIREBAK ${REXKEY}.pub
  885. fi
  886. msgdone "info"
  887. }
  888. webserverconfig() {
  889. local NOCHECK=false
  890. if [ "$1" = '--no-check' ]; then
  891. NOCHECK=true
  892. shift
  893. fi
  894. local DOWNLOG='rootdir/tmp/download-testfile.log'
  895. local STATUS='downloaded/webserverconfig.status'
  896. rm -f "$STATUS" "$DOWNLOG"
  897. local URI
  898. if [ -n "$2" ]; then
  899. msgtest "Set webserver config option '${1}' to" "$2"
  900. URI="http://localhost:8080/_config/set/${1}/${2}"
  901. else
  902. msgtest 'Clear webserver config option' "${1}"
  903. URI="http://localhost:8080/_config/clear/${1}"
  904. fi
  905. if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
  906. msgpass
  907. else
  908. cat "$DOWNLOG" "$STATUS" || true
  909. msgfail
  910. fi
  911. $NOCHECK || testwebserverlaststatuscode '200'
  912. }
  913. rewritesourceslist() {
  914. local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
  915. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  916. sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
  917. done
  918. }
  919. # wait for up to 10s for a pid file to appear to avoid possible race
  920. # when a helper is started and dosn't write the PID quick enough
  921. waitforpidfile() {
  922. local PIDFILE="$1"
  923. for i in $(seq 10); do
  924. if test -s "$PIDFILE"; then
  925. return 0
  926. fi
  927. sleep 1
  928. done
  929. msgdie "waiting for $PIDFILE failed"
  930. return 1
  931. }
  932. changetowebserver() {
  933. if [ "$1" != '--no-rewrite' ]; then
  934. rewritesourceslist 'http://localhost:8080/'
  935. else
  936. shift
  937. fi
  938. if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
  939. cd aptarchive
  940. local LOG="webserver.log"
  941. if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
  942. cat $LOG
  943. false
  944. fi
  945. waitforpidfile aptwebserver.pid
  946. local PID="$(cat aptwebserver.pid)"
  947. if [ -z "$PID" ]; then
  948. msgdie 'Could not fork aptwebserver successfully'
  949. fi
  950. addtrap "kill $PID;"
  951. cd - > /dev/null
  952. else
  953. msgdie 'You have to build aptwerbserver or install a webserver'
  954. fi
  955. }
  956. changetohttpswebserver() {
  957. if ! which stunnel4 >/dev/null; then
  958. msgdie 'You need to install stunnel4 for https testcases'
  959. fi
  960. if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
  961. changetowebserver --no-rewrite "$@"
  962. fi
  963. echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
  964. cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
  965. output = /dev/null
  966. [https]
  967. accept = 4433
  968. connect = 8080
  969. " > ${TMPWORKINGDIRECTORY}/stunnel.conf
  970. stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
  971. waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
  972. local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
  973. if [ -z "$PID" ]; then
  974. msgdie 'Could not fork stunnel4 successfully'
  975. fi
  976. addtrap 'prefix' "kill ${PID};"
  977. rewritesourceslist 'https://localhost:4433/'
  978. }
  979. changetocdrom() {
  980. mkdir -p rootdir/media/cdrom/.disk
  981. local CD="$(readlink -f rootdir/media/cdrom)"
  982. echo "acquire::cdrom::mount \"${CD}\";
  983. acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
  984. acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
  985. acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
  986. echo -n "$1" > ${CD}/.disk/info
  987. if [ ! -d aptarchive/dists ]; then
  988. msgdie 'Flat file archive cdroms can not be created currently'
  989. return 1
  990. fi
  991. mv aptarchive/dists "$CD"
  992. ln -s "$(readlink -f ./incoming)" $CD/pool
  993. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  994. # start with an unmounted disk
  995. mv "${CD}" "${CD}-unmounted"
  996. # we don't want the disk to be modifiable
  997. addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
  998. chmod -R 555 rootdir/media/cdrom-unmounted/dists
  999. }
  1000. downloadfile() {
  1001. local PROTO="$(echo "$1" | cut -d':' -f 1 )"
  1002. apthelper -o Debug::Acquire::${PROTO}=1 \
  1003. download-file "$1" "$2" 2>&1 || true
  1004. # only if the file exists the download was successful
  1005. if [ -r "$2" ]; then
  1006. return 0
  1007. else
  1008. return 1
  1009. fi
  1010. }
  1011. checkdiff() {
  1012. local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  1013. if [ -n "$DIFFTEXT" ]; then
  1014. echo >&2
  1015. echo >&2 "$DIFFTEXT"
  1016. return 1
  1017. else
  1018. return 0
  1019. fi
  1020. }
  1021. testfileequal() {
  1022. local FILE="$1"
  1023. shift
  1024. msgtest "Test for correctness of file" "$FILE"
  1025. if [ -z "$*" ]; then
  1026. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  1027. else
  1028. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  1029. fi
  1030. }
  1031. testempty() {
  1032. msgtest "Test for no output of" "$*"
  1033. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
  1034. if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
  1035. msgpass
  1036. else
  1037. cat $COMPAREFILE
  1038. msgfail
  1039. fi
  1040. aptautotest 'testempty' "$@"
  1041. }
  1042. testequal() {
  1043. local MSG='Test of equality of'
  1044. if [ "$1" = '--nomsg' ]; then
  1045. MSG=''
  1046. shift
  1047. fi
  1048. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
  1049. echo "$1" > $COMPAREFILE
  1050. shift
  1051. if [ -n "$MSG" ]; then
  1052. msgtest "$MSG" "$*"
  1053. fi
  1054. "$@" 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  1055. aptautotest 'testequal' "$@"
  1056. }
  1057. testequalor2() {
  1058. local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
  1059. local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
  1060. local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
  1061. echo "$1" > $COMPAREFILE1
  1062. echo "$2" > $COMPAREFILE2
  1063. shift 2
  1064. msgtest "Test for equality OR of" "$*"
  1065. "$@" >$COMPAREAGAINST 2>&1 || true
  1066. if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
  1067. checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
  1068. then
  1069. msgpass
  1070. else
  1071. echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
  1072. checkdiff $COMPAREFILE1 $COMPAREAGAINST || true
  1073. echo -n "${CINFO}Diff against OR 2${CNORMAL}"
  1074. checkdiff $COMPAREFILE2 $COMPAREAGAINST || true
  1075. msgfail
  1076. fi
  1077. aptautotest 'testequalor2' "$@"
  1078. }
  1079. testshowvirtual() {
  1080. local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
  1081. local PACKAGE="$1"
  1082. shift
  1083. while [ -n "$1" ]; do
  1084. VIRTUAL="${VIRTUAL}
  1085. N: Can't select versions from package '$1' as it is purely virtual"
  1086. PACKAGE="${PACKAGE} $1"
  1087. shift
  1088. done
  1089. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  1090. VIRTUAL="${VIRTUAL}
  1091. N: No packages found"
  1092. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
  1093. local ARCH="$(getarchitecture 'native')"
  1094. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  1095. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  1096. }
  1097. testnopackage() {
  1098. msgtest "Test for non-existent packages" "apt-cache show $*"
  1099. local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
  1100. if [ -n "$SHOWPKG" ]; then
  1101. echo >&2
  1102. echo >&2 "$SHOWPKG"
  1103. msgfail
  1104. else
  1105. msgpass
  1106. fi
  1107. }
  1108. testdpkginstalled() {
  1109. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  1110. local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
  1111. if [ "$PKGS" != $# ]; then
  1112. echo >&2 $PKGS
  1113. dpkg -l "$@" | grep '^[a-z]' >&2
  1114. msgfail
  1115. else
  1116. msgpass
  1117. fi
  1118. }
  1119. testdpkgnotinstalled() {
  1120. msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
  1121. local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
  1122. if [ "$PKGS" != 0 ]; then
  1123. echo
  1124. dpkg -l "$@" | grep '^[a-z]' >&2
  1125. msgfail
  1126. else
  1127. msgpass
  1128. fi
  1129. }
  1130. testmarkedauto() {
  1131. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
  1132. if [ -n "$1" ]; then
  1133. msgtest 'Test for correctly marked as auto-installed' "$*"
  1134. while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
  1135. else
  1136. msgtest 'Test for correctly marked as auto-installed' 'no package'
  1137. echo -n > $COMPAREFILE
  1138. fi
  1139. aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  1140. }
  1141. msgfailoutput() {
  1142. local MSG="$1"
  1143. local OUTPUT="$2"
  1144. shift 2
  1145. echo >&2
  1146. if [ "$1" = 'grep' ]; then
  1147. while [ -n "$2" ]; do shift; done
  1148. echo "#### Complete file: $1 ####"
  1149. cat >&2 "$1" || true
  1150. echo '#### grep output ####'
  1151. elif [ "$1" = 'test' ]; then
  1152. # doesn't support ! or non-file flags
  1153. msgfailoutputstatfile() {
  1154. local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$'
  1155. if expr match "$1" "$FILEFLAGS" >/dev/null; then
  1156. echo "#### stat(2) of file: $2 ####"
  1157. stat "$2" || true
  1158. fi
  1159. }
  1160. msgfailoutputstatfile "$2" "$3"
  1161. while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
  1162. shift 3
  1163. msgfailoutputstatfile "$2" "$3"
  1164. done
  1165. echo '#### test output ####'
  1166. fi
  1167. cat >&2 $OUTPUT
  1168. msgfail "$MSG"
  1169. }
  1170. testsuccess() {
  1171. if [ "$1" = '--nomsg' ]; then
  1172. shift
  1173. else
  1174. msgtest 'Test for successful execution of' "$*"
  1175. fi
  1176. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
  1177. if "$@" >${OUTPUT} 2>&1; then
  1178. if expr match "$1" '^apt.*' >/dev/null; then
  1179. if grep -q -E ' runtime error: ' "$OUTPUT"; then
  1180. msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
  1181. elif grep -q -E '^[WE]: ' "$OUTPUT"; then
  1182. msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
  1183. else
  1184. msgpass
  1185. fi
  1186. else
  1187. msgpass
  1188. fi
  1189. else
  1190. local EXITCODE=$?
  1191. msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
  1192. fi
  1193. aptautotest 'testsuccess' "$@"
  1194. }
  1195. testwarning() {
  1196. if [ "$1" = '--nomsg' ]; then
  1197. shift
  1198. else
  1199. msgtest 'Test for successful execution with warnings of' "$*"
  1200. fi
  1201. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
  1202. if "$@" >${OUTPUT} 2>&1; then
  1203. if expr match "$1" '^apt.*' >/dev/null; then
  1204. if grep -q -E ' runtime error: ' "$OUTPUT"; then
  1205. msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
  1206. elif grep -q -E '^E: ' "$OUTPUT"; then
  1207. msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@"
  1208. elif ! grep -q -E '^W: ' "$OUTPUT"; then
  1209. msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@"
  1210. else
  1211. msgpass
  1212. fi
  1213. else
  1214. msgpass
  1215. fi
  1216. else
  1217. local EXITCODE=$?
  1218. echo >&2
  1219. cat >&2 $OUTPUT
  1220. msgfail "exitcode $EXITCODE"
  1221. fi
  1222. aptautotest 'testwarning' "$@"
  1223. }
  1224. testfailure() {
  1225. if [ "$1" = '--nomsg' ]; then
  1226. shift
  1227. else
  1228. msgtest 'Test for failure in execution of' "$*"
  1229. fi
  1230. local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
  1231. if "$@" >${OUTPUT} 2>&1; then
  1232. local EXITCODE=$?
  1233. msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
  1234. else
  1235. local EXITCODE=$?
  1236. if expr match "$1" '^apt.*' >/dev/null; then
  1237. if grep -q -E ' runtime error: ' "$OUTPUT"; then
  1238. msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
  1239. elif ! grep -q -E '^E: ' "$OUTPUT"; then
  1240. msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
  1241. else
  1242. msgpass
  1243. fi
  1244. else
  1245. msgpass
  1246. fi
  1247. fi
  1248. aptautotest 'testfailure' "$@"
  1249. }
  1250. testfilestats() {
  1251. msgtest "Test that file $1 has $2 $3" "$4"
  1252. if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
  1253. msgpass
  1254. else
  1255. echo >&2
  1256. ls -l >&2 "$1"
  1257. echo -n >&2 "stat(1) reports for $2: "
  1258. stat --format "$2" "$1"
  1259. msgfail
  1260. fi
  1261. }
  1262. testaccessrights() {
  1263. testfilestats "$1" '%a' '=' "$2"
  1264. }
  1265. testwebserverlaststatuscode() {
  1266. local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
  1267. local STATUS='downloaded/webserverstatus-statusfile.log'
  1268. rm -f "$DOWNLOG" "$STATUS"
  1269. msgtest 'Test last status code from the webserver was' "$1"
  1270. if downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
  1271. msgpass
  1272. else
  1273. echo >&2
  1274. if [ -n "$2" ]; then
  1275. shift
  1276. echo >&2 '#### Additionally provided output files contain:'
  1277. cat >&2 "$@"
  1278. fi
  1279. echo >&2 '#### Download log of the status code:'
  1280. cat >&2 "$DOWNLOG"
  1281. msgfail "Status was $(cat "$STATUS")"
  1282. fi
  1283. }
  1284. pause() {
  1285. echo "STOPPED execution. Press enter to continue"
  1286. local IGNORE
  1287. read IGNORE
  1288. }
  1289. listcurrentlistsdirectory() {
  1290. find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
  1291. stat --format '%U:%G:%a:%n' "$line"
  1292. done
  1293. find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
  1294. stat --format '%U:%G:%a:%s:%y:%n' "$line"
  1295. done
  1296. }
  1297. ### The following tests are run by most test methods automatically to check
  1298. ### general things about commands executed without writing the test every time.
  1299. aptautotest() {
  1300. local TESTCALL="$1"
  1301. local CMD="$2"
  1302. local FIRSTOPT="$3"
  1303. local AUTOTEST="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
  1304. if command -v $AUTOTEST >/dev/null; then
  1305. shift 3
  1306. # save and restore the *.output files from other tests
  1307. # as we might otherwise override them in these automatic tests
  1308. rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
  1309. mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
  1310. mkdir ${TMPWORKINGDIRECTORY}/rootdir/tmp
  1311. $AUTOTEST "$TESTCALL" "$@"
  1312. rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
  1313. mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
  1314. mv ${TMPWORKINGDIRECTORY}/rootdir/tmp-before ${TMPWORKINGDIRECTORY}/rootdir/tmp
  1315. fi
  1316. }
  1317. aptautotest_aptget_update() {
  1318. if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
  1319. # all copied files are properly chmodded
  1320. for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f); do
  1321. testfilestats "$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
  1322. done
  1323. }
  1324. aptautotest_apt_update() { aptautotest_aptget_update "$@"; }