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

improve bundle creation
[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 cd "$BUILDDIR"
34
35 sbuild_args=
36 schangesfile=
37 arch=
38 dist=
39 for opt in "$@"; do
40   case "$opt" in
41     --arch=*) arch="${opt#--arch=}";;
42     --dist=*) dist="${opt#--dist=}";;
43     -sa) sbuild_args="${sbuild_args:+$sbuild_args }--force-orig-source";;
44     --*) sbuild_args="${sbuild_args:+$sbuild_args }$opt";;
45     *_source.changes)
46       if [ -z "$schangesfile" ]; then
47         if [ -f "$opt" ] && [ -r "$opt" ]; then
48           schangesfile="$opt"
49         else
50           echo "E: file does not exist: $opt" >&2
51           exit 1
52         fi
53       else
54         echo "E: cannot pass more than one source changes file: $opt" >&2
55         exit 1
56       fi
57       ;;
58     *)
59       echo "E: unknown option: $opt" >&1
60       exit 1
61       ;;
62   esac
63 done
64
65 schangesfile_basename="${schangesfile##*/}"
66 packagenameversion="${schangesfile_basename%_*}"
67
68 cd "${schangesfile%/*}"
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