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 --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. rewritesourceslist() {
  746. local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
  747. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  748. sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
  749. done
  750. }
  751. changetowebserver() {
  752. if [ "$1" != '--no-rewrite' ]; then
  753. rewritesourceslist 'http://localhost:8080/'
  754. else
  755. shift
  756. fi
  757. local LOG='/dev/null'
  758. if test -x ${BUILDDIRECTORY}/aptwebserver; then
  759. cd aptarchive
  760. LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
  761. local PID="$(cat aptwebserver.pid)"
  762. if [ -z "$PID" ]; then
  763. msgdie 'Could not fork aptwebserver successfully'
  764. fi
  765. addtrap "kill $PID;"
  766. cd - > /dev/null
  767. else
  768. msgdie 'You have to build aptwerbserver or install a webserver'
  769. fi
  770. }
  771. changetohttpswebserver() {
  772. if ! which stunnel4 >/dev/null; then
  773. msgdie 'You need to install stunnel4 for https testcases'
  774. fi
  775. if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
  776. changetowebserver --no-rewrite
  777. fi
  778. echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
  779. cert = ${TESTDIRECTORY}/apt.pem
  780. output = /dev/null
  781. [https]
  782. accept = 4433
  783. connect = 8080
  784. " > ${TMPWORKINGDIRECTORY}/stunnel.conf
  785. stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
  786. local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
  787. addtrap 'prefix' "kill ${PID};"
  788. rewritesourceslist 'https://localhost:4433/'
  789. }
  790. changetocdrom() {
  791. mkdir -p rootdir/media/cdrom/.disk
  792. local CD="$(readlink -f rootdir/media/cdrom)"
  793. echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
  794. echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
  795. echo -n "$1" > ${CD}/.disk/info
  796. if [ ! -d aptarchive/dists ]; then
  797. msgdie 'Flat file archive cdroms can not be created currently'
  798. return 1
  799. fi
  800. mv aptarchive/dists $CD
  801. ln -s "$(readlink -f ./incoming)" $CD/pool
  802. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  803. }
  804. downloadfile() {
  805. PROTO="$(echo "$1" | cut -d':' -f 1)"
  806. local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
  807. rm -f "$DOWNLOG"
  808. touch "$DOWNLOG"
  809. {
  810. echo "601 Configuration
  811. Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
  812. Config-Item: Debug::Acquire::${PROTO}=1
  813. 600 Acquire URI
  814. URI: $1
  815. Filename: ${2}
  816. "
  817. # simple worker keeping stdin open until we are done (201) or error (400)
  818. # and requesting new URIs on try-agains/redirects inbetween
  819. { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
  820. if [ "$f1" = 'TAILPID:' ]; then
  821. TAILPID="$f2"
  822. elif [ "$f1" = 'New-URI:' ]; then
  823. echo "600 Acquire URI
  824. URI: $f2
  825. Filename: ${2}
  826. "
  827. elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
  828. # tail would only die on next read – which never happens
  829. test -z "$TAILPID" || kill -s HUP "$TAILPID"
  830. break
  831. fi
  832. done
  833. } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/${PROTO} 2>&1 | tee "$DOWNLOG"
  834. rm "$DOWNLOG"
  835. # only if the file exists the download was successful
  836. if [ -e "$2" ]; then
  837. return 0
  838. else
  839. return 1
  840. fi
  841. }
  842. checkdiff() {
  843. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  844. if [ -n "$DIFFTEXT" ]; then
  845. echo
  846. echo "$DIFFTEXT"
  847. return 1
  848. else
  849. return 0
  850. fi
  851. }
  852. testfileequal() {
  853. local FILE="$1"
  854. shift
  855. msgtest "Test for correctness of file" "$FILE"
  856. if [ -z "$*" ]; then
  857. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  858. else
  859. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  860. fi
  861. }
  862. testempty() {
  863. msgtest "Test for no output of" "$*"
  864. test -z "$($* 2>&1)" && msgpass || msgfail
  865. }
  866. testequal() {
  867. local COMPAREFILE=$(mktemp)
  868. addtrap "rm $COMPAREFILE;"
  869. echo "$1" > $COMPAREFILE
  870. shift
  871. msgtest "Test for equality of" "$*"
  872. $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  873. }
  874. testequalor2() {
  875. local COMPAREFILE1=$(mktemp)
  876. local COMPAREFILE2=$(mktemp)
  877. local COMPAREAGAINST=$(mktemp)
  878. addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
  879. echo "$1" > $COMPAREFILE1
  880. echo "$2" > $COMPAREFILE2
  881. shift 2
  882. msgtest "Test for equality OR of" "$*"
  883. $* >$COMPAREAGAINST 2>&1 || true
  884. (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
  885. checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
  886. ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
  887. "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
  888. msgfail )
  889. }
  890. testshowvirtual() {
  891. local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
  892. local PACKAGE="$1"
  893. shift
  894. while [ -n "$1" ]; do
  895. VIRTUAL="${VIRTUAL}
  896. N: Can't select versions from package '$1' as it is purely virtual"
  897. PACKAGE="${PACKAGE} $1"
  898. shift
  899. done
  900. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  901. VIRTUAL="${VIRTUAL}
  902. N: No packages found"
  903. local COMPAREFILE=$(mktemp)
  904. addtrap "rm $COMPAREFILE;"
  905. local ARCH="$(getarchitecture 'native')"
  906. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  907. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  908. }
  909. testnopackage() {
  910. msgtest "Test for non-existent packages" "apt-cache show $*"
  911. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  912. if [ -n "$SHOWPKG" ]; then
  913. echo
  914. echo "$SHOWPKG"
  915. msgfail
  916. return 1
  917. fi
  918. msgpass
  919. }
  920. testdpkginstalled() {
  921. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  922. local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
  923. if [ "$PKGS" != $# ]; then
  924. echo $PKGS
  925. dpkg -l $* | grep '^[a-z]'
  926. msgfail
  927. return 1
  928. fi
  929. msgpass
  930. }
  931. testdpkgnotinstalled() {
  932. msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
  933. local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
  934. if [ "$PKGS" != 0 ]; then
  935. echo
  936. dpkg -l $* | grep '^[a-z]'
  937. msgfail
  938. return 1
  939. fi
  940. msgpass
  941. }
  942. testmarkedauto() {
  943. local COMPAREFILE=$(mktemp)
  944. addtrap "rm $COMPAREFILE;"
  945. if [ -n "$1" ]; then
  946. msgtest 'Test for correctly marked as auto-installed' "$*"
  947. while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
  948. else
  949. msgtest 'Test for correctly marked as auto-installed' 'no package'
  950. echo -n > $COMPAREFILE
  951. fi
  952. aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  953. }
  954. testsuccess() {
  955. if [ "$1" = '--nomsg' ]; then
  956. shift
  957. else
  958. msgtest 'Test for successful execution of' "$*"
  959. fi
  960. local OUTPUT=$(mktemp)
  961. addtrap "rm $OUTPUT;"
  962. if $@ >${OUTPUT} 2>&1; then
  963. msgpass
  964. else
  965. echo
  966. cat $OUTPUT
  967. msgfail
  968. fi
  969. }
  970. testfailure() {
  971. if [ "$1" = '--nomsg' ]; then
  972. shift
  973. else
  974. msgtest 'Test for failure in execution of' "$*"
  975. fi
  976. local OUTPUT=$(mktemp)
  977. addtrap "rm $OUTPUT;"
  978. if $@ >${OUTPUT} 2>&1; then
  979. echo
  980. cat $OUTPUT
  981. msgfail
  982. else
  983. msgpass
  984. fi
  985. }
  986. pause() {
  987. echo "STOPPED execution. Press enter to continue"
  988. local IGNORE
  989. read IGNORE
  990. }