#!/bin/bash set -e usage() { echo "usage: dcp-build [-Nh] REPODIR OUTDIR" } 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-build: unknown option '$opt'" >&2 exit 1 fi done if [ $# -lt 2 ]; then usage >&2 exit 1 fi repodir="$1" outdir="$2" shift 2 if [[ "$repodir" != */* ]]; then repodir="$defdir/${repodir}.git" fi if [ ! -d "$repodir" ]; then echo "dcp-build: could not find $repodir" >&2 exit 1 fi if [ ! -d "$outdir" ]; then echo "dcp-build: could not find $outdir" >&2 exit 1 fi td="$(mktemp -d /tmp/dcp-XXXXXX)" exec >"$td/log" 2>"$td/err" dcp-runenv "$repodir" "$td" rungit tag -f lastbuild (cd "$td"; control/build) || false cp -a "$td/output"/* "$outdir/" if [ "$push" = y ]; then rungit push --tags; fi rm -rf "$td"