framework 39 KB

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