framework 41 KB

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