framework 36 KB

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