Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
abfec703 | 36 | bogusp=nil noactp=nil signp=nil |
5e9e7146 MW |
37 | unset buildopts pkgs dbpargs |
38 | while getopts "haik:np:t:A:" opt; do | |
b94830d9 MW |
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. | |
6cf97414 | 50 | -p DIR Upload additional packages from DIR. |
b94830d9 | 51 | -t TARGET Build in TARGET build environment. |
5e9e7146 | 52 | -A ARGS Pass ARGS to \`dpkg-buildpackage'. |
b94830d9 MW |
53 | EOF |
54 | exit 0 | |
55 | ;; | |
56 | a) buildopts="${buildopts+$buildopts }-a" ;; | |
57 | i) buildopts="${buildopts+$buildopts }-i" ;; | |
8c67a535 | 58 | k) signp=t keyid=$OPTARG ;; |
b94830d9 | 59 | n) buildopts="${buildopts+$buildopts }-n" noactp=t ;; |
6cf97414 | 60 | p) pkgs=$OPTARG ;; |
b94830d9 | 61 | t) buildopts="${buildopts+$buildopts }-t$OPTARG" ;; |
5e9e7146 MW |
62 | A) |
63 | buildopts="${buildopts+$buildopts }-A$OPTARG" | |
64 | dbpargs="${dbpargs+$dbpargs }$OPTARG" | |
65 | ;; | |
b94830d9 MW |
66 | *) bogusp=t ;; |
67 | esac | |
68 | done | |
69 | shift $(( $OPTIND - 1 )) | |
70 | case $# in | |
71 | 1) host=$1 ;; | |
72 | *) bogusp=t ;; | |
73 | esac | |
74 | case $bogusp in t) fail_usage ;; esac | |
8c67a535 | 75 | case $noactp in t) signp=nil ;; esac |
6cf97414 | 76 | case ${pkgs-/hack} in /*) ;; *) pkgs=$(pwd)/$pkgs ;; esac |
b94830d9 MW |
77 | |
78 | ###-------------------------------------------------------------------------- | |
79 | ### Main program. | |
80 | ||
81 | ## Figure out the package name and version number. | |
82 | unset pkg ver | |
83 | while read tag value; do | |
84 | case $tag in | |
85 | Source:) pkg=$value ;; | |
86 | Version:) ver=$value ;; | |
87 | esac | |
88 | done <<EOF | |
89 | $(dpkg-parsechangelog) | |
90 | EOF | |
91 | case ${pkg+t} in t) ;; *) fail "can't figure out the package name" ;; esac | |
92 | case ${ver+t} in t) ;; *) fail "can't figure out the package version" ;; esac | |
93 | ||
8c67a535 MW |
94 | ## Build a Debian source package. Don't sign anything yet. That will happen |
95 | ## at the end, all in one go. | |
5e9e7146 | 96 | dpkg-buildpackage -S -uc -us -d -i $dbpargs |
8c67a535 | 97 | cd .. |
b94830d9 MW |
98 | dsc=${pkg}_${ver}.dsc |
99 | [ -f "$dsc" ] || fail "where is my \`.dsc' file?" | |
100 | ||
97720cf5 MW |
101 | ## Actually do the build. Get a build directory assigned by the server, |
102 | ## upload the sources, run the build, and collect the results. | |
b94830d9 MW |
103 | builddir=$(ssh "$host" mdw-sbuild-server dir "$pkg/$ver") |
104 | dcmd rsync -a "$dsc" "$host:$builddir/" | |
6cf97414 | 105 | case ${pkgs+t} in t) rsync -a "$pkgs/" "$host:$builddir/pkgs/" ;; esac |
b94830d9 MW |
106 | set +e; ssh "$host" mdw-sbuild-server $buildopts build "$builddir" |
107 | rc=$?; set -e | |
108 | rsync -a "$host:$builddir/" ./ | |
109 | case $rc in 0) ;; *) exit $rc ;; esac | |
97720cf5 | 110 | |
bcd2df0a MW |
111 | ## Merge the change files together, and maybe sign the result. |
112 | chchch=${pkg}_${ver}_source.changes | |
113 | for i in "${pkg}_${ver}"_*.changes; do | |
114 | case " $chchch " in *" $i "*) ;; *) chchch="$chchch $i" ;; esac | |
115 | done | |
116 | mergechanges -f $chchch | |
117 | rm $chchch | |
abfec703 | 118 | case $signp in |
bcd2df0a | 119 | t) debsign -k"$keyid" "${pkg}_${ver}_multi.changes" ;; |
b94830d9 | 120 | esac |
5e9e7146 MW |
121 | |
122 | ###----- That's all, folks -------------------------------------------------- |