framework 34 KB

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