framework 36 KB

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