framework 19 KB

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