framework 36 KB

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