All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 # - automate builds with sbuild and dinstall the result
5 # Copyright (c) 2008–2010 martin f. krafft <madduck@debian.org>
6 # Released under the terms of the Artistic Licence 2.0.
12 BUILDDIR="$(mktemp -dt $ME.XXXXXXXX)"
14 cd /tmp && rm -r "$BUILDDIR"
15 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
17 trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15
19 BUNDLE_DIR="${TMPDIR:-/tmp}"
22 echo "Copying files destined for $1 back to $TARGET_DIR..."
23 dcmd cp -v "$2" "$TARGET_DIR"
28 print_bundle_location() {
29 echo "Bundle available at $@ ."
37 MBUILDRCS="/etc/mbuild/rc $HOME/.mbuildrc $HOME/.mbuild/rc"
38 for rc in $MBUILDRCS; do
39 [ -r "$rc" ] && . "$rc"
42 if [ -z "$KEYID" ]; then
43 echo "E: \$KEYID is not defined in rc file." >&2
47 DEB_BUILD_ARCH="$(dpkg-architecture -qDEB_BUILD_ARCH)"
51 echo "$ME -- wrapper for sbuild"
52 echo "Copyright © martin f. krafft <madduck@debian.org>"
53 echo "Released under the terms of the Artistic Licence 2.0"
60 echo "Usage: $ME [options] [sbuild_options] file_source.changes"
62 echo "Valid options are:"
63 cat <<-_eof | column -s\& -t
64 --dist & specify the target distribution (default: from changes file)
65 --arch & specify the target architecture (default: $DEB_BUILD_ARCH)
66 -sa & pass --force-orig-source to sbuild
67 -B & do a binary-only build
68 -h|--help & show this output.
69 -V|--version & show version information.
75 sbuild_args_sourceful=
80 -h|--help) usage; exit 0;;
81 -V|--version) about; exit 0;;
82 --arch=*) arch="${opt#--arch=}";;
83 -D) sbuild_args="${sbuild_args:+$sbuild_args }$opt";;
84 -sa) sbuild_args="${sbuild_args:+$sbuild_args }--force-orig-source";;
86 --*) sbuild_args="${sbuild_args:+$sbuild_args }$opt";;
88 if [ -z "$schangesfile" ]; then
89 if [ -f "$opt" ] && [ -r "$opt" ]; then
92 echo "E: file does not exist: $opt" >&2
96 echo "E: cannot pass more than one source changes file: $opt" >&2
101 echo "E: unknown option: $opt" >&2
107 if [ -z "$schangesfile" ]; then
112 [ -z "$arch" ] && arch="$DEB_BUILD_ARCH"
114 dist="$(sed -ne 's,Distribution: ,,p' "$schangesfile")"
116 schangesfile_basename="${schangesfile##*/}"
117 packagename="${schangesfile_basename%%_*}"
118 packagenameversion="${schangesfile_basename%_*}"
119 debversion="${packagenameversion#*_}"
120 upstream_version="${debversion%-*}"
121 dscfile_basename="$packagenameversion".dsc
123 case "$schangesfile" in
124 */*) cd "${schangesfile%/*}";;
127 dcmd cp "${schangesfile##*/}" "$BUILDDIR"
128 schangesfile="$schangesfile_basename"
133 dcmd "$dscfile_basename" | while read f; do
134 test -f "$f" && continue
137 *.tar.gz|*.tar.bz2|*.tar.lzma|*.tar.xz)
138 if [ -f "$OLDPWD/$f" ]; then
139 echo "I: using existing tarball for $upstream_version…" >&2
142 last_version="$(apt-cache madison $packagename | sed -rne "s,.+(\<${upstream_version}[^[:space:]]+).*,\1,p")"
143 echo "I: fetching missing tarball for $upstream_version (from $last_version)…" >&2
144 if ! apt-get --tar-only --only-source source "${packagename}=${last_version}"; then
145 echo "E: I do not know how to obtain the file: $f" >&2
151 echo "E: I do not know how to obtain the file: $f" >&2
160 if [ "$binonly" = 0 ]; then
161 sbuild_args_sourceful="--source --arch-all"
164 if [ "$arch" = all ]; then
165 arch="$(schroot -l | sed -rne 's,^sid-([^-]+).*,\1,p' | uniq | tr '\n' ' ')"
169 echo "I: building $packagenameversion for $a/$dist…" >&2
171 sbuild $sbuild_args $sbuild_args_sourceful \
172 --arch="$a" --dist="$dist" --keyid=$KEYID \
175 changesfile="${packagenameversion}_${a}.changes"
177 if [ -n "$sbuild_args_sourceful" ]; then
178 schangesfile="${packagenameversion}_source+${changesfile#${packagenameversion}_}"
179 mv "$changesfile" "$schangesfile"
180 changesfile="$schangesfile"
183 # subsequent iterations should be binonly
184 sbuild_args_sourceful=
186 echo "I: running post-build hook ($packagenameversion/$a/$dist)…" >&2
187 postbuild "$dist" "$a" "$changesfile"
188 echo "I: running dinstall ($packagenameversion/$a/$dist)…" >&2
189 dinstall "$dist" "$changesfile"
191 echo "I: done building $packagenameversion for $a/$dist" >&2
194 if [ -n "${schangesfile:-}" ]; then
195 sarch="${schangesfile##*_}"; sarch=${sarch%.changes}
196 combined_arch="$(echo -n "${sarch}+";
197 for i in *.changes; do
198 [ "$i" = "$schangesfile" ] && continue
199 t="${i##*_}"; echo "${t%.changes}"
202 if [ -n "$combined_arch" ]; then
203 mergechanges *.changes > ${packagenameversion}_${combined_arch}.changes
204 arch="$combined_arch"
208 bundle="${BUNDLE_DIR}/${packagenameversion}_${arch}_bundle.tar.gz"
209 tar -chzf "$bundle" *
211 print_bundle_location "$bundle"