framework 46 KB

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