]> git.madduck.net Git - code/mbuild.git/blob - mbuild.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:

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