framework 35 KB

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