You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

framework 17 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. #!/bin/sh -- # no runable script, just for vi
  2. # we all like colorful messages
  3. CERROR="" # red
  4. CWARNING="" # yellow
  5. CMSG="" # green
  6. CINFO="" # light blue
  7. CDEBUG="" # blue
  8. CNORMAL="" # default system console color
  9. CDONE="" # green
  10. CPASS="" # green
  11. CFAIL="" # red
  12. CCMD="" # pink
  13. msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
  14. msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
  15. msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
  16. msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
  17. msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
  18. msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
  19. msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
  20. msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
  21. msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
  22. msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
  23. msgtest() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; }
  24. msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
  25. msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
  26. msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
  27. # enable / disable Debugging
  28. MSGLEVEL=${MSGLEVEL:-3}
  29. if [ $MSGLEVEL -le 0 ]; then
  30. msgdie() { true; }
  31. fi
  32. if [ $MSGLEVEL -le 1 ]; then
  33. msgwarn() { true; }
  34. msgnwarn() { true; }
  35. fi
  36. if [ $MSGLEVEL -le 2 ]; then
  37. msgmsg() { true; }
  38. msgnmsg() { true; }
  39. fi
  40. if [ $MSGLEVEL -le 3 ]; then
  41. msginfo() { true; }
  42. msgninfo() { true; }
  43. fi
  44. if [ $MSGLEVEL -le 4 ]; then
  45. msgdebug() { true; }
  46. msgndebug() { true; }
  47. fi
  48. msgdone() {
  49. if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
  50. [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
  51. [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
  52. [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
  53. [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
  54. true;
  55. else
  56. echo "${CDONE}DONE${CNORMAL}" >&2;
  57. fi
  58. }
  59. runapt() {
  60. msgdebug "Executing: ${CCMD}$*${CDEBUG} "
  61. if [ -f ./aptconfig.conf ]; then
  62. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  63. elif [ -f ../aptconfig.conf ]; then
  64. APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  65. else
  66. LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  67. fi
  68. }
  69. aptconfig() { runapt apt-config $*; }
  70. aptcache() { runapt apt-cache $*; }
  71. aptget() { runapt apt-get $*; }
  72. aptftparchive() { runapt apt-ftparchive $*; }
  73. aptkey() { runapt apt-key $*; }
  74. dpkg() {
  75. $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
  76. }
  77. setupenvironment() {
  78. TMPWORKINGDIRECTORY=$(mktemp -d)
  79. local TESTDIR=$(readlink -f $(dirname $0))
  80. msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
  81. BUILDDIRECTORY="${TESTDIR}/../../build/bin"
  82. test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
  83. local OLDWORKINGDIRECTORY=$(pwd)
  84. CURRENTTRAP="cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY"
  85. trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  86. cd $TMPWORKINGDIRECTORY
  87. mkdir rootdir aptarchive keys
  88. cd rootdir
  89. mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
  90. mkdir -p var/cache var/lib var/log
  91. mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
  92. local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
  93. if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
  94. cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
  95. else
  96. touch var/lib/dpkg/status
  97. fi
  98. touch var/lib/dpkg/available
  99. mkdir -p usr/lib/apt
  100. ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
  101. cd ..
  102. local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
  103. if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
  104. cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
  105. else
  106. touch aptarchive/Packages
  107. fi
  108. cp $(find $TESTDIR -name '*.pub' -o -name '*.sec') keys/
  109. ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  110. echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
  111. echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
  112. echo "Debug::NoLocking \"true\";" >> aptconfig.conf
  113. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  114. echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
  115. echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
  116. echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
  117. echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
  118. echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
  119. echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
  120. export LC_ALL=C
  121. msgdone "info"
  122. }
  123. configarchitecture() {
  124. local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
  125. echo "APT::Architecture \"$1\";" > $CONFFILE
  126. shift
  127. while [ -n "$1" ]; do
  128. echo "APT::Architectures:: \"$1\";" >> $CONFFILE
  129. shift
  130. done
  131. }
  132. setupsimplenativepackage() {
  133. local NAME="$1"
  134. local ARCH="$2"
  135. local VERSION="$3"
  136. local RELEASE="${4:-unstable}"
  137. local DEPENDENCIES="$5"
  138. local DESCRIPTION="$6"
  139. local SECTION="${7:-others}"
  140. local DISTSECTION
  141. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  142. DISTSECTION="main"
  143. else
  144. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  145. fi
  146. local BUILDDIR=incoming/${NAME}-${VERSION}
  147. mkdir -p ${BUILDDIR}/debian/source
  148. cd ${BUILDDIR}
  149. echo "* most suckless software product ever" > FEATURES
  150. test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
  151. test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
  152. * Initial release
  153. -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
  154. test -e debian/control || echo "Source: $NAME
  155. Section: $SECTION
  156. Priority: optional
  157. Maintainer: Joe Sixpack <joe@example.org>
  158. Build-Depends: debhelper (>= 7)
  159. Standards-Version: 3.9.1
  160. Package: $NAME
  161. Architecture: $ARCH" > debian/control
  162. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
  163. if [ -z "$DESCRIPTION" ]; then
  164. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  165. If you find such a package installed on your system,
  166. YOU did something horribly wrong! They are autogenerated
  167. und used only by testcases for APT and surf no other propose…" >> debian/control
  168. else
  169. echo "Description: $DESCRIPTION" >> debian/control
  170. fi
  171. test -e debian/compat || echo "7" > debian/compat
  172. test -e debian/source/format || echo "3.0 (native)" > debian/source/format
  173. test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
  174. cd - > /dev/null
  175. }
  176. buildsimplenativepackage() {
  177. local NAME="$1"
  178. local ARCH="$2"
  179. local VERSION="$3"
  180. local RELEASE="${4:-unstable}"
  181. local DEPENDENCIES="$5"
  182. local DESCRIPTION="$6"
  183. local SECTION="${7:-others}"
  184. local DISTSECTION
  185. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  186. DISTSECTION="main"
  187. else
  188. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  189. fi
  190. setupsimplenativepackage "$NAME" "$ARCH" "$VERSION" "$RELEASE" "$DEPENDENCIES" "$DESCRIPTION" "$SECTION"
  191. buildpackage "incoming/${NAME}-${VERSION}" "$RELEASE" "$DISTSECTION"
  192. rm -rf "incoming/${NAME}-${VERSION}"
  193. }
  194. buildpackage() {
  195. local BUILDDIR=$1
  196. local RELEASE=$2
  197. local SECTION=$3
  198. msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
  199. cd $BUILDDIR
  200. if [ "$ARCH" = "all" ]; then
  201. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  202. fi
  203. local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
  204. local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
  205. local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
  206. cd - > /dev/null
  207. for PKG in $PKGS; do
  208. echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
  209. done
  210. for SRC in $SRCS; do
  211. echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
  212. done
  213. msgdone "info"
  214. }
  215. buildaptarchive() {
  216. if [ -d incoming ]; then
  217. buildaptarchivefromincoming $*
  218. else
  219. buildaptarchivefromfiles $*
  220. fi
  221. }
  222. createaptftparchiveconfig() {
  223. 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' ' ')"
  224. if [ -z "$ARCHS" ]; then
  225. # the pool is empty, so we will operate on faked packages - let us use the configured archs
  226. ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  227. fi
  228. echo -n 'Dir {
  229. ArchiveDir "' >> ftparchive.conf
  230. echo -n $(readlink -f .) >> ftparchive.conf
  231. echo -n '";
  232. CacheDir "' >> ftparchive.conf
  233. echo -n $(readlink -f ..) >> ftparchive.conf
  234. echo -n '";
  235. FileListDir "' >> ftparchive.conf
  236. echo -n $(readlink -f pool/) >> ftparchive.conf
  237. echo -n '";
  238. };
  239. Default {
  240. Packages::Compress ". gzip bzip2 lzma";
  241. Sources::Compress ". gzip bzip2 lzma";
  242. Contents::Compress ". gzip bzip2 lzma";
  243. };
  244. TreeDefault {
  245. Directory "pool/";
  246. SrcDirectory "pool/";
  247. };
  248. APT {
  249. FTPArchive {
  250. Release {
  251. Origin "joesixpack";
  252. Label "apttestcases";
  253. Suite "unstable";
  254. Description "repository with dummy packages";
  255. Architectures "' >> ftparchive.conf
  256. echo -n "$ARCHS" >> ftparchive.conf
  257. echo 'source";
  258. };
  259. };
  260. };' >> ftparchive.conf
  261. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  262. echo -n 'tree "dists/' >> ftparchive.conf
  263. echo -n "$DIST" >> ftparchive.conf
  264. echo -n '" {
  265. Architectures "' >> ftparchive.conf
  266. echo -n "$ARCHS" >> ftparchive.conf
  267. echo -n 'source";
  268. FileList "' >> ftparchive.conf
  269. echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
  270. echo -n '";
  271. SourceFileList "' >> ftparchive.conf
  272. echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
  273. echo -n '";
  274. Sections "' >> ftparchive.conf
  275. 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
  276. echo '";
  277. };' >> ftparchive.conf
  278. done
  279. }
  280. buildaptftparchivedirectorystructure() {
  281. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  282. for DIST in $DISTS; do
  283. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  284. for SECTION in $SECTIONS; do
  285. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  286. for ARCH in $ARCHS; do
  287. mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
  288. done
  289. mkdir -p dists/${DIST}/${SECTION}/source
  290. mkdir -p dists/${DIST}/${SECTION}/i18n
  291. done
  292. done
  293. }
  294. buildaptarchivefromincoming() {
  295. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
  296. cd aptarchive
  297. [ -e pool ] || ln -s ../incoming pool
  298. [ -e ftparchive.conf ] || createaptftparchiveconfig
  299. [ -e dists ] || buildaptftparchivedirectorystructure
  300. msgninfo "\tGenerate Packages, Sources and Contents files… "
  301. aptftparchive -qq generate ftparchive.conf
  302. msgdone "info"
  303. msgninfo "\tGenerate Release files… "
  304. for dir in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do
  305. aptftparchive -qq release $dir -o APT::FTPArchive::Release::Codename="$(echo "$dir" | cut -d'/' -f 3)" | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
  306. done
  307. cd - > /dev/null
  308. msgdone "info"
  309. }
  310. buildaptarchivefromfiles() {
  311. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
  312. cd aptarchive
  313. if [ -f Packages ]; then
  314. msgninfo "\tPackages file… "
  315. cat Packages | gzip > Packages.gz
  316. cat Packages | bzip2 > Packages.bz2
  317. cat Packages | lzma > Packages.lzma
  318. msgdone "info"
  319. fi
  320. if [ -f Sources ]; then
  321. msgninfo "\tSources file… "
  322. cat Sources | gzip > Sources.gz
  323. cat Sources | bzip2 > Sources.bz2
  324. cat Sources | lzma > Sources.lzma
  325. msgdone "info"
  326. fi
  327. msgninfo "\tRelease file… "
  328. aptftparchive -qq release . | sed -e '/0 Release$/ d' > Release # remove the self reference
  329. msgdone "info"
  330. cd ..
  331. }
  332. setupdistsaptarchive() {
  333. local APTARCHIVE=$(readlink -f ./aptarchive)
  334. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  335. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  336. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  337. SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  338. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  339. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
  340. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
  341. msgdone "info"
  342. done
  343. }
  344. setupflataptarchive() {
  345. local APTARCHIVE=$(readlink -f ./aptarchive)
  346. if [ -f ${APTARCHIVE}/Packages ]; then
  347. msgninfo "\tadd deb sources.list line… "
  348. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  349. msgdone "info"
  350. else
  351. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  352. fi
  353. if [ -f ${APTARCHIVE}/Sources ]; then
  354. msgninfo "\tadd deb-src sources.list line… "
  355. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  356. msgdone "info"
  357. else
  358. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  359. fi
  360. }
  361. setupaptarchive() {
  362. buildaptarchive
  363. if [ -e aptarchive/dists ]; then
  364. setupdistsaptarchive
  365. else
  366. setupflataptarchive
  367. fi
  368. signreleasefiles
  369. msgninfo "\tSync APT's cache with the archive… "
  370. aptget update -qq
  371. msgdone "info"
  372. }
  373. signreleasefiles() {
  374. local SIGNER="${1:-Joe Sixpack}"
  375. msgninfo "\tSign archive with $SIGNER key… "
  376. local SECKEYS=""
  377. for KEY in $(find keys/ -name '*.sec'); do
  378. SECKEYS="$SECKEYS --secret-keyring $KEY"
  379. done
  380. local PUBKEYS=""
  381. for KEY in $(find keys/ -name '*.pub'); do
  382. PUBKEYS="$PUBKEYS --keyring $KEY"
  383. done
  384. for RELEASE in $(find aptarchive/ -name Release); do
  385. gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
  386. done
  387. msgdone "info"
  388. }
  389. changetowebserver() {
  390. if which weborf > /dev/null; then
  391. weborf -xb aptarchive/ 2>&1 > /dev/null &
  392. CURRENTTRAP="kill $(ps | grep weborf | sed -e 's#^[ ]*##' | cut -d' ' -f 1); $CURRENTTRAP"
  393. trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  394. local APTARCHIVE="file://$(readlink -f ./aptarchive)"
  395. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  396. sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
  397. done
  398. return 0
  399. fi
  400. return 1
  401. }
  402. checkdiff() {
  403. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  404. if [ -n "$DIFFTEXT" ]; then
  405. echo
  406. echo "$DIFFTEXT"
  407. return 1
  408. else
  409. return 0
  410. fi
  411. }
  412. testfileequal() {
  413. local FILE="$1"
  414. shift
  415. msgtest "Test for correctness of file" "$FILE"
  416. if [ -z "$*" ]; then
  417. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  418. else
  419. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  420. fi
  421. }
  422. testequal() {
  423. local COMPAREFILE=$(mktemp)
  424. echo "$1" > $COMPAREFILE
  425. shift
  426. msgtest "Test for equality of" "$*"
  427. $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  428. rm $COMPAREFILE
  429. }
  430. testequalor2() {
  431. local COMPAREFILE1=$(mktemp)
  432. local COMPAREFILE2=$(mktemp)
  433. local COMPAREAGAINST=$(mktemp)
  434. echo "$1" > $COMPAREFILE1
  435. echo "$2" > $COMPAREFILE2
  436. shift 2
  437. msgtest "Test for equality OR of" "$*"
  438. $* 2>&1 1> $COMPAREAGAINST
  439. (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
  440. checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
  441. ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
  442. "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
  443. msgfail )
  444. rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
  445. }
  446. testshowvirtual() {
  447. local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual"
  448. local PACKAGE="$1"
  449. shift
  450. while [ -n "$1" ]; do
  451. VIRTUAL="${VIRTUAL}
  452. N: Can't select versions from package '$1' as it purely virtual"
  453. PACKAGE="${PACKAGE} $1"
  454. shift
  455. done
  456. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  457. VIRTUAL="${VIRTUAL}
  458. N: No packages found"
  459. local COMPAREFILE=$(mktemp)
  460. local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
  461. eval `apt-config shell ARCH APT::Architecture`
  462. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  463. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  464. rm $COMPAREFILE
  465. }
  466. testnopackage() {
  467. msgtest "Test for non-existent packages" "apt-cache show $*"
  468. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  469. if [ -n "$SHOWPKG" ]; then
  470. echo
  471. echo "$SHOWPKG"
  472. msgfail
  473. return 1
  474. fi
  475. msgpass
  476. }
  477. testdpkginstalled() {
  478. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  479. local PKGS="$(dpkg -l $* | grep '^[a-z]' | grep '^[^i]' | wc -l)"
  480. if [ "$PKGS" != 0 ]; then
  481. echo $PKGS
  482. dpkg -l $* | grep '^[a-z]'
  483. msgfail
  484. return 1
  485. fi
  486. msgpass
  487. }
  488. testdpkgnoninstalled() {
  489. msgtest "Test for correctly non-installed package(s) with" "dpkg -l $*"
  490. local PKGS="$(dpkg -l $* | grep '^[a-z]' | grep '^[^u]' | wc -l)"
  491. if [ "$PKGS" != 0 ]; then
  492. echo
  493. dpkg -l $* | grep '^[a-z]'
  494. msgfail
  495. return 1
  496. fi
  497. msgpass
  498. }