framework 22 KB

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