framework 19 KB

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