framework 47 KB

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