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