]> 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:

fix quoting of bundle filename
[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 BUILDDIR="$(mktemp -dt mbuild.XXXXXXXX)"
11 trap "cd / && rm -R '$BUILDDIR'" 0
12
13 BUNDLE_DIR="${TMPDIR:-/tmp}"
14 dinstall() {
15   echo "Would install into $1:"
16   for file in $(dcmd echo "$2"); do
17     echo "  $file"
18   done
19 }
20
21 KEYID=
22
23 MBUILDRCS="/etc/mbuild/rc $HOME/.mbuildrc $HOME/.mbuild/rc"
24 for rc in $MBUILDRCS; do
25   [ -r "$rc" ] && . "$rc"
26 done
27
28 if [ -z "$KEYID" ]; then
29   echo "E: \$KEYID is not defined in rc file." >&2
30   exit 1
31 fi
32
33 sbuild_args=
34 schangesfile=
35 arch=
36 dist=
37 for opt in "$@"; do
38   case "$opt" in
39     --arch=*) arch="${opt#--arch=}";;
40     --dist=*) dist="${opt#--dist=}";;
41     -sa) sbuild_args="${sbuild_args:+$sbuild_args }--force-orig-source";;
42     --*) sbuild_args="${sbuild_args:+$sbuild_args }$opt";;
43     *_source.changes)
44       if [ -z "$schangesfile" ]; then
45         if [ -f "$opt" ] && [ -r "$opt" ]; then
46           schangesfile="$opt"
47         else
48           echo "E: file does not exist: $opt" >&2
49           exit 1
50         fi
51       else
52         echo "E: cannot pass more than one source changes file: $opt" >&2
53         exit 1
54       fi
55       ;;
56     *)
57       echo "E: unknown option: $opt" >&1
58       exit 1
59       ;;
60   esac
61 done
62
63 schangesfile_basename="${schangesfile##*/}"
64 packagenameversion="${schangesfile_basename%_*}"
65
66 case "$schangesfile" in
67   */*) cd "${schangesfile%/*}";;
68   *) :;;
69 esac
70 dcmd cp "${schangesfile##*/}" "$BUILDDIR"
71 schangesfile="$schangesfile_basename"
72
73 cd "$BUILDDIR"
74
75 sbuild $sbuild_args --arch="$arch" --arch-all --dist="$dist" --keyid=$KEYID \
76   "$packagenameversion".dsc
77
78 changesfile="${packagenameversion}_${arch}.changes"
79
80 dinstall "$dist" "$schangesfile"
81 dinstall "$dist" "$changesfile"
82
83 mv "$changesfile" "${changesfile}.binonly"
84 mergechanges "$schangesfile" "${changesfile}.binonly" > "$changesfile"
85 rm "${changesfile}.binonly" "$schangesfile"
86
87 DATESTR="$(date +%Y.%m.%d.%H%M%S)"
88 BUILD_PREFIX="${packagenameversion}_${arch}.${DATESTR}"
89
90 mv current "${BUILD_PREFIX}".buildlog
91 rm -f current-*
92
93 bundle="${BUNDLE_DIR}/${BUILD_PREFIX}".bundle.tar
94 tar -chf "$bundle" *
95
96 rm -r "$BUILDDIR"
97 trap - 0
98
99 echo "Bundle available at $bundle ."
100
101 exit 0