New tools for building Debian packages using sbuild(1).
[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 [-ain] [-k KEYID] [-t TARGET] HOST"; }
31 fail_usage () { usage >&2; exit 1; }
32
33 ###--------------------------------------------------------------------------
34 ### Parse options.
35
36 bogusp=nil noactp=nil
37 unset buildopts keyid
38 while getopts "haik:nt:" 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 -t TARGET Build in TARGET build environment.
51 EOF
52 exit 0
53 ;;
54 a) buildopts="${buildopts+$buildopts }-a" ;;
55 i) buildopts="${buildopts+$buildopts }-i" ;;
56 k) keyid=$OPTARG ;;
57 n) buildopts="${buildopts+$buildopts }-n" noactp=t ;;
58 t) buildopts="${buildopts+$buildopts }-t$OPTARG" ;;
59 *) bogusp=t ;;
60 esac
61 done
62 shift $(( $OPTIND - 1 ))
63 case $# in
64 1) host=$1 ;;
65 *) bogusp=t ;;
66 esac
67 case $bogusp in t) fail_usage ;; esac
68
69 ###--------------------------------------------------------------------------
70 ### Main program.
71
72 ## Figure out the package name and version number.
73 unset pkg ver
74 while read tag value; do
75 case $tag in
76 Source:) pkg=$value ;;
77 Version:) ver=$value ;;
78 esac
79 done <<EOF
80 $(dpkg-parsechangelog)
81 EOF
82 case ${pkg+t} in t) ;; *) fail "can't figure out the package name" ;; esac
83 case ${ver+t} in t) ;; *) fail "can't figure out the package version" ;; esac
84
85 ## Build a Debian source package. If we're signing, use `dpkg-buildpackage'
86 ## for this so that we get an uploadable `_source.changes' file out the end
87 ## of it.
88 case ${keyid+t},$noactp in
89 t,nil)
90 dpkg-buildpackage -S -k"$keyid"
91 cd ..
92 ;;
93 *)
94 dir=$(pwd); base=${dir##*/}
95 cd ..
96 dpkg-source -b "$base"
97 ;;
98 esac
99 dsc=${pkg}_${ver}.dsc
100 [ -f "$dsc" ] || fail "where is my \`.dsc' file?"
101
102 builddir=$(ssh "$host" mdw-sbuild-server dir "$pkg/$ver")
103 dcmd rsync -a "$dsc" "$host:$builddir/"
104 set +e; ssh "$host" mdw-sbuild-server $buildopts build "$builddir"
105 rc=$?; set -e
106 rsync -a "$host:$builddir/" ./
107 case $rc in 0) ;; *) exit $rc ;; esac
108 case $?,${keyid+t},$noactp in
109 0,t,nil) debsign -k"$keyid" "${pkg}_${ver}_"*.changes ;;
110 esac