framework 35 KB

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