framework 36 KB

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