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.
 
 
 
 
 
 

502 lines
16 KiB

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