#!/bin/bash set -e usage() { echo "usage: dcp-update [-Nh] REPODIR" } rungit() { ( cd "$td/repo" git "$@" ) || false } defdir=/srv/dcp push=y while [ "${1:0:1}" = - ]; do opt="${1:1}" shift if [ "$opt" = N ]; then push=n shift elif [ "$opt" = h ]; then usage exit 0 else echo "dcp-update: unknown option '$opt'" >&2 exit 1 fi done if [ $# -lt 1 ]; then usage >&2 exit 1 fi repodir="$1" shift if [[ "$repodir" != */* ]]; then repodir="$defdir/${repodir}.git" fi if [ ! -d "$repodir" ]; then echo "dcp-build: could not find $repodir" >&2 exit 1 fi td="$(mktemp -d /tmp/dcp-XXXXXX)" exec >"$td/log" 2>"$td/err" dcp-runenv "$repodir" "$td" lastrev="$(rungit rev-parse HEAD)" (cd "$td"; control/update) || false rungit checkout master newrev="$(rungit rev-parse HEAD)" echo "update: $lastrev -> $newrev" if [ "$push" = y ]; then rungit push; fi rm -rf "$td"