framework 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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. if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
  785. cd aptarchive
  786. local LOG="$(mktemp)"
  787. addtrap "rm $LOG;"
  788. if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
  789. cat $LOG
  790. false
  791. fi
  792. local PID="$(cat aptwebserver.pid)"
  793. if [ -z "$PID" ]; then
  794. msgdie 'Could not fork aptwebserver successfully'
  795. fi
  796. addtrap "kill $PID;"
  797. cd - > /dev/null
  798. else
  799. msgdie 'You have to build aptwerbserver or install a webserver'
  800. fi
  801. }
  802. changetohttpswebserver() {
  803. if ! which stunnel4 >/dev/null; then
  804. msgdie 'You need to install stunnel4 for https testcases'
  805. fi
  806. if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
  807. changetowebserver --no-rewrite
  808. fi
  809. echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
  810. cert = ${TESTDIRECTORY}/apt.pem
  811. output = /dev/null
  812. [https]
  813. accept = 4433
  814. connect = 8080
  815. " > ${TMPWORKINGDIRECTORY}/stunnel.conf
  816. stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
  817. local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
  818. addtrap 'prefix' "kill ${PID};"
  819. rewritesourceslist 'https://localhost:4433/'
  820. }
  821. changetocdrom() {
  822. mkdir -p rootdir/media/cdrom/.disk
  823. local CD="$(readlink -f rootdir/media/cdrom)"
  824. echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
  825. echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
  826. echo -n "$1" > ${CD}/.disk/info
  827. if [ ! -d aptarchive/dists ]; then
  828. msgdie 'Flat file archive cdroms can not be created currently'
  829. return 1
  830. fi
  831. mv aptarchive/dists $CD
  832. ln -s "$(readlink -f ./incoming)" $CD/pool
  833. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  834. }
  835. downloadfile() {
  836. PROTO="$(echo "$1" | cut -d':' -f 1)"
  837. local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
  838. rm -f "$DOWNLOG"
  839. touch "$DOWNLOG"
  840. {
  841. echo "601 Configuration
  842. Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
  843. Config-Item: Debug::Acquire::${PROTO}=1
  844. 600 Acquire URI
  845. URI: $1
  846. Filename: ${2}
  847. "
  848. # simple worker keeping stdin open until we are done (201) or error (400)
  849. # and requesting new URIs on try-agains/redirects inbetween
  850. { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
  851. if [ "$f1" = 'TAILPID:' ]; then
  852. TAILPID="$f2"
  853. elif [ "$f1" = 'New-URI:' ]; then
  854. echo "600 Acquire URI
  855. URI: $f2
  856. Filename: ${2}
  857. "
  858. elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
  859. # tail would only die on next read – which never happens
  860. test -z "$TAILPID" || kill -s HUP "$TAILPID"
  861. break
  862. fi
  863. done
  864. } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/${PROTO} 2>&1 | tee "$DOWNLOG"
  865. rm "$DOWNLOG"
  866. # only if the file exists the download was successful
  867. if [ -e "$2" ]; then
  868. return 0
  869. else
  870. return 1
  871. fi
  872. }
  873. checkdiff() {
  874. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  875. if [ -n "$DIFFTEXT" ]; then
  876. echo
  877. echo "$DIFFTEXT"
  878. return 1
  879. else
  880. return 0
  881. fi
  882. }
  883. testfileequal() {
  884. local FILE="$1"
  885. shift
  886. msgtest "Test for correctness of file" "$FILE"
  887. if [ -z "$*" ]; then
  888. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  889. else
  890. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  891. fi
  892. }
  893. testempty() {
  894. msgtest "Test for no output of" "$*"
  895. test -z "$($* 2>&1)" && msgpass || msgfail
  896. }
  897. testequal() {
  898. local COMPAREFILE=$(mktemp)
  899. addtrap "rm $COMPAREFILE;"
  900. echo "$1" > $COMPAREFILE
  901. shift
  902. msgtest "Test for equality of" "$*"
  903. $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  904. }
  905. testequalor2() {
  906. local COMPAREFILE1=$(mktemp)
  907. local COMPAREFILE2=$(mktemp)
  908. local COMPAREAGAINST=$(mktemp)
  909. addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
  910. echo "$1" > $COMPAREFILE1
  911. echo "$2" > $COMPAREFILE2
  912. shift 2
  913. msgtest "Test for equality OR of" "$*"
  914. $* >$COMPAREAGAINST 2>&1 || true
  915. (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
  916. checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
  917. ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
  918. "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
  919. msgfail )
  920. }
  921. testshowvirtual() {
  922. local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
  923. local PACKAGE="$1"
  924. shift
  925. while [ -n "$1" ]; do
  926. VIRTUAL="${VIRTUAL}
  927. N: Can't select versions from package '$1' as it is purely virtual"
  928. PACKAGE="${PACKAGE} $1"
  929. shift
  930. done
  931. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  932. VIRTUAL="${VIRTUAL}
  933. N: No packages found"
  934. local COMPAREFILE=$(mktemp)
  935. addtrap "rm $COMPAREFILE;"
  936. local ARCH="$(getarchitecture 'native')"
  937. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  938. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  939. }
  940. testnopackage() {
  941. msgtest "Test for non-existent packages" "apt-cache show $*"
  942. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  943. if [ -n "$SHOWPKG" ]; then
  944. echo
  945. echo "$SHOWPKG"
  946. msgfail
  947. return 1
  948. fi
  949. msgpass
  950. }
  951. testdpkginstalled() {
  952. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  953. local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
  954. if [ "$PKGS" != $# ]; then
  955. echo $PKGS
  956. dpkg -l $* | grep '^[a-z]'
  957. msgfail
  958. return 1
  959. fi
  960. msgpass
  961. }
  962. testdpkgnotinstalled() {
  963. msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
  964. local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
  965. if [ "$PKGS" != 0 ]; then
  966. echo
  967. dpkg -l $* | grep '^[a-z]'
  968. msgfail
  969. return 1
  970. fi
  971. msgpass
  972. }
  973. testmarkedauto() {
  974. local COMPAREFILE=$(mktemp)
  975. addtrap "rm $COMPAREFILE;"
  976. if [ -n "$1" ]; then
  977. msgtest 'Test for correctly marked as auto-installed' "$*"
  978. while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
  979. else
  980. msgtest 'Test for correctly marked as auto-installed' 'no package'
  981. echo -n > $COMPAREFILE
  982. fi
  983. aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  984. }
  985. testsuccess() {
  986. if [ "$1" = '--nomsg' ]; then
  987. shift
  988. else
  989. msgtest 'Test for successful execution of' "$*"
  990. fi
  991. local OUTPUT=$(mktemp)
  992. addtrap "rm $OUTPUT;"
  993. if $@ >${OUTPUT} 2>&1; then
  994. msgpass
  995. else
  996. echo
  997. cat $OUTPUT
  998. msgfail
  999. fi
  1000. }
  1001. testfailure() {
  1002. if [ "$1" = '--nomsg' ]; then
  1003. shift
  1004. else
  1005. msgtest 'Test for failure in execution of' "$*"
  1006. fi
  1007. local OUTPUT=$(mktemp)
  1008. addtrap "rm $OUTPUT;"
  1009. if $@ >${OUTPUT} 2>&1; then
  1010. echo
  1011. cat $OUTPUT
  1012. msgfail
  1013. else
  1014. msgpass
  1015. fi
  1016. }
  1017. pause() {
  1018. echo "STOPPED execution. Press enter to continue"
  1019. local IGNORE
  1020. read IGNORE
  1021. }