06787d36d59cafcbf89966504dc629ec7319818f
[dcp.git] / dcp-update
1 #!/bin/bash
2
3 set -e
4
5 usage() {
6     echo "usage: dcp-update [-Nh] REPODIR"
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-update: unknown option '$opt'" >&2
30         exit 1
31     fi
32 done
33
34 if [ $# -lt 1 ]; then
35     usage >&2
36     exit 1
37 fi
38
39 repodir="$1"
40 shift
41 if [[ "$repodir" != */* ]]; then
42     repodir="$defdir/${repodir}.git"
43 fi
44
45 if [ ! -d "$repodir" ]; then
46     echo "dcp-build: could not find $repodir" >&2
47     exit 1
48 fi
49
50 td="$(mktemp -d /tmp/dcp-XXXXXX)"
51 exec >"$td/log" 2>"$td/err"
52 dcp-runenv "$repodir" "$td"
53
54 lastrev="$(rungit rev-parse HEAD)"
55 (cd "$td"; control/update) || false
56 rungit checkout master
57 newrev="$(rungit rev-parse HEAD)"
58
59 echo "update: $lastrev -> $newrev"
60
61 if [ "$push" = y ]; then rungit push; fi
62
63 rm -rf "$td"