framework 39 KB

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