chiark / gitweb /
dot/parallel-hosts: Use VPN name for `mdwdev'.
[profile] / bin / mdw-sbuild
1 #! /bin/sh -e
2 ###
3 ### Build a Debian package on an sbuild server.
4 ###
5 ### (c) 2016 Mark Wooding
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU General Public License as published by
12 ### the Free Software Foundation; either version 2 of the License, or
13 ### (at your option) any later version.
14 ###
15 ### This program is distributed in the hope that it will be useful,
16 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ### GNU General Public License for more details.
19 ###
20 ### You should have received a copy of the GNU General Public License
21 ### along with this program; if not, write to the Free Software Foundation,
22 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 ###--------------------------------------------------------------------------
25 ### Some utilities.
26
27 prog=${0##*/}
28
29 fail () { echo >&2 "$prog: $*"; exit 1; }
30 usage () { echo "usage: $prog [-ainT] [-k KEYID] [-p DIR] [-t TARGET] [-A DBPARGS] HOST"; }
31 fail_usage () { usage >&2; exit 1; }
32
33 ###--------------------------------------------------------------------------
34 ### Parse options.
35
36 bogusp=nil noactp=nil signp=nil
37 unset buildopts pkgs dbpargs
38 while getopts "haik:np:t:A:T" opt; do
39   case $opt in
40     h)
41       usage
42       cat <<EOF
43
44 Options:
45         -h              Show this help text.
46         -a              Build only architecture-dependent packages.
47         -i              Build only architecture-neutral packages.
48         -k KEYID        Sign the result using KEYID.
49         -n              Don't actually do the build.
50         -p DIR          Upload additional packages from DIR.
51         -t TARGET       Build in TARGET build environment.
52         -A ARGS         Pass ARGS to \`dpkg-buildpackage'.
53         -T              Don't run the tests.
54 EOF
55       exit 0
56       ;;
57     a) buildopts="${buildopts+$buildopts }-a" ;;
58     i) buildopts="${buildopts+$buildopts }-i" ;;
59     k) signp=t keyid=$OPTARG ;;
60     n) buildopts="${buildopts+$buildopts }-n" noactp=t ;;
61     p) pkgs=$OPTARG ;;
62     t) buildopts="${buildopts+$buildopts }-t$OPTARG" ;;
63     A)
64       buildopts="${buildopts+$buildopts }-A$OPTARG"
65       dbpargs="${dbpargs+$dbpargs }$OPTARG"
66       ;;
67     T) buildopts="${buildopts+$buildopts }-T" ;;
68     *) bogusp=t ;;
69   esac
70 done
71 shift $(( $OPTIND - 1 ))
72 case $# in
73   1) host=$1 ;;
74   *) bogusp=t ;;
75 esac
76 case $bogusp in t) fail_usage ;; esac
77 case $noactp in t) signp=nil ;; esac
78 case ${pkgs-/hack} in /*) ;; *) pkgs=$(pwd)/$pkgs ;; esac
79
80 ###--------------------------------------------------------------------------
81 ### Main program.
82
83 ## Figure out the package name and version number.
84 unset pkg ver
85 while read tag value; do
86   case $tag in
87     Source:) pkg=$value ;;
88     Version:) ver=$value ;;
89   esac
90 done <<EOF
91 $(dpkg-parsechangelog)
92 EOF
93 case ${pkg+t} in t) ;; *) fail "can't figure out the package name" ;; esac
94 case ${ver+t} in t) ;; *) fail "can't figure out the package version" ;; esac
95
96 ## Build a Debian source package.  Don't sign anything yet.  That will happen
97 ## at the end, all in one go.
98 dpkg-buildpackage -S -uc -us -d -i $dbpargs
99 cd ..
100 dsc=${pkg}_${ver}.dsc
101 [ -f "$dsc" ] || fail "where is my \`.dsc' file?"
102
103 ## Actually do the build.  Get a build directory assigned by the server,
104 ## upload the sources, run the build, and collect the results.
105 builddir=$(ssh "$host" mdw-sbuild-server dir "$pkg/$ver")
106 dcmd rsync -a "$dsc" "$host:$builddir/"
107 case ${pkgs+t} in t) rsync -a "$pkgs/" "$host:$builddir/pkgs/" ;; esac
108 set +e; ssh "$host" mdw-sbuild-server $buildopts build "$builddir"
109 rc=$?; set -e
110 rsync -a "$host:$builddir/" ./
111 case $rc in 0) ;; *) exit $rc ;; esac
112
113 ## Merge the change files together, and maybe sign the result.
114 chchch=${pkg}_${ver}_source.changes
115 for i in "${pkg}_${ver}"_*.changes; do
116   case " $chchch " in *" $i "*) ;; *) chchch="$chchch $i" ;; esac
117 done
118 mergechanges -f $chchch
119 rm $chchch
120 case $signp in
121   t) debsign -k"$keyid" "${pkg}_${ver}_multi.changes" ;;
122 esac
123
124 ###----- That's all, folks --------------------------------------------------