framework 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. #!/bin/sh -- # no runable script, just for vi
  2. EXIT_CODE=0
  3. # we all like colorful messages
  4. if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null && \
  5. expr match "$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev/null; then
  6. CERROR="" # red
  7. CWARNING="" # yellow
  8. CMSG="" # green
  9. CINFO="" # light blue
  10. CDEBUG="" # blue
  11. CNORMAL="" # default system console color
  12. CDONE="" # green
  13. CPASS="" # green
  14. CFAIL="" # red
  15. CCMD="" # pink
  16. fi
  17. msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
  18. msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
  19. msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
  20. msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
  21. msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
  22. msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
  23. msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
  24. msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
  25. msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
  26. msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
  27. msgtest() {
  28. while [ -n "$1" ]; do
  29. echo -n "${CINFO}$1${CCMD} " >&2;
  30. echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2;
  31. shift
  32. if [ -n "$1" ]; then shift; else break; fi
  33. done
  34. echo -n "…${CNORMAL} " >&2;
  35. }
  36. msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
  37. msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
  38. msgfail() {
  39. if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
  40. else echo "${CFAIL}FAIL${CNORMAL}" >&2; fi
  41. EXIT_CODE=$((EXIT_CODE+1));
  42. }
  43. # enable / disable Debugging
  44. MSGLEVEL=${MSGLEVEL:-3}
  45. if [ $MSGLEVEL -le 0 ]; then
  46. msgdie() { true; }
  47. fi
  48. if [ $MSGLEVEL -le 1 ]; then
  49. msgwarn() { true; }
  50. msgnwarn() { true; }
  51. fi
  52. if [ $MSGLEVEL -le 2 ]; then
  53. msgmsg() { true; }
  54. msgnmsg() { true; }
  55. msgtest() { true; }
  56. msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
  57. msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
  58. if [ -n "$CFAIL" ]; then
  59. msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
  60. else
  61. msgfail() { echo -n " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
  62. fi
  63. fi
  64. if [ $MSGLEVEL -le 3 ]; then
  65. msginfo() { true; }
  66. msgninfo() { true; }
  67. fi
  68. if [ $MSGLEVEL -le 4 ]; then
  69. msgdebug() { true; }
  70. msgndebug() { true; }
  71. fi
  72. msgdone() {
  73. if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
  74. [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
  75. [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
  76. [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
  77. [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
  78. true;
  79. else
  80. echo "${CDONE}DONE${CNORMAL}" >&2;
  81. fi
  82. }
  83. runapt() {
  84. msgdebug "Executing: ${CCMD}$*${CDEBUG} "
  85. if [ -f ./aptconfig.conf ]; then
  86. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  87. elif [ -f ../aptconfig.conf ]; then
  88. APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  89. else
  90. LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  91. fi
  92. }
  93. aptconfig() { runapt apt-config $*; }
  94. aptcache() { runapt apt-cache $*; }
  95. aptcdrom() { runapt apt-cdrom $*; }
  96. aptget() { runapt apt-get $*; }
  97. aptftparchive() { runapt apt-ftparchive $*; }
  98. aptkey() { runapt apt-key $*; }
  99. aptmark() { runapt apt-mark $*; }
  100. dpkg() {
  101. $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
  102. }
  103. aptitude() {
  104. if [ -f ./aptconfig.conf ]; then
  105. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  106. elif [ -f ../aptconfig.conf ]; then
  107. APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  108. else
  109. LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  110. fi
  111. }
  112. gdb() {
  113. echo "gdb: run »$*«"
  114. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1
  115. }
  116. http() {
  117. LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http
  118. }
  119. exitwithstatus() {
  120. # error if we about to overflow, but ...
  121. # "255 failures ought to be enough for everybody"
  122. if [ $EXIT_CODE -gt 255 ]; then
  123. msgdie "Total failure count $EXIT_CODE too big"
  124. fi
  125. exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
  126. }
  127. shellsetedetector() {
  128. local exit_status=$?
  129. if [ "$exit_status" != '0' ]; then
  130. echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
  131. if [ "$EXIT_CODE" = '0' ]; then
  132. EXIT_CODE="$exit_status"
  133. fi
  134. fi
  135. }
  136. addtrap() {
  137. if [ "$1" = 'prefix' ]; then
  138. CURRENTTRAP="$2 $CURRENTTRAP"
  139. else
  140. CURRENTTRAP="$CURRENTTRAP $1"
  141. fi
  142. trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  143. }
  144. setupenvironment() {
  145. TMPWORKINGDIRECTORY=$(mktemp -d)
  146. TESTDIRECTORY=$(readlink -f $(dirname $0))
  147. msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
  148. BUILDDIRECTORY="${TESTDIRECTORY}/../../build/bin"
  149. test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
  150. addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
  151. cd $TMPWORKINGDIRECTORY
  152. mkdir rootdir aptarchive keys
  153. cd rootdir
  154. mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
  155. mkdir -p var/cache var/lib var/log
  156. mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
  157. touch var/lib/dpkg/available
  158. mkdir -p usr/lib/apt
  159. ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
  160. cd ..
  161. local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
  162. if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
  163. cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
  164. fi
  165. local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
  166. if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
  167. cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
  168. fi
  169. cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
  170. ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  171. echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
  172. echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
  173. echo "Debug::NoLocking \"true\";" >> aptconfig.conf
  174. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  175. echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
  176. echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
  177. echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
  178. echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
  179. echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
  180. echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
  181. if ! $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
  182. echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
  183. fi
  184. echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
  185. echo 'quiet::NoUpdate "true";' >> aptconfig.conf
  186. export LC_ALL=C
  187. export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
  188. msgdone "info"
  189. }
  190. getarchitecture() {
  191. if [ "$1" = "native" -o -z "$1" ]; then
  192. eval `aptconfig shell ARCH APT::Architecture`
  193. if [ -n "$ARCH" ]; then
  194. echo $ARCH
  195. else
  196. dpkg --print-architecture
  197. fi
  198. else
  199. echo $1
  200. fi
  201. }
  202. getarchitectures() {
  203. echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  204. }
  205. configarchitecture() {
  206. local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
  207. rm -f $CONFFILE
  208. echo "APT::Architecture \"$(getarchitecture $1)\";" > $CONFFILE
  209. shift
  210. while [ -n "$1" ]; do
  211. echo "APT::Architectures:: \"$(getarchitecture $1)\";" >> $CONFFILE
  212. shift
  213. done
  214. configdpkg
  215. }
  216. configdpkg() {
  217. if [ ! -e rootdir/var/lib/dpkg/status ]; then
  218. local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
  219. if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
  220. cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
  221. else
  222. echo -n > rootdir/var/lib/dpkg/status
  223. fi
  224. fi
  225. if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
  226. local ARCHS="$(getarchitectures)"
  227. if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
  228. DPKGARCH="$(dpkg --print-architecture)"
  229. for ARCH in ${ARCHS}; do
  230. if [ "${ARCH}" != "${DPKGARCH}" ]; then dpkg --add-architecture ${ARCH}; fi
  231. done
  232. if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
  233. # dpkg doesn't really check the version as long as it is fully installed,
  234. # but just to be sure we choose one above the required version
  235. insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
  236. fi
  237. fi
  238. fi
  239. }
  240. setupsimplenativepackage() {
  241. local NAME="$1"
  242. local ARCH="$2"
  243. local VERSION="$3"
  244. local RELEASE="${4:-unstable}"
  245. local DEPENDENCIES="$5"
  246. local DESCRIPTION="$6"
  247. local SECTION="${7:-others}"
  248. local DISTSECTION
  249. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  250. DISTSECTION="main"
  251. else
  252. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  253. fi
  254. local BUILDDIR=incoming/${NAME}-${VERSION}
  255. mkdir -p ${BUILDDIR}/debian/source
  256. cd ${BUILDDIR}
  257. echo "* most suckless software product ever" > FEATURES
  258. test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
  259. test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
  260. * Initial release
  261. -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
  262. test -e debian/control || echo "Source: $NAME
  263. Section: $SECTION
  264. Priority: optional
  265. Maintainer: Joe Sixpack <joe@example.org>
  266. Build-Depends: debhelper (>= 7)
  267. Standards-Version: 3.9.1
  268. Package: $NAME" > debian/control
  269. if [ "$ARCH" = 'all' ]; then
  270. echo "Architecture: all" >> debian/control
  271. else
  272. echo "Architecture: any" >> debian/control
  273. fi
  274. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
  275. if [ -z "$DESCRIPTION" ]; then
  276. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  277. If you find such a package installed on your system,
  278. YOU did something horribly wrong! They are autogenerated
  279. und used only by testcases for APT and surf no other propose…" >> debian/control
  280. else
  281. echo "Description: $DESCRIPTION" >> debian/control
  282. fi
  283. test -e debian/compat || echo "7" > debian/compat
  284. test -e debian/source/format || echo "3.0 (native)" > debian/source/format
  285. test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
  286. cd - > /dev/null
  287. }
  288. buildsimplenativepackage() {
  289. local NAME="$1"
  290. local ARCH="$2"
  291. local VERSION="$3"
  292. local RELEASE="${4:-unstable}"
  293. local DEPENDENCIES="$5"
  294. local DESCRIPTION="$6"
  295. local SECTION="${7:-others}"
  296. local PRIORITY="${8:-optional}"
  297. local DISTSECTION
  298. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  299. DISTSECTION="main"
  300. else
  301. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  302. fi
  303. local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
  304. msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
  305. mkdir -p $BUILDDIR/debian/source
  306. echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
  307. echo "#!/bin/sh
  308. echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
  309. echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
  310. echo "$NAME ($VERSION) $RELEASE; urgency=low
  311. * Initial release
  312. -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
  313. echo "Source: $NAME
  314. Section: $SECTION
  315. Priority: $PRIORITY
  316. Maintainer: Joe Sixpack <joe@example.org>
  317. Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
  318. local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
  319. test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
  320. echo "
  321. Package: $NAME" >> ${BUILDDIR}/debian/control
  322. if [ "$ARCH" = 'all' ]; then
  323. echo "Architecture: all" >> ${BUILDDIR}/debian/control
  324. else
  325. echo "Architecture: any" >> ${BUILDDIR}/debian/control
  326. fi
  327. local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
  328. test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
  329. if [ -z "$DESCRIPTION" ]; then
  330. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  331. If you find such a package installed on your system,
  332. YOU did something horribly wrong! They are autogenerated
  333. und used only by testcases for APT and surf no other propose…" >> ${BUILDDIR}/debian/control
  334. else
  335. echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
  336. fi
  337. echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
  338. (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
  339. | while read SRC; do
  340. echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
  341. # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
  342. # gpg --yes --no-default-keyring --secret-keyring ./keys/joesixpack.sec \
  343. # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
  344. # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  345. # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
  346. # fi
  347. done
  348. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  349. rm -rf ${BUILDDIR}/debian/tmp
  350. mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
  351. cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
  352. cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
  353. (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
  354. (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
  355. dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null
  356. echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
  357. done
  358. mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
  359. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
  360. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
  361. rm -rf "${BUILDDIR}"
  362. msgdone "info"
  363. }
  364. buildpackage() {
  365. local BUILDDIR=$1
  366. local RELEASE=$2
  367. local SECTION=$3
  368. local ARCH=$(getarchitecture $4)
  369. msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
  370. cd $BUILDDIR
  371. if [ "$ARCH" = "all" ]; then
  372. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  373. fi
  374. local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
  375. local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
  376. local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
  377. cd - > /dev/null
  378. for PKG in $PKGS; do
  379. echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
  380. done
  381. for SRC in $SRCS; do
  382. echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
  383. done
  384. msgdone "info"
  385. }
  386. buildaptarchive() {
  387. if [ -d incoming ]; then
  388. buildaptarchivefromincoming $*
  389. else
  390. buildaptarchivefromfiles $*
  391. fi
  392. }
  393. createaptftparchiveconfig() {
  394. 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' ' ')"
  395. if [ -z "$ARCHS" ]; then
  396. # the pool is empty, so we will operate on faked packages - let us use the configured archs
  397. ARCHS="$(getarchitectures)"
  398. fi
  399. echo -n 'Dir {
  400. ArchiveDir "' >> ftparchive.conf
  401. echo -n $(readlink -f .) >> ftparchive.conf
  402. echo -n '";
  403. CacheDir "' >> ftparchive.conf
  404. echo -n $(readlink -f ..) >> ftparchive.conf
  405. echo -n '";
  406. FileListDir "' >> ftparchive.conf
  407. echo -n $(readlink -f pool/) >> ftparchive.conf
  408. echo -n '";
  409. };
  410. Default {
  411. Packages::Compress ". gzip bzip2 lzma xz";
  412. Sources::Compress ". gzip bzip2 lzma xz";
  413. Contents::Compress ". gzip bzip2 lzma xz";
  414. Translation::Compress ". gzip bzip2 lzma xz";
  415. LongDescription "false";
  416. };
  417. TreeDefault {
  418. Directory "pool/";
  419. SrcDirectory "pool/";
  420. };
  421. APT {
  422. FTPArchive {
  423. Release {
  424. Origin "joesixpack";
  425. Label "apttestcases";
  426. Suite "unstable";
  427. Description "repository with dummy packages";
  428. Architectures "' >> ftparchive.conf
  429. echo -n "$ARCHS" >> ftparchive.conf
  430. echo 'source";
  431. };
  432. };
  433. };' >> ftparchive.conf
  434. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  435. echo -n 'tree "dists/' >> ftparchive.conf
  436. echo -n "$DIST" >> ftparchive.conf
  437. echo -n '" {
  438. Architectures "' >> ftparchive.conf
  439. echo -n "$ARCHS" >> ftparchive.conf
  440. echo -n 'source";
  441. FileList "' >> ftparchive.conf
  442. echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
  443. echo -n '";
  444. SourceFileList "' >> ftparchive.conf
  445. echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
  446. echo -n '";
  447. Sections "' >> ftparchive.conf
  448. 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
  449. echo '";
  450. };' >> ftparchive.conf
  451. done
  452. }
  453. buildaptftparchivedirectorystructure() {
  454. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  455. for DIST in $DISTS; do
  456. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  457. for SECTION in $SECTIONS; do
  458. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  459. for ARCH in $ARCHS; do
  460. mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
  461. done
  462. mkdir -p dists/${DIST}/${SECTION}/source
  463. mkdir -p dists/${DIST}/${SECTION}/i18n
  464. done
  465. done
  466. }
  467. insertpackage() {
  468. local RELEASE="$1"
  469. local NAME="$2"
  470. local ARCH="$3"
  471. local VERSION="$4"
  472. local DEPENDENCIES="$5"
  473. local PRIORITY="${6:-optional}"
  474. local DESCRIPTION="${7}"
  475. local ARCHS=""
  476. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  477. if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
  478. ARCHS="$(getarchitectures)"
  479. else
  480. ARCHS="$arch"
  481. fi
  482. for BUILDARCH in $ARCHS; do
  483. local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
  484. mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
  485. touch aptarchive/dists/${RELEASE}/main/source/Sources
  486. local FILE="${PPATH}/Packages"
  487. echo "Package: $NAME
  488. Priority: $PRIORITY
  489. Section: other
  490. Installed-Size: 42
  491. Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
  492. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  493. echo "Version: $VERSION
  494. Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
  495. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  496. echo -n 'Description: ' >> $FILE
  497. if [ -z "$DESCRIPTION" ]; then
  498. echo "an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  499. If you find such a package installed on your system,
  500. YOU did something horribly wrong! They are autogenerated
  501. und used only by testcases for APT and surf no other propose…" >> $FILE
  502. else
  503. echo "$DESCRIPTION" >> $FILE
  504. fi
  505. echo >> $FILE
  506. done
  507. done
  508. }
  509. insertsource() {
  510. local RELEASE="$1"
  511. local NAME="$2"
  512. local ARCH="$3"
  513. local VERSION="$4"
  514. local DEPENDENCIES="$5"
  515. local ARCHS=""
  516. local SPATH="aptarchive/dists/${RELEASE}/main/source"
  517. mkdir -p $SPATH
  518. local FILE="${SPATH}/Sources"
  519. echo "Package: $NAME
  520. Binary: $NAME
  521. Version: $VERSION
  522. Maintainer: Joe Sixpack <joe@example.org>
  523. Architecture: $ARCH" >> $FILE
  524. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  525. echo "Files:
  526. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
  527. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
  528. " >> $FILE
  529. }
  530. insertinstalledpackage() {
  531. local NAME="$1"
  532. local ARCH="$2"
  533. local VERSION="$3"
  534. local DEPENDENCIES="$4"
  535. local PRIORITY="${5:-optional}"
  536. local STATUS="${6:-install ok installed}"
  537. local FILE='rootdir/var/lib/dpkg/status'
  538. local INFO='rootdir/var/lib/dpkg/info'
  539. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  540. echo "Package: $NAME
  541. Status: $STATUS
  542. Priority: $PRIORITY
  543. Section: other
  544. Installed-Size: 42
  545. Maintainer: Joe Sixpack <joe@example.org>
  546. Version: $VERSION" >> $FILE
  547. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  548. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  549. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed
  550. If you find such a package installed on your system,
  551. YOU did something horribly wrong! They are autogenerated
  552. und used only by testcases for APT and surf no other propose…
  553. " >> $FILE
  554. if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
  555. echo -n > ${INFO}/${NAME}:${arch}.list
  556. else
  557. echo -n > ${INFO}/${NAME}.list
  558. fi
  559. done
  560. }
  561. buildaptarchivefromincoming() {
  562. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
  563. cd aptarchive
  564. [ -e pool ] || ln -s ../incoming pool
  565. [ -e ftparchive.conf ] || createaptftparchiveconfig
  566. [ -e dists ] || buildaptftparchivedirectorystructure
  567. msgninfo "\tGenerate Packages, Sources and Contents files… "
  568. aptftparchive -qq generate ftparchive.conf
  569. cd - > /dev/null
  570. msgdone "info"
  571. generatereleasefiles
  572. }
  573. buildaptarchivefromfiles() {
  574. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
  575. find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
  576. msgninfo "\t${line} file… "
  577. cat ${line} | gzip > ${line}.gz
  578. cat ${line} | bzip2 > ${line}.bz2
  579. cat ${line} | xz --format=lzma > ${line}.lzma
  580. cat ${line} | xz > ${line}.xz
  581. if [ -n "$1" ]; then
  582. touch -d "$1" ${line}.gz ${line}.bz2 ${line}.lzma ${line}.xz
  583. fi
  584. msgdone "info"
  585. done
  586. generatereleasefiles "$@"
  587. }
  588. # can be overridden by testcases for their pleasure
  589. getcodenamefromsuite() { echo -n "$1"; }
  590. getreleaseversionfromsuite() { true; }
  591. getlabelfromsuite() { true; }
  592. generatereleasefiles() {
  593. # $1 is the Date header and $2 is the ValidUntil header to be set
  594. # both should be given in notation date/touch can understand
  595. msgninfo "\tGenerate Release files… "
  596. if [ -e aptarchive/dists ]; then
  597. for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
  598. local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
  599. local CODENAME="$(getcodenamefromsuite $SUITE)"
  600. local VERSION="$(getreleaseversionfromsuite $SUITE)"
  601. local LABEL="$(getlabelfromsuite $SUITE)"
  602. if [ -n "$VERSION" ]; then
  603. VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
  604. fi
  605. if [ -n "$LABEL" ]; then
  606. LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
  607. fi
  608. aptftparchive -qq release $dir \
  609. -o APT::FTPArchive::Release::Suite="${SUITE}" \
  610. -o APT::FTPArchive::Release::Codename="${CODENAME}" \
  611. ${LABEL} \
  612. ${VERSION} \
  613. | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
  614. if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
  615. sed -i '/^Date: / a\
  616. NotAutomatic: yes' $dir/Release
  617. fi
  618. if [ -n "$1" -a "$1" != "now" ]; then
  619. sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
  620. fi
  621. if [ -n "$2" ]; then
  622. sed -i "/^Date: / a\
  623. Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
  624. fi
  625. done
  626. else
  627. aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
  628. fi
  629. if [ -n "$1" -a "$1" != "now" ]; then
  630. for release in $(find ./aptarchive -name 'Release'); do
  631. touch -d "$1" $release
  632. done
  633. fi
  634. msgdone "info"
  635. }
  636. setupdistsaptarchive() {
  637. local APTARCHIVE=$(readlink -f ./aptarchive)
  638. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  639. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  640. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  641. SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  642. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  643. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
  644. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
  645. msgdone "info"
  646. done
  647. }
  648. setupflataptarchive() {
  649. local APTARCHIVE=$(readlink -f ./aptarchive)
  650. if [ -f ${APTARCHIVE}/Packages ]; then
  651. msgninfo "\tadd deb sources.list line… "
  652. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  653. msgdone "info"
  654. else
  655. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  656. fi
  657. if [ -f ${APTARCHIVE}/Sources ]; then
  658. msgninfo "\tadd deb-src sources.list line… "
  659. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  660. msgdone "info"
  661. else
  662. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  663. fi
  664. }
  665. setupaptarchive() {
  666. buildaptarchive
  667. if [ -e aptarchive/dists ]; then
  668. setupdistsaptarchive
  669. else
  670. setupflataptarchive
  671. fi
  672. signreleasefiles
  673. if [ "$1" != '--no-update' ]; then
  674. msgninfo "\tSync APT's cache with the archive… "
  675. aptget update -qq
  676. msgdone "info"
  677. fi
  678. }
  679. signreleasefiles() {
  680. local SIGNER="${1:-Joe Sixpack}"
  681. local GPG="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
  682. msgninfo "\tSign archive with $SIGNER key… "
  683. local REXKEY='keys/rexexpired'
  684. local SECEXPIREBAK="${REXKEY}.sec.bak"
  685. local PUBEXPIREBAK="${REXKEY}.pub.bak"
  686. if [ "${SIGNER}" = 'Rex Expired' ]; then
  687. # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
  688. # option doesn't exist anymore (and using faketime would add a new obscure dependency)
  689. # therefore we 'temporary' make the key not expired and restore a backup after signing
  690. cp ${REXKEY}.sec $SECEXPIREBAK
  691. cp ${REXKEY}.pub $PUBEXPIREBAK
  692. local SECUNEXPIRED="${REXKEY}.sec.unexpired"
  693. local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
  694. if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
  695. cp $SECUNEXPIRED ${REXKEY}.sec
  696. cp $PUBUNEXPIRED ${REXKEY}.pub
  697. else
  698. printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub --secret-keyring ${REXKEY}.sec --command-fd 0 --edit-key "${SIGNER}" >/dev/null 2>&1 || true
  699. cp ${REXKEY}.sec $SECUNEXPIRED
  700. cp ${REXKEY}.pub $PUBUNEXPIRED
  701. fi
  702. fi
  703. for KEY in $(find keys/ -name '*.sec'); do
  704. GPG="$GPG --secret-keyring $KEY"
  705. done
  706. for KEY in $(find keys/ -name '*.pub'); do
  707. GPG="$GPG --keyring $KEY"
  708. done
  709. for RELEASE in $(find aptarchive/ -name Release); do
  710. $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
  711. local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
  712. $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
  713. # we might have set a specific date for the Release file, so copy it
  714. touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
  715. done
  716. if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
  717. mv -f $SECEXPIREBAK ${REXKEY}.sec
  718. mv -f $PUBEXPIREBAK ${REXKEY}.pub
  719. fi
  720. msgdone "info"
  721. }
  722. changetowebserver() {
  723. local LOG='/dev/null'
  724. if test -x ${BUILDDIRECTORY}/aptwebserver; then
  725. cd aptarchive
  726. LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
  727. local PID="$(cat aptwebserver.pid)"
  728. if [ -z "$PID" ]; then
  729. msgdie 'Could not fork aptwebserver successfully'
  730. fi
  731. addtrap "kill $PID;"
  732. cd - > /dev/null
  733. elif [ $# -gt 0 ]; then
  734. msgdie 'Need the aptwebserver when passing arguments for the webserver'
  735. elif which weborf > /dev/null; then
  736. weborf -xb aptarchive/ >$LOG 2>&1 &
  737. addtrap "kill $!;"
  738. elif which gatling > /dev/null; then
  739. cd aptarchive
  740. gatling -p 8080 -F -S >$LOG 2>&1 &
  741. addtrap "kill $!;"
  742. cd - > /dev/null
  743. elif which lighttpd > /dev/null; then
  744. echo "server.document-root = \"$(readlink -f ./aptarchive)\"
  745. server.port = 8080
  746. server.stat-cache-engine = \"disable\"" > lighttpd.conf
  747. lighttpd -t -f lighttpd.conf >/dev/null || msgdie 'Can not change to webserver: our lighttpd config is invalid'
  748. lighttpd -D -f lighttpd.conf >$LOG 2>&1 &
  749. addtrap "kill $!;"
  750. else
  751. msgdie 'You have to build aptwerbserver or install a webserver'
  752. fi
  753. local APTARCHIVE="file://$(readlink -f ./aptarchive)"
  754. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  755. sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
  756. done
  757. return 0
  758. }
  759. changetocdrom() {
  760. mkdir -p rootdir/media/cdrom/.disk
  761. local CD="$(readlink -f rootdir/media/cdrom)"
  762. echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
  763. echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
  764. echo -n "$1" > ${CD}/.disk/info
  765. if [ ! -d aptarchive/dists ]; then
  766. msgdie 'Flat file archive cdroms can not be created currently'
  767. return 1
  768. fi
  769. mv aptarchive/dists $CD
  770. ln -s "$(readlink -f ./incoming)" $CD/pool
  771. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  772. }
  773. checkdiff() {
  774. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  775. if [ -n "$DIFFTEXT" ]; then
  776. echo
  777. echo "$DIFFTEXT"
  778. return 1
  779. else
  780. return 0
  781. fi
  782. }
  783. testfileequal() {
  784. local FILE="$1"
  785. shift
  786. msgtest "Test for correctness of file" "$FILE"
  787. if [ -z "$*" ]; then
  788. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  789. else
  790. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  791. fi
  792. }
  793. testempty() {
  794. msgtest "Test for no output of" "$*"
  795. test -z "$($* 2>&1)" && msgpass || msgfail
  796. }
  797. testequal() {
  798. local COMPAREFILE=$(mktemp)
  799. addtrap "rm $COMPAREFILE;"
  800. echo "$1" > $COMPAREFILE
  801. shift
  802. msgtest "Test for equality of" "$*"
  803. $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  804. }
  805. testequalor2() {
  806. local COMPAREFILE1=$(mktemp)
  807. local COMPAREFILE2=$(mktemp)
  808. local COMPAREAGAINST=$(mktemp)
  809. addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
  810. echo "$1" > $COMPAREFILE1
  811. echo "$2" > $COMPAREFILE2
  812. shift 2
  813. msgtest "Test for equality OR of" "$*"
  814. $* >$COMPAREAGAINST 2>&1
  815. (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
  816. checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
  817. ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
  818. "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
  819. msgfail )
  820. }
  821. testshowvirtual() {
  822. local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
  823. local PACKAGE="$1"
  824. shift
  825. while [ -n "$1" ]; do
  826. VIRTUAL="${VIRTUAL}
  827. N: Can't select versions from package '$1' as it is purely virtual"
  828. PACKAGE="${PACKAGE} $1"
  829. shift
  830. done
  831. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  832. VIRTUAL="${VIRTUAL}
  833. N: No packages found"
  834. local COMPAREFILE=$(mktemp)
  835. addtrap "rm $COMPAREFILE;"
  836. local ARCH="$(getarchitecture 'native')"
  837. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  838. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  839. }
  840. testnopackage() {
  841. msgtest "Test for non-existent packages" "apt-cache show $*"
  842. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  843. if [ -n "$SHOWPKG" ]; then
  844. echo
  845. echo "$SHOWPKG"
  846. msgfail
  847. return 1
  848. fi
  849. msgpass
  850. }
  851. testdpkginstalled() {
  852. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  853. local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
  854. if [ "$PKGS" != $# ]; then
  855. echo $PKGS
  856. dpkg -l $* | grep '^[a-z]'
  857. msgfail
  858. return 1
  859. fi
  860. msgpass
  861. }
  862. testdpkgnotinstalled() {
  863. msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
  864. local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
  865. if [ "$PKGS" != 0 ]; then
  866. echo
  867. dpkg -l $* | grep '^[a-z]'
  868. msgfail
  869. return 1
  870. fi
  871. msgpass
  872. }
  873. testmarkedauto() {
  874. local COMPAREFILE=$(mktemp)
  875. addtrap "rm $COMPAREFILE;"
  876. if [ -n "$1" ]; then
  877. msgtest 'Test for correctly marked as auto-installed' "$*"
  878. while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
  879. else
  880. msgtest 'Test for correctly marked as auto-installed' 'no package'
  881. echo -n > $COMPAREFILE
  882. fi
  883. aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  884. }
  885. testsuccess() {
  886. if [ "$1" = '--nomsg' ]; then
  887. shift
  888. else
  889. msgtest 'Test for successful execution of' "$*"
  890. fi
  891. local OUTPUT=$(mktemp)
  892. addtrap "rm $OUTPUT;"
  893. if $@ >${OUTPUT} 2>&1; then
  894. msgpass
  895. else
  896. echo
  897. cat $OUTPUT
  898. msgfail
  899. fi
  900. }
  901. testfailure() {
  902. if [ "$1" = '--nomsg' ]; then
  903. shift
  904. else
  905. msgtest 'Test for failure in execution of' "$*"
  906. fi
  907. local OUTPUT=$(mktemp)
  908. addtrap "rm $OUTPUT;"
  909. if $@ >${OUTPUT} 2>&1; then
  910. echo
  911. cat $OUTPUT
  912. msgfail
  913. else
  914. msgpass
  915. fi
  916. }
  917. pause() {
  918. echo "STOPPED execution. Press enter to continue"
  919. local IGNORE
  920. read IGNORE
  921. }