framework 36 KB

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