framework 21 KB

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