framework 34 KB

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