framework 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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}/.. > /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. rm -rf "${BUILDDIR}"
  257. msgdone "info"
  258. }
  259. buildpackage() {
  260. local BUILDDIR=$1
  261. local RELEASE=$2
  262. local SECTION=$3
  263. msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
  264. cd $BUILDDIR
  265. if [ "$ARCH" = "all" ]; then
  266. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  267. fi
  268. local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
  269. local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
  270. local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
  271. cd - > /dev/null
  272. for PKG in $PKGS; do
  273. echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
  274. done
  275. for SRC in $SRCS; do
  276. echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
  277. done
  278. msgdone "info"
  279. }
  280. buildaptarchive() {
  281. if [ -d incoming ]; then
  282. buildaptarchivefromincoming $*
  283. else
  284. buildaptarchivefromfiles $*
  285. fi
  286. }
  287. createaptftparchiveconfig() {
  288. 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' ' ')"
  289. if [ -z "$ARCHS" ]; then
  290. # the pool is empty, so we will operate on faked packages - let us use the configured archs
  291. ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  292. fi
  293. echo -n 'Dir {
  294. ArchiveDir "' >> ftparchive.conf
  295. echo -n $(readlink -f .) >> ftparchive.conf
  296. echo -n '";
  297. CacheDir "' >> ftparchive.conf
  298. echo -n $(readlink -f ..) >> ftparchive.conf
  299. echo -n '";
  300. FileListDir "' >> ftparchive.conf
  301. echo -n $(readlink -f pool/) >> ftparchive.conf
  302. echo -n '";
  303. };
  304. Default {
  305. Packages::Compress ". gzip bzip2 lzma";
  306. Sources::Compress ". gzip bzip2 lzma";
  307. Contents::Compress ". gzip bzip2 lzma";
  308. Translation::Compress ". gzip bzip2 lzma";
  309. LongDescription "false";
  310. };
  311. TreeDefault {
  312. Directory "pool/";
  313. SrcDirectory "pool/";
  314. };
  315. APT {
  316. FTPArchive {
  317. Release {
  318. Origin "joesixpack";
  319. Label "apttestcases";
  320. Suite "unstable";
  321. Description "repository with dummy packages";
  322. Architectures "' >> ftparchive.conf
  323. echo -n "$ARCHS" >> ftparchive.conf
  324. echo 'source";
  325. };
  326. };
  327. };' >> ftparchive.conf
  328. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  329. echo -n 'tree "dists/' >> ftparchive.conf
  330. echo -n "$DIST" >> ftparchive.conf
  331. echo -n '" {
  332. Architectures "' >> ftparchive.conf
  333. echo -n "$ARCHS" >> ftparchive.conf
  334. echo -n 'source";
  335. FileList "' >> ftparchive.conf
  336. echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
  337. echo -n '";
  338. SourceFileList "' >> ftparchive.conf
  339. echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
  340. echo -n '";
  341. Sections "' >> ftparchive.conf
  342. 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
  343. echo '";
  344. };' >> ftparchive.conf
  345. done
  346. }
  347. buildaptftparchivedirectorystructure() {
  348. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  349. for DIST in $DISTS; do
  350. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  351. for SECTION in $SECTIONS; do
  352. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  353. for ARCH in $ARCHS; do
  354. mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
  355. done
  356. mkdir -p dists/${DIST}/${SECTION}/source
  357. mkdir -p dists/${DIST}/${SECTION}/i18n
  358. done
  359. done
  360. }
  361. insertpackage() {
  362. local RELEASE="$1"
  363. local NAME="$2"
  364. local ARCH="$3"
  365. local VERSION="$4"
  366. local DEPENDENCIES="$5"
  367. local ARCHS="$ARCH"
  368. if [ "$ARCHS" = "all" ]; then
  369. ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  370. fi
  371. for BUILDARCH in $ARCHS; do
  372. local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
  373. mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
  374. touch aptarchive/dists/${RELEASE}/main/source/Sources
  375. local FILE="${PPATH}/Packages"
  376. echo "Package: $NAME
  377. Priority: optional
  378. Section: other
  379. Installed-Size: 42
  380. Maintainer: Joe Sixpack <joe@example.org>
  381. Architecture: $ARCH
  382. Version: $VERSION
  383. Filename: pool/main/${NAME}/${NAME}_${VERSION}_${ARCH}.deb" >> $FILE
  384. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  385. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  386. If you find such a package installed on your system,
  387. YOU did something horribly wrong! They are autogenerated
  388. und used only by testcases for APT and surf no other propose…
  389. " >> $FILE
  390. done
  391. }
  392. buildaptarchivefromincoming() {
  393. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
  394. cd aptarchive
  395. [ -e pool ] || ln -s ../incoming pool
  396. [ -e ftparchive.conf ] || createaptftparchiveconfig
  397. [ -e dists ] || buildaptftparchivedirectorystructure
  398. msgninfo "\tGenerate Packages, Sources and Contents files… "
  399. aptftparchive -qq generate ftparchive.conf
  400. cd - > /dev/null
  401. msgdone "info"
  402. generatereleasefiles
  403. }
  404. buildaptarchivefromfiles() {
  405. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
  406. find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
  407. msgninfo "\t${line} file… "
  408. cat ${line} | gzip > ${line}.gz
  409. cat ${line} | bzip2 > ${line}.bz2
  410. cat ${line} | lzma > ${line}.lzma
  411. msgdone "info"
  412. done
  413. generatereleasefiles
  414. }
  415. generatereleasefiles() {
  416. msgninfo "\tGenerate Release files… "
  417. local DATE="${1:-now}"
  418. if [ -e aptarchive/dists ]; then
  419. for dir in $(find ./aptarchive/dists -mindepth 3 -maxdepth 3 -type d -name 'i18n'); do
  420. aptftparchive -qq release $dir -o APT::FTPArchive::Release::Patterns::='Translation-*' > $dir/Index
  421. done
  422. for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
  423. local CODENAME="$(echo "$dir" | cut -d'/' -f 4)"
  424. 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
  425. if [ "$CODENAME" = "experimental" -o "$CODENAME" = "experimental2" ]; then
  426. sed -i '/^Date: / a\
  427. NotAutomatic: yes' $dir/Release
  428. fi
  429. done
  430. else
  431. aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
  432. fi
  433. if [ "$DATE" != "now" ]; then
  434. for release in $(find ./aptarchive -name 'Release'); do
  435. touch -d "$1" $release
  436. done
  437. fi
  438. msgdone "info"
  439. }
  440. setupdistsaptarchive() {
  441. local APTARCHIVE=$(readlink -f ./aptarchive)
  442. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  443. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  444. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  445. SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  446. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  447. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
  448. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
  449. msgdone "info"
  450. done
  451. }
  452. setupflataptarchive() {
  453. local APTARCHIVE=$(readlink -f ./aptarchive)
  454. if [ -f ${APTARCHIVE}/Packages ]; then
  455. msgninfo "\tadd deb sources.list line… "
  456. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  457. msgdone "info"
  458. else
  459. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  460. fi
  461. if [ -f ${APTARCHIVE}/Sources ]; then
  462. msgninfo "\tadd deb-src sources.list line… "
  463. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  464. msgdone "info"
  465. else
  466. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  467. fi
  468. }
  469. setupaptarchive() {
  470. buildaptarchive
  471. if [ -e aptarchive/dists ]; then
  472. setupdistsaptarchive
  473. else
  474. setupflataptarchive
  475. fi
  476. signreleasefiles
  477. msgninfo "\tSync APT's cache with the archive… "
  478. aptget update -qq
  479. msgdone "info"
  480. }
  481. signreleasefiles() {
  482. local SIGNER="${1:-Joe Sixpack}"
  483. msgninfo "\tSign archive with $SIGNER key… "
  484. local SECKEYS=""
  485. for KEY in $(find keys/ -name '*.sec'); do
  486. SECKEYS="$SECKEYS --secret-keyring $KEY"
  487. done
  488. local PUBKEYS=""
  489. for KEY in $(find keys/ -name '*.pub'); do
  490. PUBKEYS="$PUBKEYS --keyring $KEY"
  491. done
  492. for RELEASE in $(find aptarchive/ -name Release); do
  493. gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
  494. gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
  495. done
  496. msgdone "info"
  497. }
  498. changetowebserver() {
  499. if which weborf > /dev/null; then
  500. weborf -xb aptarchive/ 2>&1 > /dev/null &
  501. addtrap "kill $!;"
  502. local APTARCHIVE="file://$(readlink -f ./aptarchive)"
  503. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  504. sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
  505. done
  506. return 0
  507. fi
  508. return 1
  509. }
  510. checkdiff() {
  511. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  512. if [ -n "$DIFFTEXT" ]; then
  513. echo
  514. echo "$DIFFTEXT"
  515. return 1
  516. else
  517. return 0
  518. fi
  519. }
  520. testfileequal() {
  521. local FILE="$1"
  522. shift
  523. msgtest "Test for correctness of file" "$FILE"
  524. if [ -z "$*" ]; then
  525. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  526. else
  527. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  528. fi
  529. }
  530. testequal() {
  531. local COMPAREFILE=$(mktemp)
  532. addtrap "rm $COMPAREFILE;"
  533. echo "$1" > $COMPAREFILE
  534. shift
  535. msgtest "Test for equality of" "$*"
  536. $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  537. }
  538. testequalor2() {
  539. local COMPAREFILE1=$(mktemp)
  540. local COMPAREFILE2=$(mktemp)
  541. local COMPAREAGAINST=$(mktemp)
  542. addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
  543. echo "$1" > $COMPAREFILE1
  544. echo "$2" > $COMPAREFILE2
  545. shift 2
  546. msgtest "Test for equality OR of" "$*"
  547. $* 2>&1 1> $COMPAREAGAINST
  548. (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
  549. checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
  550. ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
  551. "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
  552. msgfail )
  553. }
  554. testshowvirtual() {
  555. local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual"
  556. local PACKAGE="$1"
  557. shift
  558. while [ -n "$1" ]; do
  559. VIRTUAL="${VIRTUAL}
  560. N: Can't select versions from package '$1' as it purely virtual"
  561. PACKAGE="${PACKAGE} $1"
  562. shift
  563. done
  564. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  565. VIRTUAL="${VIRTUAL}
  566. N: No packages found"
  567. local COMPAREFILE=$(mktemp)
  568. addtrap "rm $COMPAREFILE;"
  569. local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
  570. eval `apt-config shell ARCH APT::Architecture`
  571. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  572. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  573. }
  574. testnopackage() {
  575. msgtest "Test for non-existent packages" "apt-cache show $*"
  576. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  577. if [ -n "$SHOWPKG" ]; then
  578. echo
  579. echo "$SHOWPKG"
  580. msgfail
  581. return 1
  582. fi
  583. msgpass
  584. }
  585. testdpkginstalled() {
  586. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  587. local PKGS="$(dpkg -l $* | grep '^[a-z]' | grep '^[^i]' | wc -l)"
  588. if [ "$PKGS" != 0 ]; then
  589. echo $PKGS
  590. dpkg -l $* | grep '^[a-z]'
  591. msgfail
  592. return 1
  593. fi
  594. msgpass
  595. }
  596. testdpkgnoninstalled() {
  597. msgtest "Test for correctly non-installed package(s) with" "dpkg -l $*"
  598. local PKGS="$(dpkg -l $* | grep '^[a-z]' | grep '^[^u]' | wc -l)"
  599. if [ "$PKGS" != 0 ]; then
  600. echo
  601. dpkg -l $* | grep '^[a-z]'
  602. msgfail
  603. return 1
  604. fi
  605. msgpass
  606. }