framework 22 KB

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