]> git.madduck.net Git - code/mbuild.git/blob - sbuild-wrapper.sh

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:

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