framework 18 KB

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