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

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