framework 45 KB

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