framework 27 KB

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