framework 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. #!/bin/sh -- # no runable script, just for vi
  2. EXIT_CODE=0
  3. # we all like colorful messages
  4. if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null && \
  5. expr match "$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev/null; then
  6. CERROR="" # red
  7. CWARNING="" # yellow
  8. CMSG="" # green
  9. CINFO="" # light blue
  10. CDEBUG="" # blue
  11. CNORMAL="" # default system console color
  12. CDONE="" # green
  13. CPASS="" # green
  14. CFAIL="" # red
  15. CCMD="" # pink
  16. fi
  17. msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
  18. msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
  19. msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
  20. msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
  21. msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
  22. msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
  23. msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
  24. msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
  25. msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
  26. msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
  27. msgtest() {
  28. while [ -n "$1" ]; do
  29. echo -n "${CINFO}$1${CCMD} " >&2;
  30. echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2;
  31. shift
  32. if [ -n "$1" ]; then shift; else break; fi
  33. done
  34. echo -n "…${CNORMAL} " >&2;
  35. }
  36. msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
  37. msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
  38. msgfail() {
  39. if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
  40. else echo "${CFAIL}FAIL${CNORMAL}" >&2; fi
  41. EXIT_CODE=$((EXIT_CODE+1));
  42. }
  43. # enable / disable Debugging
  44. MSGLEVEL=${MSGLEVEL:-3}
  45. if [ $MSGLEVEL -le 0 ]; then
  46. msgdie() { true; }
  47. fi
  48. if [ $MSGLEVEL -le 1 ]; then
  49. msgwarn() { true; }
  50. msgnwarn() { true; }
  51. fi
  52. if [ $MSGLEVEL -le 2 ]; then
  53. msgmsg() { true; }
  54. msgnmsg() { true; }
  55. msgtest() { true; }
  56. msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
  57. msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
  58. if [ -n "$CFAIL" ]; then
  59. msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
  60. else
  61. msgfail() { echo -n " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
  62. fi
  63. fi
  64. if [ $MSGLEVEL -le 3 ]; then
  65. msginfo() { true; }
  66. msgninfo() { true; }
  67. fi
  68. if [ $MSGLEVEL -le 4 ]; then
  69. msgdebug() { true; }
  70. msgndebug() { true; }
  71. fi
  72. msgdone() {
  73. if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
  74. [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
  75. [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
  76. [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
  77. [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
  78. true;
  79. else
  80. echo "${CDONE}DONE${CNORMAL}" >&2;
  81. fi
  82. }
  83. runapt() {
  84. msgdebug "Executing: ${CCMD}$*${CDEBUG} "
  85. if [ -f ./aptconfig.conf ]; then
  86. MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  87. elif [ -f ../aptconfig.conf ]; then
  88. MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  89. else
  90. MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  91. fi
  92. }
  93. aptconfig() { runapt apt-config $*; }
  94. aptcache() { runapt apt-cache $*; }
  95. aptcdrom() { runapt apt-cdrom $*; }
  96. aptget() { runapt apt-get $*; }
  97. apt() { runapt apt $*; }
  98. aptftparchive() { runapt apt-ftparchive $*; }
  99. aptkey() { runapt apt-key $*; }
  100. aptmark() { runapt apt-mark $*; }
  101. aptwebserver() {
  102. LD_LIBRARY_PATH=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver $*;
  103. }
  104. dpkg() {
  105. $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
  106. }
  107. aptitude() {
  108. if [ -f ./aptconfig.conf ]; then
  109. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  110. elif [ -f ../aptconfig.conf ]; then
  111. APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  112. else
  113. LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  114. fi
  115. }
  116. gdb() {
  117. echo "gdb: run »$*«"
  118. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1 --args $*
  119. }
  120. http() {
  121. LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http
  122. }
  123. exitwithstatus() {
  124. # error if we about to overflow, but ...
  125. # "255 failures ought to be enough for everybody"
  126. if [ $EXIT_CODE -gt 255 ]; then
  127. msgdie "Total failure count $EXIT_CODE too big"
  128. fi
  129. exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
  130. }
  131. shellsetedetector() {
  132. local exit_status=$?
  133. if [ "$exit_status" != '0' ]; then
  134. echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
  135. if [ "$EXIT_CODE" = '0' ]; then
  136. EXIT_CODE="$exit_status"
  137. fi
  138. fi
  139. }
  140. addtrap() {
  141. if [ "$1" = 'prefix' ]; then
  142. CURRENTTRAP="$2 $CURRENTTRAP"
  143. else
  144. CURRENTTRAP="$CURRENTTRAP $1"
  145. fi
  146. trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  147. }
  148. setupenvironment() {
  149. TMPWORKINGDIRECTORY=$(mktemp -d)
  150. TESTDIRECTORY=$(readlink -f $(dirname $0))
  151. msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
  152. # allow overriding the default BUILDDIR location
  153. BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
  154. METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
  155. APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
  156. test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
  157. # -----
  158. addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
  159. cd $TMPWORKINGDIRECTORY
  160. mkdir rootdir aptarchive keys
  161. cd rootdir
  162. mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
  163. mkdir -p var/cache var/lib var/log
  164. mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
  165. touch var/lib/dpkg/available
  166. mkdir -p usr/lib/apt
  167. ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
  168. cd ..
  169. local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
  170. if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
  171. cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
  172. fi
  173. local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
  174. if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
  175. cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
  176. fi
  177. cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
  178. ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  179. echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
  180. echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
  181. echo "Debug::NoLocking \"true\";" >> aptconfig.conf
  182. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  183. echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
  184. echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
  185. echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
  186. echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
  187. echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
  188. echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
  189. if ! $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
  190. echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
  191. fi
  192. echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
  193. echo 'quiet::NoUpdate "true";' >> aptconfig.conf
  194. echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https
  195. echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
  196. export LC_ALL=C
  197. export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
  198. configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
  199. msgdone "info"
  200. }
  201. getarchitecture() {
  202. if [ "$1" = "native" -o -z "$1" ]; then
  203. eval `aptconfig shell ARCH APT::Architecture`
  204. if [ -n "$ARCH" ]; then
  205. echo $ARCH
  206. else
  207. dpkg --print-architecture
  208. fi
  209. else
  210. echo $1
  211. fi
  212. }
  213. getarchitectures() {
  214. echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  215. }
  216. configarchitecture() {
  217. {
  218. echo "APT::Architecture \"$(getarchitecture $1)\";"
  219. while [ -n "$1" ]; do
  220. echo "APT::Architectures:: \"$(getarchitecture $1)\";"
  221. shift
  222. done
  223. } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
  224. configdpkg
  225. }
  226. configdpkg() {
  227. if [ ! -e rootdir/var/lib/dpkg/status ]; then
  228. local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
  229. if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
  230. cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
  231. else
  232. echo -n > rootdir/var/lib/dpkg/status
  233. fi
  234. fi
  235. rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
  236. if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
  237. local ARCHS="$(getarchitectures)"
  238. if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
  239. DPKGARCH="$(dpkg --print-architecture)"
  240. for ARCH in ${ARCHS}; do
  241. if [ "${ARCH}" != "${DPKGARCH}" ]; then
  242. if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
  243. # old-style used e.g. in Ubuntu-P – and as it seems travis
  244. echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  245. echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
  246. fi
  247. fi
  248. done
  249. if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
  250. # dpkg doesn't really check the version as long as it is fully installed,
  251. # but just to be sure we choose one above the required version
  252. insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
  253. fi
  254. fi
  255. fi
  256. }
  257. configcompression() {
  258. while [ -n "$1" ]; do
  259. case "$1" in
  260. '.') echo ".\t.\tcat";;
  261. 'gz') echo "gzip\tgz\tgzip";;
  262. 'bz2') echo "bzip2\tbz2\tbzip2";;
  263. 'lzma') echo "lzma\tlzma\txz --format=lzma";;
  264. 'xz') echo "xz\txz\txz";;
  265. *) echo "$1\t$1\t$1";;
  266. esac
  267. shift
  268. done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
  269. }
  270. setupsimplenativepackage() {
  271. local NAME="$1"
  272. local ARCH="$2"
  273. local VERSION="$3"
  274. local RELEASE="${4:-unstable}"
  275. local DEPENDENCIES="$5"
  276. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  277. If you find such a package installed on your system,
  278. something went horribly wrong! They are autogenerated
  279. und used only by testcases and surf no other propose…"}"
  280. local SECTION="${7:-others}"
  281. local DISTSECTION
  282. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  283. DISTSECTION="main"
  284. else
  285. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  286. fi
  287. local BUILDDIR=incoming/${NAME}-${VERSION}
  288. mkdir -p ${BUILDDIR}/debian/source
  289. cd ${BUILDDIR}
  290. echo "* most suckless software product ever" > FEATURES
  291. test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
  292. test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
  293. * Initial release
  294. -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
  295. test -e debian/control || echo "Source: $NAME
  296. Section: $SECTION
  297. Priority: optional
  298. Maintainer: Joe Sixpack <joe@example.org>
  299. Build-Depends: debhelper (>= 7)
  300. Standards-Version: 3.9.1
  301. Package: $NAME" > debian/control
  302. if [ "$ARCH" = 'all' ]; then
  303. echo "Architecture: all" >> debian/control
  304. else
  305. echo "Architecture: any" >> debian/control
  306. fi
  307. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
  308. echo "Description: $DESCRIPTION" >> debian/control
  309. test -e debian/compat || echo "7" > debian/compat
  310. test -e debian/source/format || echo "3.0 (native)" > debian/source/format
  311. test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
  312. cd - > /dev/null
  313. }
  314. buildsimplenativepackage() {
  315. local NAME="$1"
  316. local ARCH="$2"
  317. local VERSION="$3"
  318. local RELEASE="${4:-unstable}"
  319. local DEPENDENCIES="$5"
  320. local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  321. If you find such a package installed on your system,
  322. something went horribly wrong! They are autogenerated
  323. und used only by testcases and surf no other propose…"}"
  324. local SECTION="${7:-others}"
  325. local PRIORITY="${8:-optional}"
  326. local FILE_TREE="$9"
  327. local DISTSECTION
  328. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  329. DISTSECTION="main"
  330. else
  331. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  332. fi
  333. local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
  334. msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
  335. mkdir -p $BUILDDIR/debian/source
  336. echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
  337. echo "#!/bin/sh
  338. echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
  339. echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
  340. echo "$NAME ($VERSION) $RELEASE; urgency=low
  341. * Initial release
  342. -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
  343. echo "Source: $NAME
  344. Section: $SECTION
  345. Priority: $PRIORITY
  346. Maintainer: Joe Sixpack <joe@example.org>
  347. Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
  348. local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
  349. test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
  350. echo "
  351. Package: $NAME" >> ${BUILDDIR}/debian/control
  352. if [ "$ARCH" = 'all' ]; then
  353. echo "Architecture: all" >> ${BUILDDIR}/debian/control
  354. else
  355. echo "Architecture: any" >> ${BUILDDIR}/debian/control
  356. fi
  357. local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
  358. test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
  359. echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
  360. echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
  361. (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
  362. | while read SRC; do
  363. echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
  364. # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
  365. # gpg --yes --no-default-keyring --secret-keyring ./keys/joesixpack.sec \
  366. # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
  367. # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  368. # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  369. # fi
  370. done
  371. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  372. rm -rf ${BUILDDIR}/debian/tmp
  373. mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
  374. cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
  375. cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
  376. if [ -n "$FILE_TREE" ]; then
  377. cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
  378. fi
  379. (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
  380. (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
  381. dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null
  382. echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
  383. done
  384. mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
  385. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
  386. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
  387. rm -rf "${BUILDDIR}"
  388. msgdone "info"
  389. }
  390. buildpackage() {
  391. local BUILDDIR=$1
  392. local RELEASE=$2
  393. local SECTION=$3
  394. local ARCH=$(getarchitecture $4)
  395. msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
  396. cd $BUILDDIR
  397. if [ "$ARCH" = "all" ]; then
  398. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  399. fi
  400. local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
  401. local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
  402. local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
  403. cd - > /dev/null
  404. for PKG in $PKGS; do
  405. echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
  406. done
  407. for SRC in $SRCS; do
  408. echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
  409. done
  410. msgdone "info"
  411. }
  412. buildaptarchive() {
  413. if [ -d incoming ]; then
  414. buildaptarchivefromincoming $*
  415. else
  416. buildaptarchivefromfiles $*
  417. fi
  418. }
  419. createaptftparchiveconfig() {
  420. local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
  421. COMPRESSORS="${COMPRESSORS%* }"
  422. 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' ' ')"
  423. if [ -z "$ARCHS" ]; then
  424. # the pool is empty, so we will operate on faked packages - let us use the configured archs
  425. ARCHS="$(getarchitectures)"
  426. fi
  427. echo -n 'Dir {
  428. ArchiveDir "' >> ftparchive.conf
  429. echo -n $(readlink -f .) >> ftparchive.conf
  430. echo -n '";
  431. CacheDir "' >> ftparchive.conf
  432. echo -n $(readlink -f ..) >> ftparchive.conf
  433. echo -n '";
  434. FileListDir "' >> ftparchive.conf
  435. echo -n $(readlink -f pool/) >> ftparchive.conf
  436. echo -n '";
  437. };
  438. Default {
  439. Packages::Compress "'"$COMPRESSORS"'";
  440. Sources::Compress "'"$COMPRESSORS"'";
  441. Contents::Compress "'"$COMPRESSORS"'";
  442. Translation::Compress "'"$COMPRESSORS"'";
  443. LongDescription "false";
  444. };
  445. TreeDefault {
  446. Directory "pool/";
  447. SrcDirectory "pool/";
  448. };
  449. APT {
  450. FTPArchive {
  451. Release {
  452. Origin "joesixpack";
  453. Label "apttestcases";
  454. Suite "unstable";
  455. Description "repository with dummy packages";
  456. Architectures "' >> ftparchive.conf
  457. echo -n "$ARCHS" >> ftparchive.conf
  458. echo 'source";
  459. };
  460. };
  461. };' >> ftparchive.conf
  462. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  463. echo -n 'tree "dists/' >> ftparchive.conf
  464. echo -n "$DIST" >> ftparchive.conf
  465. echo -n '" {
  466. Architectures "' >> ftparchive.conf
  467. echo -n "$ARCHS" >> ftparchive.conf
  468. echo -n 'source";
  469. FileList "' >> ftparchive.conf
  470. echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
  471. echo -n '";
  472. SourceFileList "' >> ftparchive.conf
  473. echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
  474. echo -n '";
  475. Sections "' >> ftparchive.conf
  476. 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
  477. echo '";
  478. };' >> ftparchive.conf
  479. done
  480. }
  481. buildaptftparchivedirectorystructure() {
  482. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  483. for DIST in $DISTS; do
  484. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  485. for SECTION in $SECTIONS; do
  486. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  487. for ARCH in $ARCHS; do
  488. mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
  489. done
  490. mkdir -p dists/${DIST}/${SECTION}/source
  491. mkdir -p dists/${DIST}/${SECTION}/i18n
  492. done
  493. done
  494. }
  495. insertpackage() {
  496. local RELEASE="$1"
  497. local NAME="$2"
  498. local ARCH="$3"
  499. local VERSION="$4"
  500. local DEPENDENCIES="$5"
  501. local PRIORITY="${6:-optional}"
  502. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  503. If you find such a package installed on your system,
  504. something went horribly wrong! They are autogenerated
  505. und used only by testcases and surf no other propose…"}"
  506. local ARCHS=""
  507. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  508. if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
  509. ARCHS="$(getarchitectures)"
  510. else
  511. ARCHS="$arch"
  512. fi
  513. for BUILDARCH in $ARCHS; do
  514. local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
  515. mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
  516. touch aptarchive/dists/${RELEASE}/main/source/Sources
  517. local FILE="${PPATH}/Packages"
  518. echo "Package: $NAME
  519. Priority: $PRIORITY
  520. Section: other
  521. Installed-Size: 42
  522. Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
  523. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  524. echo "Version: $VERSION
  525. Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
  526. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  527. echo "Description: $DESCRIPTION" >> $FILE
  528. echo >> $FILE
  529. done
  530. done
  531. }
  532. insertsource() {
  533. local RELEASE="$1"
  534. local NAME="$2"
  535. local ARCH="$3"
  536. local VERSION="$4"
  537. local DEPENDENCIES="$5"
  538. local ARCHS=""
  539. local SPATH="aptarchive/dists/${RELEASE}/main/source"
  540. mkdir -p $SPATH
  541. local FILE="${SPATH}/Sources"
  542. echo "Package: $NAME
  543. Binary: $NAME
  544. Version: $VERSION
  545. Maintainer: Joe Sixpack <joe@example.org>
  546. Architecture: $ARCH" >> $FILE
  547. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  548. echo "Files:
  549. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
  550. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
  551. " >> $FILE
  552. }
  553. insertinstalledpackage() {
  554. local NAME="$1"
  555. local ARCH="$2"
  556. local VERSION="$3"
  557. local DEPENDENCIES="$4"
  558. local PRIORITY="${5:-optional}"
  559. local STATUS="${6:-install ok installed}"
  560. local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
  561. If you find such a package installed on your system,
  562. something went horribly wrong! They are autogenerated
  563. und used only by testcases and surf no other propose…"}"
  564. local FILE='rootdir/var/lib/dpkg/status'
  565. local INFO='rootdir/var/lib/dpkg/info'
  566. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  567. echo "Package: $NAME
  568. Status: $STATUS
  569. Priority: $PRIORITY
  570. Section: other
  571. Installed-Size: 42
  572. Maintainer: Joe Sixpack <joe@example.org>
  573. Version: $VERSION" >> $FILE
  574. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  575. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  576. echo "Description: $DESCRIPTION" >> $FILE
  577. echo >> $FILE
  578. if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
  579. echo -n > ${INFO}/${NAME}:${arch}.list
  580. else
  581. echo -n > ${INFO}/${NAME}.list
  582. fi
  583. done
  584. }
  585. buildaptarchivefromincoming() {
  586. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
  587. cd aptarchive
  588. [ -e pool ] || ln -s ../incoming pool
  589. [ -e ftparchive.conf ] || createaptftparchiveconfig
  590. [ -e dists ] || buildaptftparchivedirectorystructure
  591. msgninfo "\tGenerate Packages, Sources and Contents files… "
  592. aptftparchive -qq generate ftparchive.conf
  593. cd - > /dev/null
  594. msgdone "info"
  595. generatereleasefiles
  596. }
  597. buildaptarchivefromfiles() {
  598. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
  599. find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
  600. msgninfo "\t${line} file… "
  601. compressfile "$line" "$1"
  602. msgdone "info"
  603. done
  604. generatereleasefiles "$@"
  605. }
  606. compressfile() {
  607. cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
  608. if [ "$compressor" = '.' ]; then
  609. if [ -n "$2" ]; then
  610. touch -d "$2" "$1"
  611. fi
  612. continue
  613. fi
  614. cat "$1" | $command > "${1}.${extension}"
  615. if [ -n "$2" ]; then
  616. touch -d "$2" "${1}.${extension}"
  617. fi
  618. done
  619. }
  620. # can be overridden by testcases for their pleasure
  621. getcodenamefromsuite() { echo -n "$1"; }
  622. getreleaseversionfromsuite() { true; }
  623. getlabelfromsuite() { true; }
  624. generatereleasefiles() {
  625. # $1 is the Date header and $2 is the ValidUntil header to be set
  626. # both should be given in notation date/touch can understand
  627. msgninfo "\tGenerate Release files… "
  628. if [ -e aptarchive/dists ]; then
  629. for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
  630. local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
  631. local CODENAME="$(getcodenamefromsuite $SUITE)"
  632. local VERSION="$(getreleaseversionfromsuite $SUITE)"
  633. local LABEL="$(getlabelfromsuite $SUITE)"
  634. if [ -n "$VERSION" ]; then
  635. VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
  636. fi
  637. if [ -n "$LABEL" ]; then
  638. LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
  639. fi
  640. aptftparchive -qq release $dir \
  641. -o APT::FTPArchive::Release::Suite="${SUITE}" \
  642. -o APT::FTPArchive::Release::Codename="${CODENAME}" \
  643. ${LABEL} \
  644. ${VERSION} \
  645. | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
  646. if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
  647. sed -i '/^Date: / a\
  648. NotAutomatic: yes' $dir/Release
  649. fi
  650. if [ -n "$1" -a "$1" != "now" ]; then
  651. sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
  652. fi
  653. if [ -n "$2" ]; then
  654. sed -i "/^Date: / a\
  655. Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
  656. fi
  657. done
  658. else
  659. aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
  660. fi
  661. if [ -n "$1" -a "$1" != "now" ]; then
  662. for release in $(find ./aptarchive -name 'Release'); do
  663. touch -d "$1" $release
  664. done
  665. fi
  666. msgdone "info"
  667. }
  668. setupdistsaptarchive() {
  669. local APTARCHIVE=$(readlink -f ./aptarchive)
  670. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  671. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  672. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  673. SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  674. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  675. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
  676. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
  677. msgdone "info"
  678. done
  679. }
  680. setupflataptarchive() {
  681. local APTARCHIVE=$(readlink -f ./aptarchive)
  682. if [ -f ${APTARCHIVE}/Packages ]; then
  683. msgninfo "\tadd deb sources.list line… "
  684. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  685. msgdone "info"
  686. else
  687. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  688. fi
  689. if [ -f ${APTARCHIVE}/Sources ]; then
  690. msgninfo "\tadd deb-src sources.list line… "
  691. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  692. msgdone "info"
  693. else
  694. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  695. fi
  696. }
  697. setupaptarchive() {
  698. buildaptarchive
  699. if [ -e aptarchive/dists ]; then
  700. setupdistsaptarchive
  701. else
  702. setupflataptarchive
  703. fi
  704. signreleasefiles
  705. if [ "$1" != '--no-update' ]; then
  706. msgninfo "\tSync APT's cache with the archive… "
  707. aptget update -qq
  708. msgdone "info"
  709. fi
  710. }
  711. signreleasefiles() {
  712. local SIGNER="${1:-Joe Sixpack}"
  713. local GPG="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
  714. msgninfo "\tSign archive with $SIGNER key… "
  715. local REXKEY='keys/rexexpired'
  716. local SECEXPIREBAK="${REXKEY}.sec.bak"
  717. local PUBEXPIREBAK="${REXKEY}.pub.bak"
  718. if [ "${SIGNER}" = 'Rex Expired' ]; then
  719. # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
  720. # option doesn't exist anymore (and using faketime would add a new obscure dependency)
  721. # therefore we 'temporary' make the key not expired and restore a backup after signing
  722. cp ${REXKEY}.sec $SECEXPIREBAK
  723. cp ${REXKEY}.pub $PUBEXPIREBAK
  724. local SECUNEXPIRED="${REXKEY}.sec.unexpired"
  725. local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
  726. if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
  727. cp $SECUNEXPIRED ${REXKEY}.sec
  728. cp $PUBUNEXPIRED ${REXKEY}.pub
  729. else
  730. printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub --secret-keyring ${REXKEY}.sec --command-fd 0 --edit-key "${SIGNER}" >/dev/null 2>&1 || true
  731. cp ${REXKEY}.sec $SECUNEXPIRED
  732. cp ${REXKEY}.pub $PUBUNEXPIRED
  733. fi
  734. fi
  735. for KEY in $(find keys/ -name '*.sec'); do
  736. GPG="$GPG --secret-keyring $KEY"
  737. done
  738. for KEY in $(find keys/ -name '*.pub'); do
  739. GPG="$GPG --keyring $KEY"
  740. done
  741. for RELEASE in $(find aptarchive/ -name Release); do
  742. $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
  743. local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
  744. $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
  745. # we might have set a specific date for the Release file, so copy it
  746. touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
  747. done
  748. if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
  749. mv -f $SECEXPIREBAK ${REXKEY}.sec
  750. mv -f $PUBEXPIREBAK ${REXKEY}.pub
  751. fi
  752. msgdone "info"
  753. }
  754. webserverconfig() {
  755. msgtest "Set webserver config option '${1}' to" "$2"
  756. downloadfile "http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev/null
  757. local DOWNLOG='download-testfile.log'
  758. rm -f "$DOWNLOG"
  759. local STATUS="$(mktemp)"
  760. addtrap "rm $STATUS;"
  761. downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
  762. if [ "$(cat "$STATUS")" = '200' ]; then
  763. msgpass
  764. else
  765. cat >&2 "$DOWNLOG"
  766. msgfail "Statuscode was $(cat "$STATUS")"
  767. fi
  768. }
  769. rewritesourceslist() {
  770. local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
  771. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  772. sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
  773. done
  774. }
  775. changetowebserver() {
  776. if [ "$1" != '--no-rewrite' ]; then
  777. rewritesourceslist 'http://localhost:8080/'
  778. else
  779. shift
  780. fi
  781. local LOG='/dev/null'
  782. if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
  783. cd aptarchive
  784. aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
  785. local PID="$(cat aptwebserver.pid)"
  786. if [ -z "$PID" ]; then
  787. msgdie 'Could not fork aptwebserver successfully'
  788. fi
  789. addtrap "kill $PID;"
  790. cd - > /dev/null
  791. else
  792. msgdie 'You have to build aptwerbserver or install a webserver'
  793. fi
  794. }
  795. changetohttpswebserver() {
  796. if ! which stunnel4 >/dev/null; then
  797. msgdie 'You need to install stunnel4 for https testcases'
  798. fi
  799. if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
  800. changetowebserver --no-rewrite
  801. fi
  802. echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
  803. cert = ${TESTDIRECTORY}/apt.pem
  804. output = /dev/null
  805. [https]
  806. accept = 4433
  807. connect = 8080
  808. " > ${TMPWORKINGDIRECTORY}/stunnel.conf
  809. stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
  810. local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
  811. addtrap 'prefix' "kill ${PID};"
  812. rewritesourceslist 'https://localhost:4433/'
  813. }
  814. changetocdrom() {
  815. mkdir -p rootdir/media/cdrom/.disk
  816. local CD="$(readlink -f rootdir/media/cdrom)"
  817. echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
  818. echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
  819. echo -n "$1" > ${CD}/.disk/info
  820. if [ ! -d aptarchive/dists ]; then
  821. msgdie 'Flat file archive cdroms can not be created currently'
  822. return 1
  823. fi
  824. mv aptarchive/dists $CD
  825. ln -s "$(readlink -f ./incoming)" $CD/pool
  826. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  827. }
  828. downloadfile() {
  829. PROTO="$(echo "$1" | cut -d':' -f 1)"
  830. local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
  831. rm -f "$DOWNLOG"
  832. touch "$DOWNLOG"
  833. {
  834. echo "601 Configuration
  835. Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
  836. Config-Item: Debug::Acquire::${PROTO}=1
  837. 600 Acquire URI
  838. URI: $1
  839. Filename: ${2}
  840. "
  841. # simple worker keeping stdin open until we are done (201) or error (400)
  842. # and requesting new URIs on try-agains/redirects inbetween
  843. { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
  844. if [ "$f1" = 'TAILPID:' ]; then
  845. TAILPID="$f2"
  846. elif [ "$f1" = 'New-URI:' ]; then
  847. echo "600 Acquire URI
  848. URI: $f2
  849. Filename: ${2}
  850. "
  851. elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
  852. # tail would only die on next read – which never happens
  853. test -z "$TAILPID" || kill -s HUP "$TAILPID"
  854. break
  855. fi
  856. done
  857. } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/${PROTO} 2>&1 | tee "$DOWNLOG"
  858. rm "$DOWNLOG"
  859. # only if the file exists the download was successful
  860. if [ -e "$2" ]; then
  861. return 0
  862. else
  863. return 1
  864. fi
  865. }
  866. checkdiff() {
  867. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  868. if [ -n "$DIFFTEXT" ]; then
  869. echo
  870. echo "$DIFFTEXT"
  871. return 1
  872. else
  873. return 0
  874. fi
  875. }
  876. testfileequal() {
  877. local FILE="$1"
  878. shift
  879. msgtest "Test for correctness of file" "$FILE"
  880. if [ -z "$*" ]; then
  881. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  882. else
  883. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  884. fi
  885. }
  886. testempty() {
  887. msgtest "Test for no output of" "$*"
  888. test -z "$($* 2>&1)" && msgpass || msgfail
  889. }
  890. testequal() {
  891. local COMPAREFILE=$(mktemp)
  892. addtrap "rm $COMPAREFILE;"
  893. echo "$1" > $COMPAREFILE
  894. shift
  895. msgtest "Test for equality of" "$*"
  896. $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  897. }
  898. testequalor2() {
  899. local COMPAREFILE1=$(mktemp)
  900. local COMPAREFILE2=$(mktemp)
  901. local COMPAREAGAINST=$(mktemp)
  902. addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
  903. echo "$1" > $COMPAREFILE1
  904. echo "$2" > $COMPAREFILE2
  905. shift 2
  906. msgtest "Test for equality OR of" "$*"
  907. $* >$COMPAREAGAINST 2>&1 || true
  908. (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
  909. checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
  910. ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
  911. "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
  912. msgfail )
  913. }
  914. testshowvirtual() {
  915. local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
  916. local PACKAGE="$1"
  917. shift
  918. while [ -n "$1" ]; do
  919. VIRTUAL="${VIRTUAL}
  920. N: Can't select versions from package '$1' as it is purely virtual"
  921. PACKAGE="${PACKAGE} $1"
  922. shift
  923. done
  924. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  925. VIRTUAL="${VIRTUAL}
  926. N: No packages found"
  927. local COMPAREFILE=$(mktemp)
  928. addtrap "rm $COMPAREFILE;"
  929. local ARCH="$(getarchitecture 'native')"
  930. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  931. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  932. }
  933. testnopackage() {
  934. msgtest "Test for non-existent packages" "apt-cache show $*"
  935. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  936. if [ -n "$SHOWPKG" ]; then
  937. echo
  938. echo "$SHOWPKG"
  939. msgfail
  940. return 1
  941. fi
  942. msgpass
  943. }
  944. testdpkginstalled() {
  945. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  946. local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
  947. if [ "$PKGS" != $# ]; then
  948. echo $PKGS
  949. dpkg -l $* | grep '^[a-z]'
  950. msgfail
  951. return 1
  952. fi
  953. msgpass
  954. }
  955. testdpkgnotinstalled() {
  956. msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
  957. local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
  958. if [ "$PKGS" != 0 ]; then
  959. echo
  960. dpkg -l $* | grep '^[a-z]'
  961. msgfail
  962. return 1
  963. fi
  964. msgpass
  965. }
  966. testmarkedauto() {
  967. local COMPAREFILE=$(mktemp)
  968. addtrap "rm $COMPAREFILE;"
  969. if [ -n "$1" ]; then
  970. msgtest 'Test for correctly marked as auto-installed' "$*"
  971. while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
  972. else
  973. msgtest 'Test for correctly marked as auto-installed' 'no package'
  974. echo -n > $COMPAREFILE
  975. fi
  976. aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  977. }
  978. testsuccess() {
  979. if [ "$1" = '--nomsg' ]; then
  980. shift
  981. else
  982. msgtest 'Test for successful execution of' "$*"
  983. fi
  984. local OUTPUT=$(mktemp)
  985. addtrap "rm $OUTPUT;"
  986. if $@ >${OUTPUT} 2>&1; then
  987. msgpass
  988. else
  989. echo
  990. cat $OUTPUT
  991. msgfail
  992. fi
  993. }
  994. testfailure() {
  995. if [ "$1" = '--nomsg' ]; then
  996. shift
  997. else
  998. msgtest 'Test for failure in execution of' "$*"
  999. fi
  1000. local OUTPUT=$(mktemp)
  1001. addtrap "rm $OUTPUT;"
  1002. if $@ >${OUTPUT} 2>&1; then
  1003. echo
  1004. cat $OUTPUT
  1005. msgfail
  1006. else
  1007. msgpass
  1008. fi
  1009. }
  1010. pause() {
  1011. echo "STOPPED execution. Press enter to continue"
  1012. local IGNORE
  1013. read IGNORE
  1014. }