framework 34 KB

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