framework 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. #!/bin/sh -- # no runable script, just for vi
  2. # we all like colorful messages
  3. if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null && \
  4. expr match "$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev/null; then
  5. CERROR="" # red
  6. CWARNING="" # yellow
  7. CMSG="" # green
  8. CINFO="" # light blue
  9. CDEBUG="" # blue
  10. CNORMAL="" # default system console color
  11. CDONE="" # green
  12. CPASS="" # green
  13. CFAIL="" # red
  14. CCMD="" # pink
  15. fi
  16. msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
  17. msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
  18. msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
  19. msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
  20. msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
  21. msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
  22. msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
  23. msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
  24. msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
  25. msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
  26. msgtest() {
  27. while [ -n "$1" ]; do
  28. echo -n "${CINFO}$1${CCMD} " >&2;
  29. echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2;
  30. shift
  31. if [ -n "$1" ]; then shift; else break; fi
  32. done
  33. echo -n "…${CNORMAL} " >&2;
  34. }
  35. msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
  36. msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
  37. msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
  38. # enable / disable Debugging
  39. MSGLEVEL=${MSGLEVEL:-3}
  40. if [ $MSGLEVEL -le 0 ]; then
  41. msgdie() { true; }
  42. fi
  43. if [ $MSGLEVEL -le 1 ]; then
  44. msgwarn() { true; }
  45. msgnwarn() { true; }
  46. fi
  47. if [ $MSGLEVEL -le 2 ]; then
  48. msgmsg() { true; }
  49. msgnmsg() { true; }
  50. msgtest() { true; }
  51. msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
  52. msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
  53. if [ -n "$CFAIL" ]; then
  54. msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; }
  55. else
  56. msgfail() { echo -n " ###FAILED###" >&2; }
  57. fi
  58. fi
  59. if [ $MSGLEVEL -le 3 ]; then
  60. msginfo() { true; }
  61. msgninfo() { true; }
  62. fi
  63. if [ $MSGLEVEL -le 4 ]; then
  64. msgdebug() { true; }
  65. msgndebug() { true; }
  66. fi
  67. msgdone() {
  68. if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
  69. [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
  70. [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
  71. [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
  72. [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
  73. true;
  74. else
  75. echo "${CDONE}DONE${CNORMAL}" >&2;
  76. fi
  77. }
  78. runapt() {
  79. msgdebug "Executing: ${CCMD}$*${CDEBUG} "
  80. if [ -f ./aptconfig.conf ]; then
  81. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  82. elif [ -f ../aptconfig.conf ]; then
  83. APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  84. else
  85. LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
  86. fi
  87. }
  88. aptconfig() { runapt apt-config $*; }
  89. aptcache() { runapt apt-cache $*; }
  90. aptcdrom() { runapt apt-cdrom $*; }
  91. aptget() { runapt apt-get $*; }
  92. aptftparchive() { runapt apt-ftparchive $*; }
  93. aptkey() { runapt apt-key $*; }
  94. aptmark() { runapt apt-mark $*; }
  95. dpkg() {
  96. $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
  97. }
  98. aptitude() {
  99. if [ -f ./aptconfig.conf ]; then
  100. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  101. elif [ -f ../aptconfig.conf ]; then
  102. APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  103. else
  104. LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
  105. fi
  106. }
  107. gdb() {
  108. echo "gdb: run »$*«"
  109. APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1
  110. }
  111. addtrap() {
  112. CURRENTTRAP="$CURRENTTRAP $1"
  113. trap "$CURRENTTRAP exit;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
  114. }
  115. setupenvironment() {
  116. TMPWORKINGDIRECTORY=$(mktemp -d)
  117. TESTDIRECTORY=$(readlink -f $(dirname $0))
  118. msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
  119. BUILDDIRECTORY="${TESTDIRECTORY}/../../build/bin"
  120. test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
  121. local OLDWORKINGDIRECTORY=$(pwd)
  122. addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;"
  123. cd $TMPWORKINGDIRECTORY
  124. mkdir rootdir aptarchive keys
  125. cd rootdir
  126. mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
  127. mkdir -p var/cache var/lib var/log
  128. mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
  129. touch var/lib/dpkg/available
  130. mkdir -p usr/lib/apt
  131. ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
  132. cd ..
  133. local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
  134. if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
  135. cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
  136. fi
  137. local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
  138. if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
  139. cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
  140. fi
  141. cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
  142. ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
  143. echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
  144. echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
  145. echo "Debug::NoLocking \"true\";" >> aptconfig.conf
  146. echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
  147. echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
  148. echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
  149. echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
  150. echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
  151. echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
  152. echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
  153. if ! $(which dpkg) --assert-multi-arch 2>&1 > /dev/null; then
  154. echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
  155. fi
  156. echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
  157. echo 'quiet::NoUpdate "true";' >> aptconfig.conf
  158. export LC_ALL=C
  159. export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
  160. msgdone "info"
  161. }
  162. getarchitecture() {
  163. if [ "$1" = "native" -o -z "$1" ]; then
  164. eval `aptconfig shell ARCH APT::Architecture`
  165. if [ -n "$ARCH" ]; then
  166. echo $ARCH
  167. else
  168. dpkg --print-architecture
  169. fi
  170. else
  171. echo $1
  172. fi
  173. }
  174. getarchitectures() {
  175. echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
  176. }
  177. configarchitecture() {
  178. local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
  179. rm -f $CONFFILE
  180. echo "APT::Architecture \"$(getarchitecture $1)\";" > $CONFFILE
  181. shift
  182. while [ -n "$1" ]; do
  183. echo "APT::Architectures:: \"$(getarchitecture $1)\";" >> $CONFFILE
  184. shift
  185. done
  186. configdpkg
  187. }
  188. configdpkg() {
  189. if [ ! -e rootdir/var/lib/dpkg/status ]; then
  190. local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
  191. if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
  192. cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
  193. else
  194. echo -n > rootdir/var/lib/dpkg/status
  195. fi
  196. fi
  197. if $(which dpkg) --assert-multi-arch 2>&1 > /dev/null; then
  198. local ARCHS="$(getarchitectures)"
  199. if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
  200. DPKGARCH="$(dpkg --print-architecture)"
  201. for ARCH in ${ARCHS}; do
  202. if [ "${ARCH}" != "${DPKGARCH}" ]; then dpkg --add-architecture ${ARCH}; fi
  203. done
  204. if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
  205. # dpkg doesn't really check the version as long as it is fully installed,
  206. # but just to be sure we choose one above the required version
  207. insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
  208. fi
  209. fi
  210. fi
  211. }
  212. setupsimplenativepackage() {
  213. local NAME="$1"
  214. local ARCH="$2"
  215. local VERSION="$3"
  216. local RELEASE="${4:-unstable}"
  217. local DEPENDENCIES="$5"
  218. local DESCRIPTION="$6"
  219. local SECTION="${7:-others}"
  220. local DISTSECTION
  221. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  222. DISTSECTION="main"
  223. else
  224. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  225. fi
  226. local BUILDDIR=incoming/${NAME}-${VERSION}
  227. mkdir -p ${BUILDDIR}/debian/source
  228. cd ${BUILDDIR}
  229. echo "* most suckless software product ever" > FEATURES
  230. test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
  231. test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
  232. * Initial release
  233. -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
  234. test -e debian/control || echo "Source: $NAME
  235. Section: $SECTION
  236. Priority: optional
  237. Maintainer: Joe Sixpack <joe@example.org>
  238. Build-Depends: debhelper (>= 7)
  239. Standards-Version: 3.9.1
  240. Package: $NAME" > debian/control
  241. if [ "$ARCH" = 'all' ]; then
  242. echo "Architecture: all" >> debian/control
  243. else
  244. echo "Architecture: any" >> debian/control
  245. fi
  246. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
  247. if [ -z "$DESCRIPTION" ]; then
  248. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  249. If you find such a package installed on your system,
  250. YOU did something horribly wrong! They are autogenerated
  251. und used only by testcases for APT and surf no other propose…" >> debian/control
  252. else
  253. echo "Description: $DESCRIPTION" >> debian/control
  254. fi
  255. test -e debian/compat || echo "7" > debian/compat
  256. test -e debian/source/format || echo "3.0 (native)" > debian/source/format
  257. test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
  258. cd - > /dev/null
  259. }
  260. buildsimplenativepackage() {
  261. local NAME="$1"
  262. local ARCH="$2"
  263. local VERSION="$3"
  264. local RELEASE="${4:-unstable}"
  265. local DEPENDENCIES="$5"
  266. local DESCRIPTION="$6"
  267. local SECTION="${7:-others}"
  268. local PRIORITY="${8:-optional}"
  269. local DISTSECTION
  270. if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
  271. DISTSECTION="main"
  272. else
  273. DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
  274. fi
  275. local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
  276. msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
  277. mkdir -p $BUILDDIR/debian/source
  278. echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
  279. echo "#!/bin/sh
  280. echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
  281. echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
  282. echo "$NAME ($VERSION) $RELEASE; urgency=low
  283. * Initial release
  284. -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
  285. echo "Source: $NAME
  286. Section: $SECTION
  287. Priority: $PRIORITY
  288. Maintainer: Joe Sixpack <joe@example.org>
  289. Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
  290. local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
  291. test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
  292. echo "
  293. Package: $NAME" >> ${BUILDDIR}/debian/control
  294. if [ "$ARCH" = 'all' ]; then
  295. echo "Architecture: all" >> ${BUILDDIR}/debian/control
  296. else
  297. echo "Architecture: any" >> ${BUILDDIR}/debian/control
  298. fi
  299. local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
  300. test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
  301. if [ -z "$DESCRIPTION" ]; then
  302. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  303. If you find such a package installed on your system,
  304. YOU did something horribly wrong! They are autogenerated
  305. und used only by testcases for APT and surf no other propose…" >> ${BUILDDIR}/debian/control
  306. else
  307. echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
  308. fi
  309. echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
  310. local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
  311. for SRC in $SRCS; do
  312. echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
  313. done
  314. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  315. rm -rf ${BUILDDIR}/debian/tmp
  316. mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
  317. cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
  318. cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
  319. (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
  320. (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
  321. dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null
  322. echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
  323. done
  324. mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
  325. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
  326. cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
  327. rm -rf "${BUILDDIR}"
  328. msgdone "info"
  329. }
  330. buildpackage() {
  331. local BUILDDIR=$1
  332. local RELEASE=$2
  333. local SECTION=$3
  334. local ARCH=$(getarchitecture $4)
  335. msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
  336. cd $BUILDDIR
  337. if [ "$ARCH" = "all" ]; then
  338. ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
  339. fi
  340. local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
  341. local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
  342. local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
  343. cd - > /dev/null
  344. for PKG in $PKGS; do
  345. echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
  346. done
  347. for SRC in $SRCS; do
  348. echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
  349. done
  350. msgdone "info"
  351. }
  352. buildaptarchive() {
  353. if [ -d incoming ]; then
  354. buildaptarchivefromincoming $*
  355. else
  356. buildaptarchivefromfiles $*
  357. fi
  358. }
  359. createaptftparchiveconfig() {
  360. 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' ' ')"
  361. if [ -z "$ARCHS" ]; then
  362. # the pool is empty, so we will operate on faked packages - let us use the configured archs
  363. ARCHS="$(getarchitectures)"
  364. fi
  365. echo -n 'Dir {
  366. ArchiveDir "' >> ftparchive.conf
  367. echo -n $(readlink -f .) >> ftparchive.conf
  368. echo -n '";
  369. CacheDir "' >> ftparchive.conf
  370. echo -n $(readlink -f ..) >> ftparchive.conf
  371. echo -n '";
  372. FileListDir "' >> ftparchive.conf
  373. echo -n $(readlink -f pool/) >> ftparchive.conf
  374. echo -n '";
  375. };
  376. Default {
  377. Packages::Compress ". gzip bzip2 lzma xz";
  378. Sources::Compress ". gzip bzip2 lzma xz";
  379. Contents::Compress ". gzip bzip2 lzma xz";
  380. Translation::Compress ". gzip bzip2 lzma xz";
  381. LongDescription "false";
  382. };
  383. TreeDefault {
  384. Directory "pool/";
  385. SrcDirectory "pool/";
  386. };
  387. APT {
  388. FTPArchive {
  389. Release {
  390. Origin "joesixpack";
  391. Label "apttestcases";
  392. Suite "unstable";
  393. Description "repository with dummy packages";
  394. Architectures "' >> ftparchive.conf
  395. echo -n "$ARCHS" >> ftparchive.conf
  396. echo 'source";
  397. };
  398. };
  399. };' >> ftparchive.conf
  400. for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
  401. echo -n 'tree "dists/' >> ftparchive.conf
  402. echo -n "$DIST" >> ftparchive.conf
  403. echo -n '" {
  404. Architectures "' >> ftparchive.conf
  405. echo -n "$ARCHS" >> ftparchive.conf
  406. echo -n 'source";
  407. FileList "' >> ftparchive.conf
  408. echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
  409. echo -n '";
  410. SourceFileList "' >> ftparchive.conf
  411. echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
  412. echo -n '";
  413. Sections "' >> ftparchive.conf
  414. 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
  415. echo '";
  416. };' >> ftparchive.conf
  417. done
  418. }
  419. buildaptftparchivedirectorystructure() {
  420. local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
  421. for DIST in $DISTS; do
  422. local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
  423. for SECTION in $SECTIONS; do
  424. local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
  425. for ARCH in $ARCHS; do
  426. mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
  427. done
  428. mkdir -p dists/${DIST}/${SECTION}/source
  429. mkdir -p dists/${DIST}/${SECTION}/i18n
  430. done
  431. done
  432. }
  433. insertpackage() {
  434. local RELEASE="$1"
  435. local NAME="$2"
  436. local ARCH="$3"
  437. local VERSION="$4"
  438. local DEPENDENCIES="$5"
  439. local PRIORITY="${6:-optional}"
  440. local ARCHS=""
  441. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  442. if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
  443. ARCHS="$(getarchitectures)"
  444. else
  445. ARCHS="$arch"
  446. fi
  447. for BUILDARCH in $ARCHS; do
  448. local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
  449. mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
  450. touch aptarchive/dists/${RELEASE}/main/source/Sources
  451. local FILE="${PPATH}/Packages"
  452. echo "Package: $NAME
  453. Priority: $PRIORITY
  454. Section: other
  455. Installed-Size: 42
  456. Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
  457. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  458. echo "Version: $VERSION
  459. Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
  460. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  461. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  462. If you find such a package installed on your system,
  463. YOU did something horribly wrong! They are autogenerated
  464. und used only by testcases for APT and surf no other propose…
  465. " >> $FILE
  466. done
  467. done
  468. }
  469. insertsource() {
  470. local RELEASE="$1"
  471. local NAME="$2"
  472. local ARCH="$3"
  473. local VERSION="$4"
  474. local DEPENDENCIES="$5"
  475. local ARCHS=""
  476. local SPATH="aptarchive/dists/${RELEASE}/main/source"
  477. mkdir -p $SPATH
  478. local FILE="${SPATH}/Sources"
  479. echo "Package: $NAME
  480. Binary: $NAME
  481. Version: $VERSION
  482. Maintainer: Joe Sixpack <joe@example.org>
  483. Architecture: $ARCH" >> $FILE
  484. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  485. echo "Files:
  486. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
  487. d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
  488. " >> $FILE
  489. }
  490. insertinstalledpackage() {
  491. local NAME="$1"
  492. local ARCH="$2"
  493. local VERSION="$3"
  494. local DEPENDENCIES="$4"
  495. local PRIORITY="${5:-optional}"
  496. local STATUS="${6:-install ok installed}"
  497. local FILE='rootdir/var/lib/dpkg/status'
  498. local INFO='rootdir/var/lib/dpkg/info'
  499. for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
  500. echo "Package: $NAME
  501. Status: $STATUS
  502. Priority: $PRIORITY
  503. Section: other
  504. Installed-Size: 42
  505. Maintainer: Joe Sixpack <joe@example.org>
  506. Version: $VERSION" >> $FILE
  507. test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
  508. test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
  509. echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed
  510. If you find such a package installed on your system,
  511. YOU did something horribly wrong! They are autogenerated
  512. und used only by testcases for APT and surf no other propose…
  513. " >> $FILE
  514. if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
  515. echo -n > ${INFO}/${NAME}:${arch}.list
  516. else
  517. echo -n > ${INFO}/${NAME}.list
  518. fi
  519. done
  520. }
  521. buildaptarchivefromincoming() {
  522. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
  523. cd aptarchive
  524. [ -e pool ] || ln -s ../incoming pool
  525. [ -e ftparchive.conf ] || createaptftparchiveconfig
  526. [ -e dists ] || buildaptftparchivedirectorystructure
  527. msgninfo "\tGenerate Packages, Sources and Contents files… "
  528. aptftparchive -qq generate ftparchive.conf
  529. cd - > /dev/null
  530. msgdone "info"
  531. generatereleasefiles
  532. }
  533. buildaptarchivefromfiles() {
  534. msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
  535. find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
  536. msgninfo "\t${line} file… "
  537. cat ${line} | gzip > ${line}.gz
  538. cat ${line} | bzip2 > ${line}.bz2
  539. cat ${line} | xz --format=lzma > ${line}.lzma
  540. cat ${line} | xz > ${line}.xz
  541. msgdone "info"
  542. done
  543. generatereleasefiles
  544. }
  545. # can be overridden by testcases for their pleasure
  546. getcodenamefromsuite() { echo -n "$1"; }
  547. getreleaseversionfromsuite() { true; }
  548. getlabelfromsuite() { true; }
  549. generatereleasefiles() {
  550. # $1 is the Date header and $2 is the ValidUntil header to be set
  551. # both should be given in notation date/touch can understand
  552. msgninfo "\tGenerate Release files… "
  553. if [ -e aptarchive/dists ]; then
  554. for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
  555. local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
  556. local CODENAME="$(getcodenamefromsuite $SUITE)"
  557. local VERSION="$(getreleaseversionfromsuite $SUITE)"
  558. local LABEL="$(getlabelfromsuite $SUITE)"
  559. if [ -n "$VERSION" ]; then
  560. VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
  561. fi
  562. if [ -n "$LABEL" ]; then
  563. LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
  564. fi
  565. aptftparchive -qq release $dir \
  566. -o APT::FTPArchive::Release::Suite="${SUITE}" \
  567. -o APT::FTPArchive::Release::Codename="${CODENAME}" \
  568. ${LABEL} \
  569. ${VERSION} \
  570. | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
  571. if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
  572. sed -i '/^Date: / a\
  573. NotAutomatic: yes' $dir/Release
  574. fi
  575. if [ -n "$1" -a "$1" != "now" ]; then
  576. sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
  577. fi
  578. if [ -n "$2" ]; then
  579. sed -i "/^Date: / a\
  580. Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
  581. fi
  582. done
  583. else
  584. aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
  585. fi
  586. if [ -n "$1" -a "$1" != "now" ]; then
  587. for release in $(find ./aptarchive -name 'Release'); do
  588. touch -d "$1" $release
  589. done
  590. fi
  591. msgdone "info"
  592. }
  593. setupdistsaptarchive() {
  594. local APTARCHIVE=$(readlink -f ./aptarchive)
  595. rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
  596. rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
  597. for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
  598. SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
  599. msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
  600. echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
  601. echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
  602. msgdone "info"
  603. done
  604. }
  605. setupflataptarchive() {
  606. local APTARCHIVE=$(readlink -f ./aptarchive)
  607. if [ -f ${APTARCHIVE}/Packages ]; then
  608. msgninfo "\tadd deb sources.list line… "
  609. echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  610. msgdone "info"
  611. else
  612. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
  613. fi
  614. if [ -f ${APTARCHIVE}/Sources ]; then
  615. msgninfo "\tadd deb-src sources.list line… "
  616. echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  617. msgdone "info"
  618. else
  619. rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
  620. fi
  621. }
  622. setupaptarchive() {
  623. buildaptarchive
  624. if [ -e aptarchive/dists ]; then
  625. setupdistsaptarchive
  626. else
  627. setupflataptarchive
  628. fi
  629. signreleasefiles
  630. msgninfo "\tSync APT's cache with the archive… "
  631. aptget update -qq
  632. msgdone "info"
  633. }
  634. signreleasefiles() {
  635. local SIGNER="${1:-Joe Sixpack}"
  636. msgninfo "\tSign archive with $SIGNER key… "
  637. local SECKEYS=""
  638. for KEY in $(find keys/ -name '*.sec'); do
  639. SECKEYS="$SECKEYS --secret-keyring $KEY"
  640. done
  641. local PUBKEYS=""
  642. for KEY in $(find keys/ -name '*.pub'); do
  643. PUBKEYS="$PUBKEYS --keyring $KEY"
  644. done
  645. for RELEASE in $(find aptarchive/ -name Release); do
  646. gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
  647. gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
  648. done
  649. msgdone "info"
  650. }
  651. changetowebserver() {
  652. if which weborf > /dev/null; then
  653. weborf -xb aptarchive/ 2>&1 > /dev/null &
  654. addtrap "kill $!;"
  655. elif which gatling > /dev/null; then
  656. cd aptarchive
  657. gatling -p 8080 -F -S 2>&1 > /dev/null &
  658. addtrap "kill $!;"
  659. cd - > /dev/null
  660. elif which lighttpd > /dev/null; then
  661. echo "server.document-root = \"$(readlink -f ./aptarchive)\"
  662. server.port = 8080
  663. server.stat-cache-engine = \"disable\"" > lighttpd.conf
  664. lighttpd -t -f lighttpd.conf >/dev/null || msgdie 'Can not change to webserver: our lighttpd config is invalid'
  665. lighttpd -D -f lighttpd.conf 2>/dev/null >/dev/null &
  666. addtrap "kill $!;"
  667. else
  668. msgdie 'You have to install weborf or lighttpd first'
  669. return 1
  670. fi
  671. local APTARCHIVE="file://$(readlink -f ./aptarchive)"
  672. for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
  673. sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
  674. done
  675. return 0
  676. }
  677. changetocdrom() {
  678. mkdir -p rootdir/media/cdrom/.disk
  679. local CD="$(readlink -f rootdir/media/cdrom)"
  680. echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
  681. echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
  682. echo -n "$1" > ${CD}/.disk/info
  683. if [ ! -d aptarchive/dists ]; then
  684. msgdie 'Flat file archive cdroms can not be created currently'
  685. return 1
  686. fi
  687. mv aptarchive/dists $CD
  688. ln -s "$(readlink -f ./incoming)" $CD/pool
  689. find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
  690. }
  691. checkdiff() {
  692. local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
  693. if [ -n "$DIFFTEXT" ]; then
  694. echo
  695. echo "$DIFFTEXT"
  696. return 1
  697. else
  698. return 0
  699. fi
  700. }
  701. testfileequal() {
  702. local FILE="$1"
  703. shift
  704. msgtest "Test for correctness of file" "$FILE"
  705. if [ -z "$*" ]; then
  706. echo -n "" | checkdiff $FILE - && msgpass || msgfail
  707. else
  708. echo "$*" | checkdiff $FILE - && msgpass || msgfail
  709. fi
  710. }
  711. testempty() {
  712. msgtest "Test for no output of" "$*"
  713. test -z "$($* 2>&1)" && msgpass || msgfail
  714. }
  715. testequal() {
  716. local COMPAREFILE=$(mktemp)
  717. addtrap "rm $COMPAREFILE;"
  718. echo "$1" > $COMPAREFILE
  719. shift
  720. msgtest "Test for equality of" "$*"
  721. $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  722. }
  723. testequalor2() {
  724. local COMPAREFILE1=$(mktemp)
  725. local COMPAREFILE2=$(mktemp)
  726. local COMPAREAGAINST=$(mktemp)
  727. addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
  728. echo "$1" > $COMPAREFILE1
  729. echo "$2" > $COMPAREFILE2
  730. shift 2
  731. msgtest "Test for equality OR of" "$*"
  732. $* 2>&1 1> $COMPAREAGAINST
  733. (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
  734. checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
  735. ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
  736. "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
  737. msgfail )
  738. }
  739. testshowvirtual() {
  740. local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
  741. local PACKAGE="$1"
  742. shift
  743. while [ -n "$1" ]; do
  744. VIRTUAL="${VIRTUAL}
  745. N: Can't select versions from package '$1' as it is purely virtual"
  746. PACKAGE="${PACKAGE} $1"
  747. shift
  748. done
  749. msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
  750. VIRTUAL="${VIRTUAL}
  751. N: No packages found"
  752. local COMPAREFILE=$(mktemp)
  753. addtrap "rm $COMPAREFILE;"
  754. local ARCH="$(getarchitecture 'native')"
  755. echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
  756. aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  757. }
  758. testnopackage() {
  759. msgtest "Test for non-existent packages" "apt-cache show $*"
  760. local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
  761. if [ -n "$SHOWPKG" ]; then
  762. echo
  763. echo "$SHOWPKG"
  764. msgfail
  765. return 1
  766. fi
  767. msgpass
  768. }
  769. testdpkginstalled() {
  770. msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
  771. local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
  772. if [ "$PKGS" != $# ]; then
  773. echo $PKGS
  774. dpkg -l $* | grep '^[a-z]'
  775. msgfail
  776. return 1
  777. fi
  778. msgpass
  779. }
  780. testdpkgnotinstalled() {
  781. msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
  782. local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
  783. if [ "$PKGS" != 0 ]; then
  784. echo
  785. dpkg -l $* | grep '^[a-z]'
  786. msgfail
  787. return 1
  788. fi
  789. msgpass
  790. }
  791. testmarkedauto() {
  792. local COMPAREFILE=$(mktemp)
  793. addtrap "rm $COMPAREFILE;"
  794. if [ -n "$1" ]; then
  795. msgtest 'Test for correctly marked as auto-installed' "$*"
  796. while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
  797. else
  798. msgtest 'Test for correctly marked as auto-installed' 'no package'
  799. echo -n > $COMPAREFILE
  800. fi
  801. aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
  802. }
  803. pause() {
  804. echo "STOPPED execution. Press enter to continue"
  805. local IGNORE
  806. read IGNORE
  807. }