bin/mdw-sbuild: Add some section-header comments.
[profile] / bin / mdw-sbuild
CommitLineData
b94830d9
MW
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
27prog=${0##*/}
28
29fail () { echo >&2 "$prog: $*"; exit 1; }
30usage () { echo "usage: $prog [-ain] [-k KEYID] [-t TARGET] HOST"; }
31fail_usage () { usage >&2; exit 1; }
32
33###--------------------------------------------------------------------------
34### Parse options.
35
36bogusp=nil noactp=nil
37unset buildopts keyid
38while getopts "haik:nt:" opt; do
39 case $opt in
40 h)
41 usage
42 cat <<EOF
43
44Options:
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.
51EOF
52 exit 0
53 ;;
54 a) buildopts="${buildopts+$buildopts }-a" ;;
55 i) buildopts="${buildopts+$buildopts }-i" ;;
8c67a535 56 k) signp=t keyid=$OPTARG ;;
b94830d9
MW
57 n) buildopts="${buildopts+$buildopts }-n" noactp=t ;;
58 t) buildopts="${buildopts+$buildopts }-t$OPTARG" ;;
59 *) bogusp=t ;;
60 esac
61done
62shift $(( $OPTIND - 1 ))
63case $# in
64 1) host=$1 ;;
65 *) bogusp=t ;;
66esac
67case $bogusp in t) fail_usage ;; esac
8c67a535 68case $noactp in t) signp=nil ;; esac
b94830d9
MW
69
70###--------------------------------------------------------------------------
71### Main program.
72
73## Figure out the package name and version number.
74unset pkg ver
75while read tag value; do
76 case $tag in
77 Source:) pkg=$value ;;
78 Version:) ver=$value ;;
79 esac
80done <<EOF
81$(dpkg-parsechangelog)
82EOF
83case ${pkg+t} in t) ;; *) fail "can't figure out the package name" ;; esac
84case ${ver+t} in t) ;; *) fail "can't figure out the package version" ;; esac
85
8c67a535
MW
86## Build a Debian source package. Don't sign anything yet. That will happen
87## at the end, all in one go.
88dpkg-buildpackage -S -uc -us
89cd ..
b94830d9
MW
90dsc=${pkg}_${ver}.dsc
91[ -f "$dsc" ] || fail "where is my \`.dsc' file?"
92
97720cf5
MW
93## Actually do the build. Get a build directory assigned by the server,
94## upload the sources, run the build, and collect the results.
b94830d9
MW
95builddir=$(ssh "$host" mdw-sbuild-server dir "$pkg/$ver")
96dcmd rsync -a "$dsc" "$host:$builddir/"
97set +e; ssh "$host" mdw-sbuild-server $buildopts build "$builddir"
98rc=$?; set -e
99rsync -a "$host:$builddir/" ./
100case $rc in 0) ;; *) exit $rc ;; esac
97720cf5
MW
101
102## Maybe sign the result.
b94830d9
MW
103case $?,${keyid+t},$noactp in
104 0,t,nil) debsign -k"$keyid" "${pkg}_${ver}_"*.changes ;;
105esac