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 "Debug::NoLocking \"true\";" >> aptconfig.conf
  225. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  226. echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
  227. # store apt-key were we can access it, even if we run it as a different user
  228. # destroys coverage reporting though, so just do it for root for now
  229. if [ "$(id -u)" = '0' ]; then
  230. cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
  231. chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
  232. echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
  233. else
  234. echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
  235. fi
  236. echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
  237. echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
  238. echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
  239. echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
  240. echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
  241. if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
  242. echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
  243. fi
  244. echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
  245. echo 'quiet::NoUpdate "true";' >> aptconfig.conf
  246. echo 'quiet::NoStatistic "true";' >> aptconfig.conf
  247. # too distracting for users, but helpful to detect changes
  248. echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
  249. # in testcases, it can appear as if localhost has a rotation setup,
  250. # hide this as we can't really deal with it properly
  251. echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
  252. cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
  253. if [ "$(id -u)" = '0' ]; then
  254. chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
  255. fi
  256. echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https
  257. echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
  258. configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
  259. # Acquire::AllowInsecureRepositories=false is not yet the default
  260. # but we want it to be the default soon
  261. configallowinsecurerepositories "false";
  262. # cleanup the environment a bit
  263. # prefer our apt binaries over the system apt binaries
  264. export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
  265. export LC_ALL=C.UTF-8
  266. unset LANGUAGE APT_CONFIG
  267. unset GREP_OPTIONS DEB_BUILD_PROFILES
  268. msgdone "info"
  269. }
  270. getarchitecture() {
  271. if [ "$1" = "native" -o -z "$1" ]; then
  272. eval `aptconfig shell ARCH APT::Architecture`
  273. if [ -n "$ARCH" ]; then
  274. echo $ARCH
  275. else
  276. dpkg --print-architecture
  277. fi
  278. else
  279. echo $1
  280. fi
  281. }
  282. getarchitectures() {
  283. echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  284. }
  285. getarchitecturesfromcommalist() {
  286. echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
  287. }
  288. configarchitecture() {
  289. {
  290. echo "APT::Architecture \"$(getarchitecture $1)\";"
  291. while [ -n "$1" ]; do
  292. echo "APT::Architectures:: \"$(getarchitecture $1)\";"
  293. shift
  294. done
  295. } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
  296. configdpkg
  297. }
  298. configdpkg() {
  299. if [ ! -e rootdir/var/lib/dpkg/status ]; then
  300. local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
  301. if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
  302. cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
  303. else
  304. echo -n > rootdir/var/lib/dpkg/status
  305. fi
  306. fi
  307. rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
  308. if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
  309. local ARCHS="$(getarchitectures)"
  310. if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
  311. DPKGARCH="$(dpkg --print-architecture)"
  312. for ARCH in ${ARCHS}; do
  313. if [ "${ARCH}" != "${DPKGARCH}" ]; then
  314. if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
  315. # old-style used e.g. in Ubuntu-P – and as it seems travis
  316. echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  317. echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  318. fi
  319. fi
  320. done
  321. if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
  322. # dpkg doesn't really check the version as long as it is fully installed,
  323. # but just to be sure we choose one above the required version
  324. insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
  325. fi
  326. fi
  327. fi
  328. }
  329. configallowinsecurerepositories() {
  330. echo "Acquire::AllowInsecureRepositories \"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
  331. }
  332. configcompression() {
  333. while [ -n "$1" ]; do
  334. case "$1" in
  335. '.') printf ".\t.\tcat\n";;
  336. 'gz') printf "gzip\tgz\tgzip\n";;
  337. 'bz2') printf "bzip2\tbz2\tbzip2\n";;
  338. 'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
  339. 'xz') printf "xz\txz\txz\n";;
  340. *) printf "$1\t$1\t$1\n";;
  341. esac
  342. shift
  343. done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
  344. }
  345. forcecompressor() {
  346. COMPRESSOR="$1"
  347. COMPRESSOR_CMD="$1"
  348. case $COMPRESSOR in
  349. gzip) COMPRESS='gz';;
  350. bzip2) COMPRESS='bz2';;
  351. lzma) COMPRESS='lzma';;
  352. xz) COMPRESS='xz';;
  353. *) msgdie "Compressor $COMPRESSOR is unknown to framework, so can't be forced by forcecompressor!";;
  354. esac
  355. local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
  356. echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
  357. Dir::Bin::uncompressed \"/does/not/exist\";
  358. Dir::Bin::gzip \"/does/not/exist\";
  359. Dir::Bin::bzip2 \"/does/not/exist\";
  360. Dir::Bin::lzma \"/does/not/exist\";
  361. Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
  362. if [ -e "/bin/${COMPRESSOR}" ]; then
  363. echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
  364. elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
  365. echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
  366. elif [ "${COMPRESSOR}" = 'lzma' ]; then
  367. echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
  368. COMPRESSOR_CMD='xz --format=lzma'
  369. else
  370. msgtest 'Test for availability of compressor' "${COMPRESSOR}"
  371. msgfail
  372. fi
  373. }
  374. setupsimplenativepackage() {
  375. local NAME="$1"
  376. local ARCH="$2"
  377. local VERSION="$3"
  378. local RELEASE="${4:-unstable}"
  379. local DEPENDENCIES="$5"
  380. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  381. If you find such a package installed on your system,
  382. something went horribly wrong! They are autogenerated
  383. und used only by testcases and surf no other propose…"}"
  384. local SECTION="${7:-others}"
  385. local DISTSECTION
  386. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  387. DISTSECTION="main"
  388. else
  389. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  390. fi
  391. local BUILDDIR=incoming/${NAME}-${VERSION}
  392. mkdir -p ${BUILDDIR}/debian/source
  393. cd ${BUILDDIR}
  394. echo "* most suckless software product ever" > FEATURES
  395. test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
  396. test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
  397. * Initial release
  398. -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
  399. test -e debian/control || echo "Source: $NAME
  400. Section: $SECTION
  401. Priority: optional
  402. Maintainer: Joe Sixpack <joe@example.org>
  403. Build-Depends: debhelper (>= 7)
  404. Standards-Version: 3.9.1
  405. Package: $NAME" > debian/control
  406. if [ "$ARCH" = 'all' ]; then
  407. echo "Architecture: all" >> debian/control
  408. else
  409. echo "Architecture: any" >> debian/control
  410. fi
  411. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
  412. echo "Description: $DESCRIPTION" >> debian/control
  413. test -e debian/compat || echo "7" > debian/compat
  414. test -e debian/source/format || echo "3.0 (native)" > debian/source/format
  415. test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
  416. cd - > /dev/null
  417. }
  418. buildsimplenativepackage() {
  419. local NAME="$1"
  420. local ARCH="$2"
  421. local VERSION="$3"
  422. local RELEASE="${4:-unstable}"
  423. local DEPENDENCIES="$5"
  424. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  425. If you find such a package installed on your system,
  426. something went horribly wrong! They are autogenerated
  427. und used only by testcases and surf no other propose…"}"
  428. local SECTION="${7:-others}"
  429. local PRIORITY="${8:-optional}"
  430. local FILE_TREE="$9"
  431. local COMPRESS_TYPE="${10:-gzip}"
  432. local DISTSECTION
  433. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  434. DISTSECTION="main"
  435. else
  436. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  437. fi
  438. local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
  439. msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
  440. mkdir -p $BUILDDIR/debian/source
  441. echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
  442. echo "#!/bin/sh
  443. echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
  444. echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
  445. echo "$NAME ($VERSION) $RELEASE; urgency=low
  446. * Initial release
  447. -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
  448. echo "Source: $NAME
  449. Section: $SECTION
  450. Priority: $PRIORITY
  451. Maintainer: Joe Sixpack <joe@example.org>
  452. Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
  453. local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
  454. test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
  455. echo "
  456. Package: $NAME" >> ${BUILDDIR}/debian/control
  457. if [ "$ARCH" = 'all' ]; then
  458. echo "Architecture: all" >> ${BUILDDIR}/debian/control
  459. else
  460. echo "Architecture: any" >> ${BUILDDIR}/debian/control
  461. fi
  462. local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
  463. test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
  464. echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
  465. echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
  466. (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
  467. | while read SRC; do
  468. echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
  469. # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
  470. # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
  471. # adv --yes --default-key 'Joe Sixpack' \
  472. # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  473. # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  474. # fi
  475. done
  476. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  477. rm -rf ${BUILDDIR}/debian/tmp
  478. mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
  479. cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
  480. cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
  481. if [ -n "$FILE_TREE" ]; then
  482. cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
  483. fi
  484. (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
  485. (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
  486. local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
  487. # ensure the right permissions as dpkg-deb ensists
  488. chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
  489. if ! dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. >$LOG 2>&1; then
  490. cat $LOG
  491. false
  492. fi
  493. rm $LOG
  494. echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
  495. done
  496. mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
  497. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
  498. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
  499. rm -rf "${BUILDDIR}"
  500. msgdone "info"
  501. }
  502. buildpackage() {
  503. local BUILDDIR=$1
  504. local RELEASE=$2
  505. local SECTION=$3
  506. local ARCH=$(getarchitecture $4)
  507. local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
  508. local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
  509. msgninfo "Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
  510. cd $BUILDDIR
  511. if [ "$ARCH" = "all" ]; then
  512. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  513. fi
  514. if ! dpkg-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
  515. cat $BUILDLOG
  516. false
  517. fi
  518. local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
  519. local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
  520. cd - > /dev/null
  521. for PKG in $PKGS; do
  522. echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
  523. done
  524. for SRC in $SRCS; do
  525. echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
  526. done
  527. msgdone "info"
  528. }
  529. buildaptarchive() {
  530. if [ -d incoming ]; then
  531. buildaptarchivefromincoming "$@"
  532. else
  533. buildaptarchivefromfiles "$@"
  534. fi
  535. }
  536. createaptftparchiveconfig() {
  537. local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
  538. COMPRESSORS="${COMPRESSORS%* }"
  539. 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' ' ')"
  540. if [ -z "$ARCHS" ]; then
  541. # the pool is empty, so we will operate on faked packages - let us use the configured archs
  542. ARCHS="$(getarchitectures)"
  543. fi
  544. echo -n 'Dir {
  545. ArchiveDir "' >> ftparchive.conf
  546. echo -n $(readlink -f .) >> ftparchive.conf
  547. echo -n '";
  548. CacheDir "' >> ftparchive.conf
  549. echo -n $(readlink -f ..) >> ftparchive.conf
  550. echo -n '";
  551. FileListDir "' >> ftparchive.conf
  552. echo -n $(readlink -f pool/) >> ftparchive.conf
  553. echo -n '";
  554. };
  555. Default {
  556. Packages::Compress "'"$COMPRESSORS"'";
  557. Sources::Compress "'"$COMPRESSORS"'";
  558. Contents::Compress "'"$COMPRESSORS"'";
  559. Translation::Compress "'"$COMPRESSORS"'";
  560. LongDescription "false";
  561. };
  562. TreeDefault {
  563. Directory "pool/";
  564. SrcDirectory "pool/";
  565. };
  566. APT {
  567. FTPArchive {
  568. Release {
  569. Origin "joesixpack";
  570. Label "apttestcases";
  571. Suite "unstable";
  572. Description "repository with dummy packages";
  573. Architectures "' >> ftparchive.conf
  574. echo -n "$ARCHS" >> ftparchive.conf
  575. echo 'source";
  576. };
  577. };
  578. };' >> ftparchive.conf
  579. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  580. echo -n 'tree "dists/' >> ftparchive.conf
  581. echo -n "$DIST" >> ftparchive.conf
  582. echo -n '" {
  583. Architectures "' >> ftparchive.conf
  584. echo -n "$ARCHS" >> ftparchive.conf
  585. echo -n 'source";
  586. FileList "' >> ftparchive.conf
  587. echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
  588. echo -n '";
  589. SourceFileList "' >> ftparchive.conf
  590. echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
  591. echo -n '";
  592. Sections "' >> ftparchive.conf
  593. 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
  594. echo '";
  595. };' >> ftparchive.conf
  596. done
  597. }
  598. buildaptftparchivedirectorystructure() {
  599. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  600. for DIST in $DISTS; do
  601. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  602. for SECTION in $SECTIONS; do
  603. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  604. for ARCH in $ARCHS; do
  605. mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
  606. done
  607. mkdir -p dists/${DIST}/${SECTION}/source
  608. mkdir -p dists/${DIST}/${SECTION}/i18n
  609. done
  610. done
  611. }
  612. insertpackage() {
  613. local RELEASES="$1"
  614. local NAME="$2"
  615. local ARCH="$3"
  616. local VERSION="$4"
  617. local DEPENDENCIES="$5"
  618. local PRIORITY="${6:-optional}"
  619. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
  620. If you find such a package installed on your system,
  621. something went horribly wrong! They are autogenerated
  622. und used only by testcases and surf no other propose…"}"
  623. local ARCHS=""
  624. for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
  625. if [ "$RELEASE" = 'installed' ]; then
  626. insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
  627. continue
  628. fi
  629. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  630. if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
  631. ARCHS="$(getarchitectures)"
  632. else
  633. ARCHS="$arch"
  634. fi
  635. for BUILDARCH in $ARCHS; do
  636. local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
  637. mkdir -p $PPATH
  638. local FILE="${PPATH}/Packages"
  639. echo "Package: $NAME
  640. Priority: $PRIORITY
  641. Section: other
  642. Installed-Size: 42
  643. Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
  644. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  645. echo "Version: $VERSION
  646. Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
  647. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  648. echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
  649. echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
  650. echo >> $FILE
  651. done
  652. done
  653. mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
  654. touch aptarchive/dists/${RELEASE}/main/source/Sources
  655. echo "Package: $NAME
  656. Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
  657. Description-en: $DESCRIPTION
  658. " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
  659. done
  660. }
  661. insertsource() {
  662. local RELEASE="$1"
  663. local NAME="$2"
  664. local ARCH="$3"
  665. local VERSION="$4"
  666. local DEPENDENCIES="$5"
  667. local ARCHS=""
  668. local SPATH="aptarchive/dists/${RELEASE}/main/source"
  669. mkdir -p $SPATH
  670. local FILE="${SPATH}/Sources"
  671. echo "Package: $NAME
  672. Binary: $NAME
  673. Version: $VERSION
  674. Maintainer: Joe Sixpack <joe@example.org>
  675. Architecture: $ARCH" >> $FILE
  676. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  677. echo "Files:
  678. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
  679. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
  680. " >> $FILE
  681. }
  682. insertinstalledpackage() {
  683. local NAME="$1"
  684. local ARCH="$2"
  685. local VERSION="$3"
  686. local DEPENDENCIES="$4"
  687. local PRIORITY="${5:-optional}"
  688. local STATUS="${6:-install ok installed}"
  689. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
  690. If you find such a package installed on your system,
  691. something went horribly wrong! They are autogenerated
  692. und used only by testcases and surf no other propose…"}"
  693. local FILE='rootdir/var/lib/dpkg/status'
  694. local INFO='rootdir/var/lib/dpkg/info'
  695. for arch in $(getarchitecturesfromcommalist "$ARCH"); do
  696. echo "Package: $NAME
  697. Status: $STATUS
  698. Priority: $PRIORITY
  699. Section: other
  700. Installed-Size: 42
  701. Maintainer: Joe Sixpack <joe@example.org>
  702. Version: $VERSION" >> $FILE
  703. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  704. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  705. echo "Description: $DESCRIPTION" >> $FILE
  706. echo >> $FILE
  707. if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
  708. echo -n > ${INFO}/${NAME}:${arch}.list
  709. else
  710. echo -n > ${INFO}/${NAME}.list
  711. fi
  712. done
  713. }
  714. buildaptarchivefromincoming() {
  715. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
  716. cd aptarchive
  717. [ -e pool ] || ln -s ../incoming pool
  718. [ -e ftparchive.conf ] || createaptftparchiveconfig
  719. [ -e dists ] || buildaptftparchivedirectorystructure
  720. msgninfo "\tGenerate Packages, Sources and Contents files… "
  721. aptftparchive -qq generate ftparchive.conf
  722. cd - > /dev/null
  723. msgdone "info"
  724. generatereleasefiles "$@"
  725. }
  726. buildaptarchivefromfiles() {
  727. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
  728. find aptarchive -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
  729. msgninfo "\t${line} file… "
  730. compressfile "$line" "$1"
  731. msgdone "info"
  732. done
  733. generatereleasefiles "$@"
  734. }
  735. compressfile() {
  736. cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
  737. if [ "$compressor" = '.' ]; then
  738. if [ -n "$2" ]; then
  739. touch -d "$2" "$1"
  740. fi
  741. continue
  742. fi
  743. cat "$1" | $command > "${1}.${extension}"
  744. if [ -n "$2" ]; then
  745. touch -d "$2" "${1}.${extension}"
  746. fi
  747. done
  748. }
  749. # can be overridden by testcases for their pleasure
  750. getcodenamefromsuite() {
  751. case "$1" in
  752. unstable) echo 'sid';;
  753. *) echo -n "$1";;
  754. esac
  755. }
  756. getreleaseversionfromsuite() { true; }
  757. getlabelfromsuite() { true; }
  758. generatereleasefiles() {
  759. # $1 is the Date header and $2 is the ValidUntil header to be set
  760. # both should be given in notation date/touch can understand
  761. msgninfo "\tGenerate Release files… "
  762. if [ -e aptarchive/dists ]; then
  763. for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
  764. local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
  765. local CODENAME="$(getcodenamefromsuite $SUITE)"
  766. local VERSION="$(getreleaseversionfromsuite $SUITE)"
  767. local LABEL="$(getlabelfromsuite $SUITE)"
  768. if [ -n "$VERSION" ]; then
  769. VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
  770. fi
  771. if [ -n "$LABEL" ]; then
  772. LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
  773. fi
  774. aptftparchive -qq release $dir \
  775. -o APT::FTPArchive::Release::Suite="${SUITE}" \
  776. -o APT::FTPArchive::Release::Codename="${CODENAME}" \
  777. ${LABEL} \
  778. ${VERSION} \
  779. | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
  780. if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
  781. sed -i '/^Date: / a\
  782. NotAutomatic: yes' $dir/Release
  783. fi
  784. if [ -n "$1" -a "$1" != "now" ]; then
  785. sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
  786. fi
  787. if [ -n "$2" ]; then
  788. sed -i "/^Date: / a\
  789. Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
  790. fi
  791. done
  792. else
  793. aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
  794. fi
  795. if [ -n "$1" -a "$1" != "now" ]; then
  796. for release in $(find ./aptarchive -name 'Release'); do
  797. touch -d "$1" $release
  798. done
  799. fi
  800. msgdone "info"
  801. }
  802. setupdistsaptarchive() {
  803. local APTARCHIVE=$(readlink -f ./aptarchive)
  804. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  805. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  806. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  807. SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  808. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  809. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
  810. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
  811. msgdone "info"
  812. done
  813. }
  814. setupflataptarchive() {
  815. local APTARCHIVE=$(readlink -f ./aptarchive)
  816. if [ -f ${APTARCHIVE}/Packages ]; then
  817. msgninfo "\tadd deb sources.list line… "
  818. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  819. msgdone "info"
  820. else
  821. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  822. fi
  823. if [ -f ${APTARCHIVE}/Sources ]; then
  824. msgninfo "\tadd deb-src sources.list line… "
  825. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  826. msgdone "info"
  827. else
  828. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  829. fi
  830. }
  831. setupaptarchive() {
  832. local NOUPDATE=0
  833. if [ "$1" = '--no-update' ]; then
  834. NOUPDATE=1
  835. shift
  836. fi
  837. buildaptarchive "$@"
  838. if [ -e aptarchive/dists ]; then
  839. setupdistsaptarchive
  840. else
  841. setupflataptarchive
  842. fi
  843. signreleasefiles 'Joe Sixpack'
  844. if [ "1" != "$NOUPDATE" ]; then
  845. testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
  846. fi
  847. }
  848. signreleasefiles() {
  849. local SIGNER="${1:-Joe Sixpack}"
  850. local REPODIR="${2:-aptarchive}"
  851. local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
  852. local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
  853. msgninfo "\tSign archive with $SIGNER key $KEY… "
  854. local REXKEY='keys/rexexpired'
  855. local SECEXPIREBAK="${REXKEY}.sec.bak"
  856. local PUBEXPIREBAK="${REXKEY}.pub.bak"
  857. if [ "${SIGNER}" = 'Rex Expired' ]; then
  858. # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
  859. # option doesn't exist anymore (and using faketime would add a new obscure dependency)
  860. # therefore we 'temporary' make the key not expired and restore a backup after signing
  861. cp ${REXKEY}.sec $SECEXPIREBAK
  862. cp ${REXKEY}.pub $PUBEXPIREBAK
  863. local SECUNEXPIRED="${REXKEY}.sec.unexpired"
  864. local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
  865. if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
  866. cp $SECUNEXPIRED ${REXKEY}.sec
  867. cp $PUBUNEXPIRED ${REXKEY}.pub
  868. else
  869. if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
  870. cat setexpire.gpg
  871. exit 1
  872. fi
  873. cp ${REXKEY}.sec $SECUNEXPIRED
  874. cp ${REXKEY}.pub $PUBUNEXPIRED
  875. fi
  876. fi
  877. for RELEASE in $(find ${REPODIR}/ -name Release); do
  878. $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
  879. local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
  880. $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
  881. # we might have set a specific date for the Release file, so copy it
  882. touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
  883. done
  884. if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
  885. mv -f $SECEXPIREBAK ${REXKEY}.sec
  886. mv -f $PUBEXPIREBAK ${REXKEY}.pub
  887. fi
  888. msgdone "info"
  889. }
  890. webserverconfig() {
  891. local NOCHECK=false
  892. if [ "$1" = '--no-check' ]; then
  893. NOCHECK=true
  894. shift
  895. fi
  896. local DOWNLOG='rootdir/tmp/download-testfile.log'
  897. local STATUS='downloaded/webserverconfig.status'
  898. rm -f "$STATUS" "$DOWNLOG"
  899. local URI
  900. if [ -n "$2" ]; then
  901. msgtest "Set webserver config option '${1}' to" "$2"
  902. URI="http://localhost:8080/_config/set/${1}/${2}"
  903. else
  904. msgtest 'Clear webserver config option' "${1}"
  905. URI="http://localhost:8080/_config/clear/${1}"
  906. fi
  907. if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
  908. msgpass
  909. else
  910. cat "$DOWNLOG" "$STATUS" || true
  911. msgfail
  912. fi
  913. $NOCHECK || testwebserverlaststatuscode '200'
  914. }
  915. rewritesourceslist() {
  916. local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
  917. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  918. sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
  919. done
  920. }
  921. # wait for up to 10s for a pid file to appear to avoid possible race
  922. # when a helper is started and dosn't write the PID quick enough
  923. waitforpidfile() {
  924. local PIDFILE="$1"
  925. for i in $(seq 10); do
  926. if test -s "$PIDFILE"; then
  927. return 0
  928. fi
  929. sleep 1
  930. done
  931. msgdie "waiting for $PIDFILE failed"
  932. return 1
  933. }
  934. changetowebserver() {
  935. if [ "$1" != '--no-rewrite' ]; then
  936. rewritesourceslist 'http://localhost:8080/'
  937. else
  938. shift
  939. fi
  940. if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
  941. cd aptarchive
  942. local LOG="webserver.log"
  943. if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
  944. cat $LOG
  945. false
  946. fi
  947. waitforpidfile aptwebserver.pid
  948. local PID="$(cat aptwebserver.pid)"
  949. if [ -z "$PID" ]; then
  950. msgdie 'Could not fork aptwebserver successfully'
  951. fi
  952. addtrap "kill $PID;"
  953. cd - > /dev/null
  954. else
  955. msgdie 'You have to build aptwerbserver or install a webserver'
  956. fi
  957. }
  958. changetohttpswebserver() {
  959. if ! which stunnel4 >/dev/null; then
  960. msgdie 'You need to install stunnel4 for https testcases'
  961. fi
  962. if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
  963. changetowebserver --no-rewrite "$@"
  964. fi
  965. echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
  966. cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
  967. output = /dev/null
  968. [https]
  969. accept = 4433
  970. connect = 8080
  971. " > ${TMPWORKINGDIRECTORY}/stunnel.conf
  972. stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
  973. waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
  974. local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
  975. if [ -z "$PID" ]; then
  976. msgdie 'Could not fork stunnel4 successfully'
  977. fi
  978. addtrap 'prefix' "kill ${PID};"
  979. rewritesourceslist 'https://localhost:4433/'
  980. }
  981. changetocdrom() {
  982. mkdir -p rootdir/media/cdrom/.disk
  983. local CD="$(readlink -f rootdir/media/cdrom)"
  984. echo "acquire::cdrom::mount \"${CD}\";
  985. acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
  986. acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
  987. acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
  988. echo -n "$1" > ${CD}/.disk/info
  989. if [ ! -d aptarchive/dists ]; then
  990. msgdie 'Flat file archive cdroms can not be created currently'
  991. return 1
  992. fi
  993. mv aptarchive/dists "$CD"
  994. ln -s "$(readlink -f ./incoming)" $CD/pool
  995. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  996. # start with an unmounted disk
  997. mv "${CD}" "${CD}-unmounted"
  998. # we don't want the disk to be modifiable
  999. addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
  1000. chmod -R 555 rootdir/media/cdrom-unmounted/dists
  1001. }
  1002. downloadfile() {
  1003. local PROTO="$(echo "$1" | cut -d':' -f 1 )"
  1004. apthelper -o Debug::Acquire::${PROTO}=1 \
  1005. download-file "$1" "$2" 2>&1 || true
  1006. # only if the file exists the download was successful
  1007. if [ -r "$2" ]; then
  1008. return 0
  1009. else
  1010. return 1
  1011. fi
  1012. }
  1013. checkdiff() {
  1014. local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  1015. if [ -n "$DIFFTEXT" ]; then
  1016. echo >&2
  1017. echo >&2 "$DIFFTEXT"
  1018. return 1
  1019. else
  1020. return 0
  1021. fi
  1022. }
  1023. testfileequal() {
  1024. local FILE="$1"
  1025. shift
  1026. msgtest "Test for correctness of file" "$FILE"
  1027. if [ -z "$*" ]; then
  1028. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  1029. else
  1030. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  1031. fi
  1032. }
  1033. testempty() {
  1034. msgtest "Test for no output of" "$*"
  1035. local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
  1036. if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
  1037. msgpass
  1038. else
  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); do
  1323. testfilestats "$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
  1324. done
  1325. }
  1326. aptautotest_apt_update() { aptautotest_aptget_update "$@"; }