util.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. #!/bin/bash
  2. ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
  3. ##### Author: Travis Cross <tc@traviscross.com>
  4. set -e
  5. ddir="."
  6. [ -n "${0%/*}" ] && ddir="${0%/*}"
  7. cd $ddir/../
  8. #### lib
  9. err () {
  10. echo "$0 error: $1" >&2
  11. exit 1
  12. }
  13. announce () {
  14. cat >&2 <<EOF
  15. ########################################################################
  16. ## $1
  17. ########################################################################
  18. EOF
  19. }
  20. xread () {
  21. local xIFS="$IFS"
  22. IFS=''
  23. read $@
  24. local ret=$?
  25. IFS="$xIFS"
  26. return $ret
  27. }
  28. mk_dver () { echo "$1" | sed -e 's/-/~/g'; }
  29. mk_uver () { echo "$1" | sed -e 's/-.*$//' -e 's/~/-/'; }
  30. dsc_source () { dpkg-parsechangelog | grep '^Source:' | awk '{print $2}'; }
  31. dsc_ver () { dpkg-parsechangelog | grep '^Version:' | awk '{print $2}'; }
  32. up_ver () { mk_uver "$(dsc_ver)"; }
  33. dsc_base () { echo "$(dsc_source)_$(dsc_ver)"; }
  34. up_base () { echo "$(dsc_source)-$(up_ver)"; }
  35. find_distro () {
  36. case "$1" in
  37. experimental) echo "sid";;
  38. unstable) echo "sid";;
  39. testing) echo "bullseye";;
  40. stable) echo "buster";;
  41. oldstable) echo "stretch";;
  42. *) echo "$1";;
  43. esac
  44. }
  45. find_suite () {
  46. case "$1" in
  47. sid) echo "unstable";;
  48. bullseye) echo "testing";;
  49. buster) echo "stable";;
  50. stretch) echo "oldstable";;
  51. *) echo "$1";;
  52. esac
  53. }
  54. #### debian/rules helpers
  55. create_dbg_pkgs () {
  56. for x in $ddir/*; do
  57. test ! -d $x && continue
  58. test "$x" = "tmp" -o "$x" = "source" && continue
  59. test ! "$x" = "${x%-dbg}" && continue
  60. test ! -d $x/usr/lib/debug && continue
  61. mkdir -p $x-dbg/usr/lib
  62. mv $x/usr/lib/debug $x-dbg/usr/lib/
  63. done
  64. }
  65. cwget () {
  66. local url="$1" f="${1##*/}"
  67. echo "fetching: $url to $f" >&2
  68. if [ -n "$FS_FILES_DIR" ]; then
  69. if ! [ -s "$FS_FILES_DIR/$f" ]; then
  70. (cd $FS_FILES_DIR && wget -N "$url")
  71. fi
  72. cp -a $FS_FILES_DIR/$f .
  73. else
  74. wget -N "$url"
  75. fi
  76. }
  77. getlib () {
  78. local url="$1" f="${1##*/}"
  79. cwget "$url"
  80. tar -xv --no-same-owner --no-same-permissions -f "$f"
  81. rm -f "$f" && mkdir -p $f && touch $f/.download-stamp
  82. }
  83. getlibs () {
  84. # get pinned libraries
  85. getlib http://files.freeswitch.org/downloads/libs/sphinxbase-0.8.tar.gz
  86. getlib http://files.freeswitch.org/downloads/libs/pocketsphinx-0.8.tar.gz
  87. getlib http://files.freeswitch.org/downloads/libs/communicator_semi_6000_20080321.tar.gz
  88. #getlib http://download.zeromq.org/zeromq-2.1.9.tar.gz \
  89. # || getlib http://download.zeromq.org/historic/zeromq-2.1.9.tar.gz
  90. getlib http://files.freeswitch.org/downloads/libs/freeradius-client-1.1.7.tar.gz
  91. #getlib http://files.freeswitch.org/downloads/libs/v8-3.24.14.tar.bz2
  92. }
  93. check_repo_clean () {
  94. git diff-index --quiet --cached HEAD \
  95. || err "uncommitted changes present"
  96. git diff-files --quiet \
  97. || err "unclean working tree"
  98. git diff-index --quiet HEAD \
  99. || err "unclean repository"
  100. ! git ls-files --other --error-unmatch . >/dev/null 2>&1 \
  101. || err "untracked files or build products present"
  102. }
  103. get_last_release_ver () {
  104. grep -m1 -e '^AC_INIT' configure.ac \
  105. | cut -d, -f2 \
  106. | sed -e 's/\[//' -e 's/\]//' -e 's/ //g'
  107. }
  108. get_nightly_version () {
  109. local commit="$(git rev-list -n1 --abbrev=10 --abbrev-commit HEAD)"
  110. echo "$(get_last_release_ver)+git~$(date -u '+%Y%m%dT%H%M%SZ')~$commit"
  111. }
  112. get_nightly_revision_human () {
  113. echo "git $(git rev-list -n1 --abbrev=7 --abbrev-commit HEAD) $(date -u '+%Y-%m-%d %H:%M:%SZ')"
  114. }
  115. create_orig () {
  116. {
  117. set -e
  118. local OPTIND OPTARG
  119. local uver="" hrev="" bundle_deps=true modules_list="" zl=9e
  120. while getopts 'bm:nv:z:' o "$@"; do
  121. case "$o" in
  122. m) modules_list="$OPTARG";;
  123. n) uver="nightly";;
  124. v) uver="$OPTARG";;
  125. z) zl="$OPTARG";;
  126. esac
  127. done
  128. shift $(($OPTIND-1))
  129. if [ -z "$uver" ] || [ "$uver" = "nightly" ]; then
  130. uver="$(get_nightly_version)"
  131. hrev="$(get_nightly_revision_human)"
  132. fi
  133. local treeish="$1" dver="$(mk_dver "$uver")"
  134. local orig="../freeswitch_$dver~$(lsb_release -sc).orig.tar.xz"
  135. [ -n "$treeish" ] || treeish="HEAD"
  136. check_repo_clean
  137. git reset --hard "$treeish"
  138. mv .gitattributes .gitattributes.orig
  139. local -a args=(-e '\bdebian-ignore\b')
  140. test "$modules_list" = "non-dfsg" || args+=(-e '\bdfsg-nonfree\b')
  141. grep .gitattributes.orig "${args[@]}" \
  142. | while xread l; do
  143. echo "$l export-ignore" >> .gitattributes
  144. done
  145. if $bundle_deps; then
  146. (cd libs && getlibs)
  147. git add -f libs
  148. fi
  149. ./build/set-fs-version.sh "$uver" "$hrev" && git add configure.ac
  150. echo "$uver" > .version && git add -f .version
  151. git commit --allow-empty -m "nightly v$uver"
  152. git archive -v \
  153. --worktree-attributes \
  154. --format=tar \
  155. --prefix=freeswitch-$uver/ \
  156. HEAD \
  157. | xz -c -${zl}v > $orig
  158. mv .gitattributes.orig .gitattributes
  159. git reset --hard HEAD^ && git clean -fdx
  160. } 1>&2
  161. echo $orig
  162. }
  163. set_modules_quicktest () {
  164. cat > debian/modules.conf <<EOF
  165. applications/mod_commands
  166. EOF
  167. }
  168. create_dsc () {
  169. {
  170. set -e
  171. local OPTIND OPTARG modules_conf="" modules_list="" speed="normal" suite_postfix="" suite_postfix_p=false zl=9
  172. local modules_add=""
  173. while getopts 'a:f:m:p:s:u:z:' o "$@"; do
  174. case "$o" in
  175. a) avoid_mods_arch="$OPTARG";;
  176. f) modules_conf="$OPTARG";;
  177. m) modules_list="$OPTARG";;
  178. p) modules_add="$modules_add $OPTARG";;
  179. s) speed="$OPTARG";;
  180. u) suite_postfix="$OPTARG"; suite_postfix_p=true;;
  181. z) zl="$OPTARG";;
  182. esac
  183. done
  184. shift $(($OPTIND-1))
  185. local distro="$(find_distro $1)" orig="$2"
  186. local suite="$(find_suite $distro)"
  187. local orig_ver="$(echo "$orig" | sed -e 's/^.*_//' -e 's/\.orig\.tar.*$//')"
  188. local dver="${orig_ver}-1~${distro}+1"
  189. $suite_postfix_p && { suite="${distro}${suite_postfix}"; }
  190. [ -x "$(which dch)" ] \
  191. || err "package devscripts isn't installed"
  192. if [ -n "$modules_conf" ]; then
  193. cp $modules_conf debian/modules.conf
  194. fi
  195. local bootstrap_args=""
  196. if [ -n "$modules_list" ]; then
  197. if [ "$modules_list" = "non-dfsg" ]; then
  198. bootstrap_args="-mnon-dfsg"
  199. else set_modules_${modules_list}; fi
  200. fi
  201. if test -n "$modules_add"; then
  202. for x in $modules_add; do
  203. bootstrap_args="$bootstrap_args -p${x}"
  204. done
  205. fi
  206. (cd debian && ./bootstrap.sh -a "$avoid_mods_arch" -c $distro $bootstrap_args)
  207. case "$speed" in
  208. paranoid) sed -i ./debian/rules \
  209. -e '/\.stamp-bootstrap:/{:l2 n; /\.\/bootstrap.sh -j/{s/ -j//; :l3 n; b l3}; b l2};' ;;
  210. reckless) sed -i ./debian/rules \
  211. -e '/\.stamp-build:/{:l2 n; /make/{s/$/ -j/; :l3 n; b l3}; b l2};' ;;
  212. esac
  213. [ "$zl" -ge "1" ] || zl=1
  214. git add debian/rules
  215. dch -b -m -v "$dver" --force-distribution -D "$suite" "Nightly build."
  216. git add debian/changelog && git commit -m "nightly v$orig_ver"
  217. dpkg-source -i.* -Zxz -z${zl} -b .
  218. dpkg-genchanges -S > ../$(dsc_base)_source.changes
  219. local dsc="../$(dsc_base).dsc"
  220. git reset --hard HEAD^ && git clean -fdx
  221. } 1>&2
  222. echo $dsc
  223. }
  224. fmt_debug_hook () {
  225. cat <<'EOF'
  226. #!/bin/bash
  227. export debian_chroot="cow"
  228. cd /tmp/buildd/*/debian/..
  229. /bin/bash < /dev/tty > /dev/tty 2> /dev/tty
  230. EOF
  231. }
  232. get_sources () {
  233. local tgt_distro="$1"
  234. while read type args path distro components; do
  235. test "$type" = deb || continue
  236. if echo "$args" | grep -qv "\[" ; then components=$distro;distro=$path;path=$args;args=""; fi
  237. prefix=`echo $distro | awk -F/ '{print $1}'`
  238. suffix="`echo $distro | awk -F/ '{print $2}'`"
  239. if test -n "$suffix" ; then full="$tgt_distro/$suffix" ; else full="$tgt_distro" ; fi
  240. printf "$type $args $path $full $components\n"
  241. done < "$2"
  242. }
  243. get_mirrors () {
  244. file=${2-/etc/apt/sources.list}
  245. announce "Using apt sources file: $file"
  246. get_sources "$1" "$file" | tr '\n' '|' | head -c-1; echo
  247. }
  248. build_debs () {
  249. {
  250. set -e
  251. local OPTIND OPTARG debug_hook=false hookdir="" cow_build_opts=""
  252. local keep_pbuilder_config=false keyring="" custom_keyring="/tmp/fs.gpg"
  253. local use_custom_sources=true
  254. local custom_sources_file="/etc/apt/sources.list"
  255. while getopts 'BbdK:kT:t' o "$@"; do
  256. case "$o" in
  257. B) cow_build_opts="--debbuildopts '-B'";;
  258. b) cow_build_opts="--debbuildopts '-b'";;
  259. d) debug_hook=true;;
  260. k) keep_pbuilder_config=true;;
  261. K) custom_keyring="$OPTARG";;
  262. t) custom_sources_file="/etc/apt/sources.list";;
  263. T) custom_sources_file="$OPTARG";;
  264. esac
  265. done
  266. shift $(($OPTIND-1))
  267. if [ "$custom_sources_file" == "/etc/apt/sources.list" ]; then
  268. # If you are using the system sources, then it is reasonable that you expect to use all of the supplementary repos too
  269. cat /etc/apt/sources.list > /tmp/fs.sources.list
  270. if [ "$(ls -A /etc/apt/sources.list.d)" ]; then
  271. for X in /etc/apt/sources.list.d/*; do cat $X >> /tmp/fs.sources.list; done
  272. fi
  273. custom_sources_file="/tmp/fs.sources.list"
  274. apt-key exportall > "/tmp/fs.tmp.gpg"
  275. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --import /tmp/fs.tmp.gpg
  276. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --export > "/tmp/fs.gpg"
  277. custom_keyring="/tmp/fs.gpg"
  278. fi
  279. if [ "$custom_sources_file" == "" ]; then
  280. # Caller has explicitly set the custom sources file to empty string. They must intend to not use additional mirrors.
  281. use_custom_sources=false
  282. fi
  283. if [[ "$custom_source_file" == "/tmp/fs.sources.list" && ! -e "/tmp/fs.sources.list" ]]; then
  284. echo "deb [trusted=yes] http://files.freeswitch.org/repo/deb/freeswitch-1.8/ stretch main" >> "/tmp/fs.sources.list"
  285. fi
  286. if [[ "$custom_keyring" == "/tmp/fs.gpg" && ! -r "/tmp/fs.gpg" ]]; then
  287. cat << EOF > "/tmp/fs.tmp.gpg"
  288. -----BEGIN PGP PUBLIC KEY BLOCK-----
  289. mQINBFlVeA4BEADg3MkzUvnbuqG7S6ppt0BJIYx2WIlDzsj2EBPBBo7VpppWPGa/
  290. 5IDuCgSTVeNPffo6jlHk6HFK4g3r+oVJIDoSGE8bKHAeva/iQRUx5o56zXBVOu8q
  291. 3lkUQBjRD+14Ujz9pShNylNfIjgmUp/lg93JYHvIMVGp3AcQKr0dgkhw31NXV2D1
  292. BOSXdx6SNcbIhjY1X4CQivrz+WfX6Lk6vfWTwF0qDC0f7TYSEKmR4Sxadx/3Pb+a
  293. +Hiu3BrYtpf99ldwjb2OsfHnRvdf57z+9cA6IEbA+5ergHgrMOVj8oRRCjWM2qNg
  294. 5aaJa5WfQsPNNQ41hvjYkdOJjI5mOUFEhX0+y0Gab7S5KCvNn8f5oGvcaYLjFfM4
  295. syl2CbNx4mKfx+zJ43eH6GsU2N0VCk2lNZt0TV6p3AjZ4ofjj9YusQ6FczlWUgFW
  296. QlNQZsR5KXAhVu3ACKWsy2WSvfkSOMPpM4lAXJvHyqXh8kO+GsuedVgu8uOiAmkS
  297. acyPLohm0W87q2N/6xZ4OH7oMHQFos3hrknlESySN1iJz2qyuysL0yh77OWtdJH+
  298. GIsnftEH33ggG69FHZRDouC60C2HwWxrOwngCSxFEdQppJZjI1H5wSIUOuywZ6a0
  299. +mSe/ZnZKL/hYjy/ZQhGWdmliN8V0WF2MEesk1ouQg63bzxOYEo6Fpw6AwARAQAB
  300. tD1GcmVlU1dJVENIIFBhY2thZ2luZyBLZXkgKERlYmlhbiA5KSA8cGFja2FnZXNA
  301. ZnJlZXN3aXRjaC5vcmc+iQJUBBMBAgA+AhsDBQkSzAMAAh4BAheAFiEEXgmLPRhA
  302. bo4ZVDcJvTGJ9aK1dpgFAluBckwFCwkIBwMFFQoJCAsFFgIDAQAACgkQvTGJ9aK1
  303. dpidXQ//YVqAQrmC4EG1v2iHiap5ykMjOIW1g2w7n5Lgb30OxUHQqz5pwhdS0Ej4
  304. jXy57rvdWBm1lIyO+q2cMtKfVvRmr8OZG9XyyPg3l//lQFxoEKA1zI5+hB47xhl7
  305. GkNv0P8TsDJN9i1Swkid/jTqu+RtfEm6lUHBEKH5F5O0Mf2n/W2X6gOlqRLTNlfC
  306. SjveaOlmuTPeryxNVBka5SOsc/eHXzMM4/bWMeJbwgDdVISPuK2LHRHfEiMQr+8E
  307. SOpgTA1uIdg0BTiLvT916Qd+6a71SdKeH++AhpSe9/s3mJOS6r7FSZWvCrTs7tBR
  308. dXAqAshUTWpG5VaSO24pt+iOMvPDIMgVwuBREJy6ApyWX9m+UszJ8AV5jVBInUAO
  309. 9yLqCYdxXI4QSZVLsbFI2SuzYELaIvH3VZcapLCzBqyWzeQlUPrJ3qq92Lmencp0
  310. w7kDNZNyzRdNTsx1anN56Q90qmMJZwlZ8R/oaCphj3upQl4FPxfI3Lq+uQ1Iu44x
  311. ormacyLi9IgDogSARy/E/BPysK5G3WaKORfELVQBQQxMSsvoVP61tkKDzTqwlNAy
  312. +OxEGT8hJbMyI63f2frhKGl/mZc3PNEszqbfwbvJ61abYQWSHZEgnyr6QGORejcy
  313. YTwcjuZcrcVWfnLBufq5kHPoGtRefjZJy2EZlrvGViWGWhnk8Hq5Ag0EWVV4DgEQ
  314. ALO/uYI+WvJ8pIZbnV2XJ/wS7jAiD/1+bttd5051mSXYa7RsBJ87c6KGQqVgnDYy
  315. GucS+cmNCyiogfNKYWFWee9/FNLWpb8sqy9IcQB4GinZp1Tkom0+G9TMTjz+JlXZ
  316. fy6UNFVFRblz1esc0mMVqASmIxB9aL4u8fyJ6+WHQ4GgI/iPBZGF0XYOadeRRNGN
  317. zT24KU2WeOuOHnkneDmyEG7zYzZLnXMhwquWwpvaf5bEMgud3htM/XR9VW8vxcpH
  318. NpBHYZ1aZZfhJSKLDWTaDkOeujBsZi6r6rq9Lig03zFj5BKhm0W+J4ToyYSaQt1O
  319. sLmdpHddDAgMjJaNjokYcpje0/oRQ0sfVNWrULd0i7Y7quyc8Hk7r4uZRHc88Sie
  320. wq6+fGQjhKLgjdBm5SoOEx2ZNhrZs/0/eQCsdnQnkM5j7M8EJcOzqKu35NuDw98o
  321. hPbhwYHMTqS2aGYXyO2hPtgPo37oHE9BBvBswyvT4FO0WWRKzxqjqZK7/oEgDbNp
  322. 4qM9MrMBlRZK7VzUgJ9nczuvajzxt2F0TIUDcYy+F3sJYhtxopKroRoyWEx6V7eZ
  323. W5dXzXE903VtHI77XlMJyWErvKep8IXb2PrflaxTsadITl9DCb2kGHHPwIFhyGg/
  324. kMEgJkMv5VaHkZ5oTbbN8FdKUOjs1T3z1Jr8b+nN1opfABEBAAGJAiUEGAECAA8F
  325. AllVeA4CGwwFCRLMAwAACgkQvTGJ9aK1dph+8A/+PbNx4iW1URg/d8mz9P4hmrTn
  326. 0nG/nghfWKNnE0CUReM8sqp9yOTmzbj32uWVL5vEjXHcYwnB25n9CI4wD0nCN7Su
  327. Og7W+Eu1FiNMV/4VKf307O6ZwfMdGEqxckWC2vCa9Xp1hip/G3qO3XXHfC76kPQf
  328. CSPwNymtxICjXa8yNrncRcMuCYcy9Y+zJc9bEfSGOyQH6XBnulIOjtkw9gOWCq9b
  329. lq4WlRx69y/kMfkhj1M1rNv3ceHqeG7WvxVGgsLjLFea9L7jJNclVRhqdeRydwmP
  330. xe0UlUcSm3nu9V+opvRDoeNsVwey6dyovRrxy2Urm4FZ4CiCUpu+zbjjKO5IuHNV
  331. UIIfeR9+Y/8eT7g7mhmmidjhDXQ9Ot+MdF2tSsBk8WssXnAEeaWiZoSVl6ux5bYm
  332. XdiqaK1KoINrEt/5E80L2jsADp/uXczIkslH5W9PaMp0QHKOQa/0VrXVkyDNgyzi
  333. bNJmOz8oqhd/LleeQpgAbH3LQIMx4KVRyMVOTVjdCHptMd/xAr4KAQ3Smoi5CARL
  334. bFgFljxEwjcB6EyzvY/VAH24lZz2Mwq4WIY4yDxc1OuKyoF6EXUXmbmOhhSO1nCe
  335. +8rrZs2D85rJwFbD5nT2v/kqsgqUHUQLuwdjF1McJQpC0BK3cYXSMLe4vFE8B3/T
  336. Y4o4oqgePeTYzkxVYj8=
  337. =XPvO
  338. -----END PGP PUBLIC KEY BLOCK-----
  339. EOF
  340. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --import /tmp/fs.tmp.gpg
  341. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --export > "/tmp/fs.gpg"
  342. fi
  343. local distro="$(find_distro $1)" dsc="$2" arch="$3"
  344. if [ -z "$distro" ] || [ "$distro" = "auto" ]; then
  345. if ! (echo "$dsc" | grep -e '-[0-9]*~[a-z]*+[0-9]*'); then
  346. err "no distro specified or found"
  347. fi
  348. local x="$(echo $dsc | sed -e 's/^[^-]*-[0-9]*~//' -e 's/+[^+]*$//')"
  349. distro="$(find_distro $x)"
  350. fi
  351. [ -n "$arch" ] || arch="$(dpkg-architecture | grep '^DEB_BUILD_ARCH=' | cut -d'=' -f2)"
  352. [ -x "$(which cowbuilder)" ] \
  353. || err "package cowbuilder isn't installed"
  354. local cow_img=/var/cache/pbuilder/base-$distro-$arch.cow
  355. if [ -e "$custom_keyring" ]; then
  356. keyring="$custom_keyring"
  357. else
  358. keyring="$(mktemp /tmp/keyringXXXXXXXX.asc)"
  359. apt-key exportall > "$keyring"
  360. fi
  361. cow () {
  362. if ! $use_custom_sources; then
  363. echo "Using system sources $keyring $distro $custom_sources_file"
  364. cowbuilder "$@" \
  365. --distribution $distro \
  366. --architecture $arch \
  367. --basepath $cow_img
  368. else
  369. echo "Using custom sources $keyring $distro $custom_sources_file"
  370. cowbuilder "$@" \
  371. --distribution $distro \
  372. --architecture $arch \
  373. --basepath $cow_img \
  374. --keyring "$keyring" \
  375. --othermirror "$(get_mirrors $distro $custom_sources_file)"
  376. fi
  377. }
  378. if ! [ -d $cow_img ]; then
  379. announce "Creating base $distro-$arch image..."
  380. local x=30
  381. while ! cow --create; do
  382. [ $x -lt 1 ] && break; sleep 120; x=$((x-1))
  383. done
  384. fi
  385. announce "Updating base $distro-$arch image..."
  386. local x=30
  387. local opts="--override-config"
  388. $keep_pbuilder_config && opts=""
  389. while ! cow --update $opts; do
  390. [ $x -lt 1 ] && break; sleep 120; x=$((x-1))
  391. done
  392. announce "Building $distro-$arch DEBs from $dsc..."
  393. if $debug_hook; then
  394. mkdir -p .hooks
  395. fmt_debug_hook > .hooks/C10shell
  396. chmod +x .hooks/C10shell
  397. hookdir=$(pwd)/.hooks
  398. fi
  399. cow --build $dsc \
  400. --hookdir "$hookdir" \
  401. --buildresult ../ \
  402. $cow_build_opts
  403. if [ ! -e "$custom_keyring" ]; then
  404. # Cleanup script created temporary file
  405. rm -f $keyring
  406. fi
  407. } 1>&2
  408. echo ${dsc%.dsc}_${arch}.changes
  409. }
  410. default_distros () {
  411. local host_distro="Debian"
  412. test -z "$(which lsb_release)" || host_distro="$(lsb_release -is)"
  413. case "$host_distro" in
  414. Debian) echo "sid stretch jessie" ;;
  415. Ubuntu) echo "utopic trusty" ;;
  416. *) err "Unknown host distribution \"$host_distro\"" ;;
  417. esac
  418. }
  419. build_all () {
  420. local OPTIND OPTARG
  421. local orig_opts="" dsc_opts="" deb_opts="" modlist=""
  422. local archs="" distros="" orig="" depinst=false par=false
  423. while getopts 'a:bc:df:ijkK:l:m:no:p:s:tT:u:v:z:' o "$@"; do
  424. case "$o" in
  425. a) archs="$archs $OPTARG";;
  426. b) orig_opts="$orig_opts -b";;
  427. c) distros="$distros $OPTARG";;
  428. d) deb_opts="$deb_opts -d";;
  429. f) dsc_opts="$dsc_opts -f$OPTARG";;
  430. i) depinst=true;;
  431. j) par=true;;
  432. k) deb_opts="$deb_opts -k";;
  433. K) deb_opts="$deb_opts -K$OPTARG";;
  434. l) modlist="$OPTARG";;
  435. m) orig_opts="$orig_opts -m$OPTARG"; dsc_opts="$dsc_opts -m$OPTARG";;
  436. n) orig_opts="$orig_opts -n";;
  437. o) orig="$OPTARG";;
  438. p) dsc_opts="$dsc_opts -p$OPTARG";;
  439. s) dsc_opts="$dsc_opts -s$OPTARG";;
  440. t) deb_opts="$deb_opts -t";;
  441. T) deb_opts="$deb_opts -T$OPTARG";;
  442. u) dsc_opts="$dsc_opts -u$OPTARG";;
  443. v) orig_opts="$orig_opts -v$OPTARG";;
  444. z) orig_opts="$orig_opts -z$OPTARG"; dsc_opts="$dsc_opts -z$OPTARG";;
  445. esac
  446. done
  447. shift $(($OPTIND-1))
  448. [ -n "$archs" ] || archs="amd64 i386"
  449. [ -n "$distros" ] || distros="$(default_distros)"
  450. ! $depinst || aptitude install -y \
  451. rsync git less cowbuilder ccache \
  452. devscripts equivs build-essential yasm
  453. [ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
  454. if [ -n "$modlist" ]; then
  455. local modtmp="$(mktemp /tmp/modules-XXXXXXXXXX.conf)"
  456. > $modtmp
  457. for m in "$modlist"; do printf '%s\n' "$m" >> $modtmp; done
  458. dsc_opts="$dsc_opts -f${modtmp}"; fi
  459. [ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
  460. mkdir -p ../log
  461. > ../log/changes.txt
  462. echo; echo; echo; echo
  463. trap 'echo "Killing children...">&2; for x in $(jobs -p); do kill $x; done' EXIT
  464. if [ "${orig:0:2}" = ".." ]; then
  465. echo "true" > ../log/builds-ok.txt
  466. for distro in $distros; do
  467. echo "Creating $distro dsc..." >&2
  468. local dsc="$(create_dsc $dsc_opts $distro $orig 2>../log/$distro.txt | tail -n1)"
  469. echo "Done creating $distro dsc." >&2
  470. if [ "${dsc:0:2}" = ".." ]; then
  471. local lopts="-b"
  472. for arch in $archs; do
  473. {
  474. echo "Building $distro-$arch debs..." >&2
  475. local changes="$(build_debs $lopts $deb_opts $distro $dsc $arch 2>../log/$distro-$arch.txt | tail -n1)"
  476. echo "Done building $distro-$arch debs." >&2
  477. if [ "${changes:0:2}" = ".." ]; then
  478. echo "$changes" >> ../log/changes.txt
  479. else
  480. echo "false" > ../log/builds-ok.txt
  481. fi
  482. } &
  483. $par || wait
  484. lopts="-B"
  485. done
  486. fi
  487. done
  488. ! $par || wait
  489. fi
  490. [ -z "$modlist" ] || rm -f $modtmp
  491. trap - EXIT
  492. cat ../log/changes.txt
  493. test "$(cat ../log/builds-ok.txt)" = true || exit 1
  494. }
  495. usage () {
  496. cat >&2 <<EOF
  497. $0 [opts] [cmd] [cmd-opts]
  498. options:
  499. -d Enable debugging mode.
  500. commands:
  501. archive-orig
  502. build-all
  503. [ This must be run as root! ]
  504. -a Specify architectures
  505. -c Specify distributions
  506. -d Enable cowbuilder debug hook
  507. -f <modules.conf>
  508. Build only modules listed in this file
  509. -i Auto install build deps on host system
  510. -j Build debs in parallel
  511. -k Don't override pbuilder image configurations
  512. -K [/path/to/keyring.asc]
  513. Use custom keyring file for sources.list in build environment
  514. in the format of: apt-key exportall > /path/to/file.asc
  515. -l <modules>
  516. -m [ quicktest | non-dfsg ]
  517. Choose custom list of modules to build
  518. -n Nightly build
  519. -o <orig-file>
  520. Specify existing .orig.tar.xz file
  521. -p <module>
  522. Include otherwise avoided module
  523. -s [ paranoid | reckless ]
  524. Set FS bootstrap/build -j flags
  525. -t Use system /etc/apt/sources.list in build environment(does not include /etc/apt/sources.list.d/*.list)
  526. -T [/path/to/sources.list]
  527. Use custom /etc/apt/sources.list in build environment
  528. -u <suite-postfix>
  529. Specify a custom suite postfix
  530. -v Set version
  531. -z Set compression level
  532. build-debs <distro> <dsc-file> <architecture>
  533. [ This must be run as root! ]
  534. -B Binary architecture-dependent build
  535. -b Binary-only build
  536. -d Enable cowbuilder debug hook
  537. -k Don't override pbuilder image configurations
  538. -K [/path/to/keyring.asc]
  539. Use custom keyring file for sources.list in build environment
  540. in the format of: apt-key exportall > /path/to/file.asc
  541. -t Use system /etc/apt/sources.list in build environment
  542. -T [/path/to/sources.list]
  543. Use custom /etc/apt/sources.list in build environment
  544. create-dbg-pkgs
  545. create-dsc <distro> <orig-file>
  546. -f <modules.conf>
  547. Build only modules listed in this file
  548. -m [ quicktest | non-dfsg ]
  549. Choose custom list of modules to build
  550. -p <module>
  551. Include otherwise avoided module
  552. -s [ paranoid | reckless ]
  553. Set FS bootstrap/build -j flags
  554. -u <suite-postfix>
  555. Specify a custom suite postfix
  556. -z Set compression level
  557. create-orig <treeish>
  558. -m [ quicktest | non-dfsg ]
  559. Choose custom list of modules to build
  560. -n Nightly build
  561. -v Set version
  562. -z Set compression level
  563. EOF
  564. exit 1
  565. }
  566. while getopts 'dh' o "$@"; do
  567. case "$o" in
  568. d) set -vx;;
  569. h) usage;;
  570. esac
  571. done
  572. shift $(($OPTIND-1))
  573. cmd="$1"; [ -n "$cmd" ] || usage
  574. shift
  575. case "$cmd" in
  576. archive-orig) archive_orig "$@" ;;
  577. build-all) build_all "$@" ;;
  578. build-debs) build_debs "$@" ;;
  579. create-dbg-pkgs) create_dbg_pkgs ;;
  580. create-dsc) create_dsc "$@" ;;
  581. create-orig) create_orig "$@" ;;
  582. *) usage ;;
  583. esac