2
0

util.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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. prep_create_orig () {
  118. {
  119. set -e
  120. local OPTIND OPTARG
  121. local uver="" hrev="" bundle_deps=true soft_reset=false
  122. while getopts 'bm:nv:V:xz:' o "$@"; do
  123. case "$o" in
  124. b) ;;
  125. m) ;;
  126. n) uver="nightly";;
  127. v) uver="$OPTARG";;
  128. V) uver="$OPTARG";;
  129. x) soft_reset=true;;
  130. z) ;;
  131. esac
  132. done
  133. shift $(($OPTIND-1))
  134. if [ -z "$uver" ] || [ "$uver" = "nightly" ]; then
  135. uver="$(get_nightly_version)"
  136. hrev="$(get_nightly_revision_human)"
  137. fi
  138. local treeish="$1"
  139. [ -n "$treeish" ] || treeish="HEAD"
  140. if $soft_reset; then
  141. git reset --soft "$treeish"
  142. else
  143. check_repo_clean
  144. git reset --hard "$treeish"
  145. fi
  146. if $bundle_deps; then
  147. (cd libs && getlibs)
  148. fi
  149. ./build/set-fs-version.sh "$uver" "$hrev" # ToDo: Handle empty $hrev
  150. echo "$uver" > .version
  151. } 1>&2
  152. echo "$uver"
  153. }
  154. create_orig () {
  155. {
  156. set -e
  157. local OPTIND OPTARG
  158. local bundle_deps=true modules_list="" soft_reset=false auto_orig=false zl=9e
  159. local uver="$(prep_create_orig "$@")"
  160. while getopts 'bm:nv:V:xz:' o "$@"; do
  161. case "$o" in
  162. b) ;;
  163. m) modules_list="$OPTARG";;
  164. n) ;;
  165. v) ;;
  166. V) auto_orig=true;;
  167. x) soft_reset=true;;
  168. z) zl="$OPTARG";;
  169. esac
  170. done
  171. shift $(($OPTIND-1))
  172. local commit_epoch=$(git log -1 --format=%ct)
  173. local source_date=$(date -u -d @$commit_epoch +'%Y-%m-%d %H:%M:%S')
  174. local orig git_archive_prefix
  175. if $auto_orig; then
  176. orig="../freeswitch_$(debian/version-omit_revision.pl).orig.tar.xz"
  177. git_archive_prefix="freeswitch/"
  178. else
  179. orig="../freeswitch_$(mk_dver "$uver")~$(lsb_release -sc).orig.tar.xz"
  180. git_archive_prefix="freeswitch-$uver/"
  181. fi
  182. mv .gitattributes .gitattributes.orig
  183. local -a args=(-e '\bdebian-ignore\b')
  184. test "$modules_list" = "non-dfsg" || args+=(-e '\bdfsg-nonfree\b')
  185. grep .gitattributes.orig "${args[@]}" \
  186. | while xread l; do
  187. echo "$l export-ignore" >> .gitattributes
  188. done
  189. if $bundle_deps; then
  190. git add -f libs
  191. fi
  192. git add -f configure.ac .version
  193. git commit --allow-empty -m "nightly v$uver"
  194. local tmpsrcdir="$(mktemp -d)"
  195. git archive -v \
  196. --worktree-attributes \
  197. --format=tar \
  198. --prefix=$git_archive_prefix \
  199. HEAD | tar --extract --directory="$tmpsrcdir"
  200. # https://www.gnu.org/software/tar/manual/html_section/Reproducibility.html
  201. tar \
  202. --sort=name \
  203. --format=posix \
  204. --pax-option='exthdr.name=%d/PaxHeaders/%f' \
  205. --pax-option='delete=atime,delete=ctime' \
  206. --clamp-mtime \
  207. --mtime="$source_date" \
  208. --numeric-owner \
  209. --owner=0 \
  210. --group=0 \
  211. --mode='go+u,go-w' \
  212. --create \
  213. --directory="$tmpsrcdir" \
  214. . | xz -v -c -${zl} > "$orig" && \
  215. rm -rf "$tmpsrcdir"
  216. echo "Source archive checksum:"
  217. sha256sum $orig
  218. mv .gitattributes.orig .gitattributes
  219. if $soft_reset; then
  220. git reset --soft HEAD^
  221. else
  222. git reset --hard HEAD^ && git clean -fdx
  223. fi
  224. } 1>&2
  225. echo $orig
  226. }
  227. set_modules_quicktest () {
  228. cat > debian/modules.conf <<EOF
  229. applications/mod_commands
  230. EOF
  231. }
  232. prep_create_dsc () {
  233. {
  234. set -e
  235. local OPTIND OPTARG modules_conf="" modules_add="" modules_list="" speed="normal"
  236. while getopts 'a:f:m:p:s:u:z:' o "$@"; do
  237. case "$o" in
  238. a) avoid_mods_arch="$OPTARG";;
  239. f) modules_conf="$OPTARG";;
  240. m) modules_list="$OPTARG";;
  241. p) modules_add="$modules_add $OPTARG";;
  242. s) speed="$OPTARG";;
  243. u) ;;
  244. z) ;;
  245. esac
  246. done
  247. shift $(($OPTIND-1))
  248. local distro="$(find_distro $1)"
  249. if [ -n "$modules_conf" ]; then
  250. cp $modules_conf debian/modules.conf
  251. fi
  252. local bootstrap_args=""
  253. if [ -n "$modules_list" ]; then
  254. if [ "$modules_list" = "non-dfsg" ]; then
  255. bootstrap_args="-mnon-dfsg"
  256. else
  257. set_modules_${modules_list}
  258. fi
  259. fi
  260. if test -n "$modules_add"; then
  261. for x in $modules_add; do
  262. bootstrap_args="$bootstrap_args -p${x}"
  263. done
  264. fi
  265. (cd debian && ./bootstrap.sh -a "$avoid_mods_arch" -c $distro $bootstrap_args)
  266. case "$speed" in
  267. paranoid) sed -i ./debian/rules \
  268. -e '/\.stamp-bootstrap:/{:l2 n; /\.\/bootstrap.sh -j/{s/ -j//; :l3 n; b l3}; b l2};' ;;
  269. reckless) sed -i ./debian/rules \
  270. -e '/\.stamp-build:/{:l2 n; /make/{s/$/ -j/; :l3 n; b l3}; b l2};' ;;
  271. esac
  272. } 1>&2
  273. }
  274. create_dsc () {
  275. {
  276. set -e
  277. prep_create_dsc "$@"
  278. local OPTIND OPTARG suite_postfix="" suite_postfix_p=false soft_reset=false zl=9
  279. while getopts 'a:f:m:p:s:u:xz:' o "$@"; do
  280. case "$o" in
  281. a) ;;
  282. f) ;;
  283. m) ;;
  284. p) ;;
  285. s) ;;
  286. u) suite_postfix="$OPTARG"; suite_postfix_p=true;;
  287. x) soft_reset=true;;
  288. z) zl="$OPTARG";;
  289. esac
  290. done
  291. shift $(($OPTIND-1))
  292. local distro="$(find_distro $1)" orig="$2"
  293. local suite="$(find_suite $distro)"
  294. local orig_ver="$(echo "$orig" | sed -e 's/^.*_//' -e 's/\.orig\.tar.*$//')"
  295. local dver="${orig_ver}-1~${distro}+1"
  296. $suite_postfix_p && { suite="${distro}${suite_postfix}"; }
  297. [ -x "$(which dch)" ] \
  298. || err "package devscripts isn't installed"
  299. [ "$zl" -ge "1" ] || zl=1
  300. dch -b -m -v "$dver" --force-distribution -D "$suite" "Nightly build."
  301. git add debian/rules debian/changelog && git commit -m "nightly v$orig_ver"
  302. dpkg-source -i.* -Zxz -z${zl} -b .
  303. dpkg-genchanges -S > ../$(dsc_base)_source.changes
  304. local dsc="../$(dsc_base).dsc"
  305. if $soft_reset; then
  306. git reset --soft HEAD^
  307. else
  308. git reset --hard HEAD^ && git clean -fdx
  309. fi
  310. } 1>&2
  311. echo $dsc
  312. }
  313. fmt_debug_hook () {
  314. cat <<'EOF'
  315. #!/bin/bash
  316. export debian_chroot="cow"
  317. cd /tmp/buildd/*/debian/..
  318. /bin/bash < /dev/tty > /dev/tty 2> /dev/tty
  319. EOF
  320. }
  321. get_sources () {
  322. local tgt_distro="$1"
  323. while read type args path distro components; do
  324. test "$type" = deb || continue
  325. if echo "$args" | grep -qv "\[" ; then components=$distro;distro=$path;path=$args;args=""; fi
  326. prefix=`echo $distro | awk -F/ '{print $1}'`
  327. suffix="`echo $distro | awk -F/ '{print $2}'`"
  328. if test -n "$suffix" ; then full="$tgt_distro/$suffix" ; else full="$tgt_distro" ; fi
  329. printf "$type $args $path $full $components\n"
  330. done < "$2"
  331. }
  332. get_mirrors () {
  333. file=${2-/etc/apt/sources.list}
  334. announce "Using apt sources file: $file"
  335. get_sources "$1" "$file" | tr '\n' '|' | head -c-1; echo
  336. }
  337. build_debs () {
  338. {
  339. set -e
  340. local OPTIND OPTARG debug_hook=false hookdir="" cow_build_opts=""
  341. local keep_pbuilder_config=false keyring="" custom_keyring="/tmp/fs.gpg"
  342. local use_custom_sources=true
  343. local custom_sources_file="/etc/apt/sources.list"
  344. while getopts 'BbdK:kT:t' o "$@"; do
  345. case "$o" in
  346. B) cow_build_opts="--debbuildopts '-B'";;
  347. b) cow_build_opts="--debbuildopts '-b'";;
  348. d) debug_hook=true;;
  349. k) keep_pbuilder_config=true;;
  350. K) custom_keyring="$OPTARG";;
  351. t) custom_sources_file="/etc/apt/sources.list";;
  352. T) custom_sources_file="$OPTARG";;
  353. esac
  354. done
  355. shift $(($OPTIND-1))
  356. if [ "$custom_sources_file" == "/etc/apt/sources.list" ]; then
  357. # If you are using the system sources, then it is reasonable that you expect to use all of the supplementary repos too
  358. cat /etc/apt/sources.list > /tmp/fs.sources.list
  359. if [ "$(ls -A /etc/apt/sources.list.d)" ]; then
  360. for X in /etc/apt/sources.list.d/*; do cat $X >> /tmp/fs.sources.list; done
  361. fi
  362. custom_sources_file="/tmp/fs.sources.list"
  363. apt-key exportall > "/tmp/fs.tmp.gpg"
  364. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --import /tmp/fs.tmp.gpg
  365. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --export > "/tmp/fs.gpg"
  366. custom_keyring="/tmp/fs.gpg"
  367. fi
  368. if [ "$custom_sources_file" == "" ]; then
  369. # Caller has explicitly set the custom sources file to empty string. They must intend to not use additional mirrors.
  370. use_custom_sources=false
  371. fi
  372. if [[ "$custom_source_file" == "/tmp/fs.sources.list" && ! -e "/tmp/fs.sources.list" ]]; then
  373. echo "deb [trusted=yes] http://files.freeswitch.org/repo/deb/freeswitch-1.8/ stretch main" >> "/tmp/fs.sources.list"
  374. fi
  375. if [[ "$custom_keyring" == "/tmp/fs.gpg" && ! -r "/tmp/fs.gpg" ]]; then
  376. cat << EOF > "/tmp/fs.tmp.gpg"
  377. -----BEGIN PGP PUBLIC KEY BLOCK-----
  378. mQINBFlVeA4BEADg3MkzUvnbuqG7S6ppt0BJIYx2WIlDzsj2EBPBBo7VpppWPGa/
  379. 5IDuCgSTVeNPffo6jlHk6HFK4g3r+oVJIDoSGE8bKHAeva/iQRUx5o56zXBVOu8q
  380. 3lkUQBjRD+14Ujz9pShNylNfIjgmUp/lg93JYHvIMVGp3AcQKr0dgkhw31NXV2D1
  381. BOSXdx6SNcbIhjY1X4CQivrz+WfX6Lk6vfWTwF0qDC0f7TYSEKmR4Sxadx/3Pb+a
  382. +Hiu3BrYtpf99ldwjb2OsfHnRvdf57z+9cA6IEbA+5ergHgrMOVj8oRRCjWM2qNg
  383. 5aaJa5WfQsPNNQ41hvjYkdOJjI5mOUFEhX0+y0Gab7S5KCvNn8f5oGvcaYLjFfM4
  384. syl2CbNx4mKfx+zJ43eH6GsU2N0VCk2lNZt0TV6p3AjZ4ofjj9YusQ6FczlWUgFW
  385. QlNQZsR5KXAhVu3ACKWsy2WSvfkSOMPpM4lAXJvHyqXh8kO+GsuedVgu8uOiAmkS
  386. acyPLohm0W87q2N/6xZ4OH7oMHQFos3hrknlESySN1iJz2qyuysL0yh77OWtdJH+
  387. GIsnftEH33ggG69FHZRDouC60C2HwWxrOwngCSxFEdQppJZjI1H5wSIUOuywZ6a0
  388. +mSe/ZnZKL/hYjy/ZQhGWdmliN8V0WF2MEesk1ouQg63bzxOYEo6Fpw6AwARAQAB
  389. tD1GcmVlU1dJVENIIFBhY2thZ2luZyBLZXkgKERlYmlhbiA5KSA8cGFja2FnZXNA
  390. ZnJlZXN3aXRjaC5vcmc+iQJUBBMBAgA+AhsDBQkSzAMAAh4BAheAFiEEXgmLPRhA
  391. bo4ZVDcJvTGJ9aK1dpgFAluBckwFCwkIBwMFFQoJCAsFFgIDAQAACgkQvTGJ9aK1
  392. dpidXQ//YVqAQrmC4EG1v2iHiap5ykMjOIW1g2w7n5Lgb30OxUHQqz5pwhdS0Ej4
  393. jXy57rvdWBm1lIyO+q2cMtKfVvRmr8OZG9XyyPg3l//lQFxoEKA1zI5+hB47xhl7
  394. GkNv0P8TsDJN9i1Swkid/jTqu+RtfEm6lUHBEKH5F5O0Mf2n/W2X6gOlqRLTNlfC
  395. SjveaOlmuTPeryxNVBka5SOsc/eHXzMM4/bWMeJbwgDdVISPuK2LHRHfEiMQr+8E
  396. SOpgTA1uIdg0BTiLvT916Qd+6a71SdKeH++AhpSe9/s3mJOS6r7FSZWvCrTs7tBR
  397. dXAqAshUTWpG5VaSO24pt+iOMvPDIMgVwuBREJy6ApyWX9m+UszJ8AV5jVBInUAO
  398. 9yLqCYdxXI4QSZVLsbFI2SuzYELaIvH3VZcapLCzBqyWzeQlUPrJ3qq92Lmencp0
  399. w7kDNZNyzRdNTsx1anN56Q90qmMJZwlZ8R/oaCphj3upQl4FPxfI3Lq+uQ1Iu44x
  400. ormacyLi9IgDogSARy/E/BPysK5G3WaKORfELVQBQQxMSsvoVP61tkKDzTqwlNAy
  401. +OxEGT8hJbMyI63f2frhKGl/mZc3PNEszqbfwbvJ61abYQWSHZEgnyr6QGORejcy
  402. YTwcjuZcrcVWfnLBufq5kHPoGtRefjZJy2EZlrvGViWGWhnk8Hq5Ag0EWVV4DgEQ
  403. ALO/uYI+WvJ8pIZbnV2XJ/wS7jAiD/1+bttd5051mSXYa7RsBJ87c6KGQqVgnDYy
  404. GucS+cmNCyiogfNKYWFWee9/FNLWpb8sqy9IcQB4GinZp1Tkom0+G9TMTjz+JlXZ
  405. fy6UNFVFRblz1esc0mMVqASmIxB9aL4u8fyJ6+WHQ4GgI/iPBZGF0XYOadeRRNGN
  406. zT24KU2WeOuOHnkneDmyEG7zYzZLnXMhwquWwpvaf5bEMgud3htM/XR9VW8vxcpH
  407. NpBHYZ1aZZfhJSKLDWTaDkOeujBsZi6r6rq9Lig03zFj5BKhm0W+J4ToyYSaQt1O
  408. sLmdpHddDAgMjJaNjokYcpje0/oRQ0sfVNWrULd0i7Y7quyc8Hk7r4uZRHc88Sie
  409. wq6+fGQjhKLgjdBm5SoOEx2ZNhrZs/0/eQCsdnQnkM5j7M8EJcOzqKu35NuDw98o
  410. hPbhwYHMTqS2aGYXyO2hPtgPo37oHE9BBvBswyvT4FO0WWRKzxqjqZK7/oEgDbNp
  411. 4qM9MrMBlRZK7VzUgJ9nczuvajzxt2F0TIUDcYy+F3sJYhtxopKroRoyWEx6V7eZ
  412. W5dXzXE903VtHI77XlMJyWErvKep8IXb2PrflaxTsadITl9DCb2kGHHPwIFhyGg/
  413. kMEgJkMv5VaHkZ5oTbbN8FdKUOjs1T3z1Jr8b+nN1opfABEBAAGJAiUEGAECAA8F
  414. AllVeA4CGwwFCRLMAwAACgkQvTGJ9aK1dph+8A/+PbNx4iW1URg/d8mz9P4hmrTn
  415. 0nG/nghfWKNnE0CUReM8sqp9yOTmzbj32uWVL5vEjXHcYwnB25n9CI4wD0nCN7Su
  416. Og7W+Eu1FiNMV/4VKf307O6ZwfMdGEqxckWC2vCa9Xp1hip/G3qO3XXHfC76kPQf
  417. CSPwNymtxICjXa8yNrncRcMuCYcy9Y+zJc9bEfSGOyQH6XBnulIOjtkw9gOWCq9b
  418. lq4WlRx69y/kMfkhj1M1rNv3ceHqeG7WvxVGgsLjLFea9L7jJNclVRhqdeRydwmP
  419. xe0UlUcSm3nu9V+opvRDoeNsVwey6dyovRrxy2Urm4FZ4CiCUpu+zbjjKO5IuHNV
  420. UIIfeR9+Y/8eT7g7mhmmidjhDXQ9Ot+MdF2tSsBk8WssXnAEeaWiZoSVl6ux5bYm
  421. XdiqaK1KoINrEt/5E80L2jsADp/uXczIkslH5W9PaMp0QHKOQa/0VrXVkyDNgyzi
  422. bNJmOz8oqhd/LleeQpgAbH3LQIMx4KVRyMVOTVjdCHptMd/xAr4KAQ3Smoi5CARL
  423. bFgFljxEwjcB6EyzvY/VAH24lZz2Mwq4WIY4yDxc1OuKyoF6EXUXmbmOhhSO1nCe
  424. +8rrZs2D85rJwFbD5nT2v/kqsgqUHUQLuwdjF1McJQpC0BK3cYXSMLe4vFE8B3/T
  425. Y4o4oqgePeTYzkxVYj8=
  426. =XPvO
  427. -----END PGP PUBLIC KEY BLOCK-----
  428. EOF
  429. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --import /tmp/fs.tmp.gpg
  430. gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --export > "/tmp/fs.gpg"
  431. fi
  432. local distro="$(find_distro $1)" dsc="$2" arch="$3"
  433. if [ -z "$distro" ] || [ "$distro" = "auto" ]; then
  434. if ! (echo "$dsc" | grep -e '-[0-9]*~[a-z]*+[0-9]*'); then
  435. err "no distro specified or found"
  436. fi
  437. local x="$(echo $dsc | sed -e 's/^[^-]*-[0-9]*~//' -e 's/+[^+]*$//')"
  438. distro="$(find_distro $x)"
  439. fi
  440. [ -n "$arch" ] || arch="$(dpkg-architecture | grep '^DEB_BUILD_ARCH=' | cut -d'=' -f2)"
  441. [ -x "$(which cowbuilder)" ] \
  442. || err "package cowbuilder isn't installed"
  443. local cow_img=/var/cache/pbuilder/base-$distro-$arch.cow
  444. if [ -e "$custom_keyring" ]; then
  445. keyring="$custom_keyring"
  446. else
  447. keyring="$(mktemp /tmp/keyringXXXXXXXX.asc)"
  448. apt-key exportall > "$keyring"
  449. fi
  450. cow () {
  451. if ! $use_custom_sources; then
  452. echo "Using system sources $keyring $distro $custom_sources_file"
  453. cowbuilder "$@" \
  454. --distribution $distro \
  455. --architecture $arch \
  456. --basepath $cow_img
  457. else
  458. echo "Using custom sources $keyring $distro $custom_sources_file"
  459. cowbuilder "$@" \
  460. --distribution $distro \
  461. --architecture $arch \
  462. --basepath $cow_img \
  463. --keyring "$keyring" \
  464. --othermirror "$(get_mirrors $distro $custom_sources_file)"
  465. fi
  466. }
  467. if ! [ -d $cow_img ]; then
  468. announce "Creating base $distro-$arch image..."
  469. local x=30
  470. while ! cow --create; do
  471. [ $x -lt 1 ] && break; sleep 120; x=$((x-1))
  472. done
  473. fi
  474. announce "Updating base $distro-$arch image..."
  475. local x=30
  476. local opts="--override-config"
  477. $keep_pbuilder_config && opts=""
  478. while ! cow --update $opts; do
  479. [ $x -lt 1 ] && break; sleep 120; x=$((x-1))
  480. done
  481. announce "Building $distro-$arch DEBs from $dsc..."
  482. if $debug_hook; then
  483. mkdir -p .hooks
  484. fmt_debug_hook > .hooks/C10shell
  485. chmod +x .hooks/C10shell
  486. hookdir=$(pwd)/.hooks
  487. fi
  488. cow --build $dsc \
  489. --hookdir "$hookdir" \
  490. --buildresult ../ \
  491. $cow_build_opts
  492. if [ ! -e "$custom_keyring" ]; then
  493. # Cleanup script created temporary file
  494. rm -f $keyring
  495. fi
  496. } 1>&2
  497. echo ${dsc%.dsc}_${arch}.changes
  498. }
  499. default_distros () {
  500. local host_distro="Debian"
  501. test -z "$(which lsb_release)" || host_distro="$(lsb_release -is)"
  502. case "$host_distro" in
  503. Debian) echo "sid stretch jessie" ;;
  504. Ubuntu) echo "utopic trusty" ;;
  505. *) err "Unknown host distribution \"$host_distro\"" ;;
  506. esac
  507. }
  508. build_all () {
  509. local OPTIND OPTARG
  510. local orig_opts="" dsc_opts="" deb_opts="" modlist=""
  511. local archs="" distros="" orig="" depinst=false par=false
  512. while getopts 'a:bc:df:ijkK:l:m:no:p:s:tT:u:v:z:' o "$@"; do
  513. case "$o" in
  514. a) archs="$archs $OPTARG";;
  515. b) orig_opts="$orig_opts -b";;
  516. c) distros="$distros $OPTARG";;
  517. d) deb_opts="$deb_opts -d";;
  518. f) dsc_opts="$dsc_opts -f$OPTARG";;
  519. i) depinst=true;;
  520. j) par=true;;
  521. k) deb_opts="$deb_opts -k";;
  522. K) deb_opts="$deb_opts -K$OPTARG";;
  523. l) modlist="$OPTARG";;
  524. m) orig_opts="$orig_opts -m$OPTARG"; dsc_opts="$dsc_opts -m$OPTARG";;
  525. n) orig_opts="$orig_opts -n";;
  526. o) orig="$OPTARG";;
  527. p) dsc_opts="$dsc_opts -p$OPTARG";;
  528. s) dsc_opts="$dsc_opts -s$OPTARG";;
  529. t) deb_opts="$deb_opts -t";;
  530. T) deb_opts="$deb_opts -T$OPTARG";;
  531. u) dsc_opts="$dsc_opts -u$OPTARG";;
  532. v) orig_opts="$orig_opts -v$OPTARG";;
  533. z) orig_opts="$orig_opts -z$OPTARG"; dsc_opts="$dsc_opts -z$OPTARG";;
  534. esac
  535. done
  536. shift $(($OPTIND-1))
  537. [ -n "$archs" ] || archs="amd64 i386"
  538. [ -n "$distros" ] || distros="$(default_distros)"
  539. ! $depinst || aptitude install -y \
  540. rsync git less cowbuilder ccache \
  541. devscripts equivs build-essential yasm
  542. [ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
  543. if [ -n "$modlist" ]; then
  544. local modtmp="$(mktemp /tmp/modules-XXXXXXXXXX.conf)"
  545. > $modtmp
  546. for m in "$modlist"; do printf '%s\n' "$m" >> $modtmp; done
  547. dsc_opts="$dsc_opts -f${modtmp}"; fi
  548. [ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
  549. mkdir -p ../log
  550. > ../log/changes.txt
  551. echo; echo; echo; echo
  552. trap 'echo "Killing children...">&2; for x in $(jobs -p); do kill $x; done' EXIT
  553. if [ "${orig:0:2}" = ".." ]; then
  554. echo "true" > ../log/builds-ok.txt
  555. for distro in $distros; do
  556. echo "Creating $distro dsc..." >&2
  557. local dsc="$(create_dsc $dsc_opts $distro $orig 2>../log/$distro.txt | tail -n1)"
  558. echo "Done creating $distro dsc." >&2
  559. if [ "${dsc:0:2}" = ".." ]; then
  560. local lopts="-b"
  561. for arch in $archs; do
  562. {
  563. echo "Building $distro-$arch debs..." >&2
  564. local changes="$(build_debs $lopts $deb_opts $distro $dsc $arch 2>../log/$distro-$arch.txt | tail -n1)"
  565. echo "Done building $distro-$arch debs." >&2
  566. if [ "${changes:0:2}" = ".." ]; then
  567. echo "$changes" >> ../log/changes.txt
  568. else
  569. echo "false" > ../log/builds-ok.txt
  570. fi
  571. } &
  572. $par || wait
  573. lopts="-B"
  574. done
  575. fi
  576. done
  577. ! $par || wait
  578. fi
  579. [ -z "$modlist" ] || rm -f $modtmp
  580. trap - EXIT
  581. cat ../log/changes.txt
  582. test "$(cat ../log/builds-ok.txt)" = true || exit 1
  583. }
  584. usage () {
  585. cat >&2 <<EOF
  586. $0 [opts] [cmd] [cmd-opts]
  587. options:
  588. -d Enable debugging mode.
  589. commands:
  590. archive-orig
  591. build-all
  592. [ This must be run as root! ]
  593. -a Specify architectures
  594. -c Specify distributions
  595. -d Enable cowbuilder debug hook
  596. -f <modules.conf>
  597. Build only modules listed in this file
  598. -i Auto install build deps on host system
  599. -j Build debs in parallel
  600. -k Don't override pbuilder image configurations
  601. -K [/path/to/keyring.asc]
  602. Use custom keyring file for sources.list in build environment
  603. in the format of: apt-key exportall > /path/to/file.asc
  604. -l <modules>
  605. -m [ quicktest | non-dfsg ]
  606. Choose custom list of modules to build
  607. -n Nightly build
  608. -o <orig-file>
  609. Specify existing .orig.tar.xz file
  610. -p <module>
  611. Include otherwise avoided module
  612. -s [ paranoid | reckless ]
  613. Set FS bootstrap/build -j flags
  614. -t Use system /etc/apt/sources.list in build environment(does not include /etc/apt/sources.list.d/*.list)
  615. -T [/path/to/sources.list]
  616. Use custom /etc/apt/sources.list in build environment
  617. -u <suite-postfix>
  618. Specify a custom suite postfix
  619. -v Set version
  620. -z Set compression level
  621. build-debs <distro> <dsc-file> <architecture>
  622. [ This must be run as root! ]
  623. -B Binary architecture-dependent build
  624. -b Binary-only build
  625. -d Enable cowbuilder debug hook
  626. -k Don't override pbuilder image configurations
  627. -K [/path/to/keyring.asc]
  628. Use custom keyring file for sources.list in build environment
  629. in the format of: apt-key exportall > /path/to/file.asc
  630. -t Use system /etc/apt/sources.list in build environment
  631. -T [/path/to/sources.list]
  632. Use custom /etc/apt/sources.list in build environment
  633. create-dbg-pkgs
  634. create-dsc <distro> <orig-file> (same for 'prep-create-dsc')
  635. -f <modules.conf>
  636. Build only modules listed in this file
  637. -m [ quicktest | non-dfsg ]
  638. Choose custom list of modules to build
  639. -p <module>
  640. Include otherwise avoided module
  641. -s [ paranoid | reckless ]
  642. Set FS bootstrap/build -j flags
  643. -u <suite-postfix>
  644. Specify a custom suite postfix
  645. -x Use git soft reset instead of hard reset
  646. -z Set compression level
  647. create-orig <treeish> (same for 'prep_create_orig')
  648. -m [ quicktest | non-dfsg ]
  649. Choose custom list of modules to build
  650. -n Nightly build
  651. -v Set version
  652. -V Set version (without replacing every '-' to '~')
  653. -x Use git soft reset instead of hard reset
  654. -z Set compression level
  655. EOF
  656. exit 1
  657. }
  658. while getopts 'dh' o "$@"; do
  659. case "$o" in
  660. d) set -vx;;
  661. h) usage;;
  662. esac
  663. done
  664. shift $(($OPTIND-1))
  665. cmd="$1"; [ -n "$cmd" ] || usage
  666. shift
  667. case "$cmd" in
  668. archive-orig) archive_orig "$@" ;;
  669. build-all) build_all "$@" ;;
  670. build-debs) build_debs "$@" ;;
  671. create-dbg-pkgs) create_dbg_pkgs ;;
  672. prep-create-dsc) prep_create_dsc "$@" ;;
  673. create-dsc) create_dsc "$@" ;;
  674. prep-create-orig) prep_create_orig "$@" ;;
  675. create-orig) create_orig "$@" ;;
  676. *) usage ;;
  677. esac