framework 19 KB

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