framework 38 KB

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