util.sh 21 KB

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