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

bca4840ffab6024225028a53657ae4ed4b88a5ee
[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 [ -z "$arch" ] && arch="$(dpkg-architecture -qDEB_BUILD_ARCH)"
63 [ -z "$dist" ] && dist="sid"
64
65 schangesfile_basename="${schangesfile##*/}"
66 packagenameversion="${schangesfile_basename%_*}"
67
68 case "$schangesfile" in
69   */*) cd "${schangesfile%/*}";;
70   *) :;;
71 esac
72 dcmd cp "${schangesfile##*/}" "$BUILDDIR"
73 schangesfile="$schangesfile_basename"
74
75 cd "$BUILDDIR"
76
77 sbuild $sbuild_args --arch="$arch" --arch-all --dist="$dist" --keyid=$KEYID \
78   "$packagenameversion".dsc
79
80 changesfile="${packagenameversion}_${arch}.changes"
81
82 dinstall "$dist" "$schangesfile"
83 dinstall "$dist" "$changesfile"
84
85 mv "$changesfile" "${changesfile}.binonly"
86 mergechanges "$schangesfile" "${changesfile}.binonly" > "$changesfile"
87 rm "${changesfile}.binonly" "$schangesfile"
88
89 DATESTR="$(date +%Y.%m.%d.%H%M%S)"
90 BUILD_PREFIX="${packagenameversion}_${arch}.${DATESTR}"
91
92 mv current "${BUILD_PREFIX}".buildlog
93 rm -f current-*
94
95 bundle="${BUNDLE_DIR}/${BUILD_PREFIX}".bundle.tar
96 tar -chf "$bundle" *
97
98 rm -r "$BUILDDIR"
99 trap - 0
100
101 echo "Bundle available at $bundle ."
102
103 exit 0