framework 37 KB

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