madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

731e1bd78f5051d6fe21491cd140526dd2f87797
[code/mbuild.git] / sbuild-wrapper.sh
1 #!/bin/sh
2 #
3 #  - automate builds with sbuild and dinstall the result
4 #
5 # Copyright (c) 2008 martin f. krafft <madduck@debian.org>
6 # Released under the terms of the Artistic Licence 2.0.
7 #
8 set -eu
9
10 ME="${0##*/}"
11
12 BUILDDIR="$(mktemp -dt $ME.XXXXXXXX)"
13 trap "cd / && rm -R '$BUILDDIR'" 0
14
15 BUNDLE_DIR="${TMPDIR:-/tmp}"
16 TARGET_DIR="$PWD"
17 copy_back_files() {
18   echo "Copying files destined for $1 back to $TARGET_DIR..."
19   dcmd cp -v "$2" "$TARGET_DIR"
20 }
21 dinstall() {
22   copy_back_files "$@"
23 }
24 print_bundle_location() {
25   echo "Bundle available at $@ ."
26 }
27
28 KEYID=
29
30 MBUILDRCS="/etc/mbuild/rc $HOME/.mbuildrc $HOME/.mbuild/rc"
31 for rc in $MBUILDRCS; do
32   [ -r "$rc" ] && . "$rc"
33 done
34
35 if [ -z "$KEYID" ]; then
36   echo "E: \$KEYID is not defined in rc file." >&2
37   exit 1
38 fi
39
40 DEB_BUILD_ARCH="$(dpkg-architecture -qDEB_BUILD_ARCH)"
41
42 about()
43 {
44   echo "$ME -- wrapper for sbuild"
45   echo "Copyright © martin f. krafft <madduck@debian.org>"
46   echo "Released under the terms of the Artistic Licence 2.0"
47 }
48
49 usage()
50 {
51   about
52   echo
53   echo "Usage: $ME [options] [sbuild_options] file_source.changes"
54   echo
55   echo "Valid options are:"
56   cat <<-_eof | column -s\& -t
57         --dist & specify the target distribution (default: sid)
58         --arch & specify the target architecture (default: $DEB_BUILD_ARCH)
59         -h|--help & show this output.
60         -V|--version & show version information.
61         _eof
62 }
63
64 sbuild_args=
65 schangesfile=
66 arch=
67 dist=
68 for opt in "$@"; do
69   case "$opt" in
70     -h|--help) usage; exit 0;;
71     -V|--version) about; exit 0;;
72     --arch=*) arch="${opt#--arch=}";;
73     --dist=*) dist="${opt#--dist=}";;
74     -sa) sbuild_args="${sbuild_args:+$sbuild_args }--force-orig-source";;
75     --*) sbuild_args="${sbuild_args:+$sbuild_args }$opt";;
76     *_source.changes)
77       if [ -z "$schangesfile" ]; then
78         if [ -f "$opt" ] && [ -r "$opt" ]; then
79           schangesfile="$opt"
80         else
81           echo "E: file does not exist: $opt" >&2
82           exit 1
83         fi
84       else
85         echo "E: cannot pass more than one source changes file: $opt" >&2
86         exit 1
87       fi
88       ;;
89     *)
90       echo "E: unknown option: $opt" >&1
91       exit 1
92       ;;
93   esac
94 done
95
96 if [ -z "$schangesfile" ]; then
97   usage
98   exit 1
99 fi
100
101 [ -z "$arch" ] && arch="$DEB_BUILD_ARCH"
102 [ -z "$dist" ] && dist="unstable"
103
104 schangesfile_basename="${schangesfile##*/}"
105 packagenameversion="${schangesfile_basename%_*}"
106
107 case "$schangesfile" in
108   */*) cd "${schangesfile%/*}";;
109   *) :;;
110 esac
111 dcmd cp "${schangesfile##*/}" "$BUILDDIR"
112 schangesfile="$schangesfile_basename"
113
114 cd "$BUILDDIR"
115
116 sbuild $sbuild_args --arch="$arch" --arch-all --dist="$dist" --keyid=$KEYID \
117   "$packagenameversion".dsc
118
119 changesfile="${packagenameversion}_${arch}.changes"
120
121 mv "$changesfile" "${changesfile}.binonly"
122 mergechanges "$schangesfile" "${changesfile}.binonly" > "$changesfile"
123 rm "${changesfile}.binonly" "$schangesfile"
124
125 #TODO sign here
126
127 dinstall "$dist" "$changesfile"
128
129 DATESTR="$(date +%Y.%m.%d.%H%M%S)"
130 BUILD_PREFIX="${packagenameversion}_${arch}.${DATESTR}"
131
132 mv current "${BUILD_PREFIX}".buildlog
133 rm -f current-*
134
135 bundle="${BUNDLE_DIR}/${BUILD_PREFIX}".bundle.tar
136 tar -chf "$bundle" *
137 chmod 644 "$bundle"
138
139 rm -r "$BUILDDIR"
140 trap - 0
141
142 print_bundle_location "$bundle"
143
144 exit 0