Initial import.
[dcp.git] / dcp-build
1 #!/bin/sh
2
3 set -e
4
5 usage() {
6     echo "usage: dcp-build [-Nh] REPODIR OUTDIR"
7 }
8
9 rungit() {
10     (
11         cd "$td/repo"
12         git "$@"
13     ) || false
14 }
15
16 defdir=/srv/dcp
17 push=y
18
19 while [ "${1:0:1}" = - ]; do
20     opt="${1:1}"
21     shift
22     if [ "$opt" = N ]; then
23         push=n
24         shift
25     elif [ "$opt" = h ]; then
26         usage
27         exit 0
28     else
29         echo "dcp-build: unknown option '$opt'" >&2
30         exit 1
31     fi
32 done
33
34 if [ $# -lt 2 ]; then
35     usage >&2
36     exit 1
37 fi
38
39 repodir="$1"
40 outdir="$2"
41 shift 2
42 if [[ "$repodir" != */* ]]; then
43     repodir="$defdir/${repodir}.git"
44 fi
45
46 if [ ! -d "$repodir" ]; then
47     echo "dcp-build: could not find $repodir" >&2
48     exit 1
49 fi
50 if [ ! -d "$outdir" ]; then
51     echo "dcp-build: could not find $outdir" >&2
52     exit 1
53 fi
54
55 td="$(mktemp -d /tmp/dcp-XXXXXX)"
56 exec >"$td/log" 2>"$td/err"
57 dcp-runenv "$repodir" "$td"
58
59 rungit tag -f lastbuild
60 (cd "$td"; control/build) || false
61 cp -a "$td/output"/* "$outdir/"
62
63 if [ "$push" = y ]; then rungit push --tags; fi
64
65 rm -rf "$td"