--- /dev/null
+#!/bin/sh
+
+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"
--- /dev/null
+#!/bin/bash
+
+set -e
+
+usage() {
+ echo "usage: dcp-init [-C key=val] [-d REPODIR] PACKAGE [PATCH...]"
+ echo " PATCH ::= [-p LEVEL] [-bB BRANCH] FILE"
+ echo " -b creates a new branch at the current patch"
+ echo " -B creates a new branch at the upstream sources"
+}
+
+rungit() {
+ (
+ cd "$td"
+ git "$@"
+ ) || false
+}
+
+getaptsrc() {
+ mkdir "$td/apt-tmp"
+ (cd "$td/apt-tmp"; apt-get source "$1") || false
+
+ echo Achtung
+ sleep 10
+
+ sdir=
+ for f in "$td/apt-tmp"/*; do
+ if [ -d "$f" ]; then
+ if [ -z "$sdir" ]; then
+ sdir="$f"
+ else
+ echo "dcp-init: got more than one directory from apt-get; cannot continue" >&2
+ exit 1
+ fi
+ fi
+ done
+ if [ -z "$sdir" ]; then
+ echo "dcp-init: could not find any source directory" >&2
+ exit 1
+ fi
+ mv "$sdir" "$td/src"
+ rm -rf "$td/apt-tmp"
+
+ rungit add src
+}
+
+initrepo() {
+ rungit init -q
+ mkdir "$td/control"
+ touch "$td/control/conf"
+ rungit add control
+ rungit commit -q -m "Initial repo"
+ rungit tag empty
+}
+
+initbase() {
+ mkdir "$td/control/build.d"
+ mkdir "$td/control/update.d"
+ cat >"$td/control/functions" <<EOF
+readconf() {
+ while read key val; do
+ export "CONF_\$key"="\$val"
+ done <control/conf
+}
+
+rungit() {
+ (cd repo; git "\$@") || false
+}
+EOF
+ cat >"$td/control/build" <<EOF
+#!/bin/sh
+
+set -e
+
+. control/functions
+readconf
+
+for file in control/build.d/*; do
+ if [ -x "\$file" ]; then "\$file"; fi
+done
+EOF
+ chmod 755 "$td/control/build"
+ cat >"$td/control/update" <<EOF
+#!/bin/sh
+
+set -e
+
+. control/functions
+readconf
+
+for branch in repo/.git/refs/heads/*; do
+ branch="\${branch##*/}"
+ if [ -x "control/update.d/\$branch" ]; then
+ rungit checkout "\$branch"
+ lastrev="\$(rungit rev-parse HEAD)"
+ "control/update.d/\$branch"
+ newrev="\$(rungit rev-parse HEAD)"
+ rungit checkout master
+ if [ "\$newrev" != "\$lastrev" ]; then
+ rungit merge -n "\$branch"
+ fi
+ fi
+done
+EOF
+ chmod 755 "$td/control/update"
+ rungit add control
+}
+
+initapt() {
+ cat >"$td/control/build.d/99dpkg" <<EOF
+#!/bin/bash
+
+set -e
+
+cmd=(dpkg-buildpackage -b)
+if [ -n "\$CONF_MAINTAINER" ]; then
+ cmd=("\${cmd[@]}" "-m\$CONF_MAINTAINER")
+fi
+if [ -n "\$CONF_GPGKEY" ]; then
+ cmd=("\${cmd[@]}" "-k\$CONF_GPGKEY")
+fi
+(cd repo/src; "\${cmd[@]}") || false
+mv repo/*.deb output/
+EOF
+ chmod 755 "$td/control/build.d/99dpkg"
+ rungit add control/build.d/99dpkg
+ cat >"$td/control/update.d/upstream" <<EOF
+#!/bin/sh
+
+set -e
+
+cd repo
+dcp-update-apt "\$CONF_APTPKG"
+
+EOF
+ chmod 755 "$td/control/update.d/upstream"
+ rungit add control/update.d/upstream
+ echo "APTPKG $pkg" >>"$td/control/conf"
+ rungit add control/conf
+}
+
+defdir=/srv/dcp
+repodir=
+confopts=()
+
+while [ "${1:0:1}" = - ]; do
+ opt="${1:1}"
+ shift
+ if [ "$opt" = d ]; then
+ repodir="$1"
+ shift
+ elif [ "$opt" = h ]; then
+ usage
+ exit 0
+ elif [ "$opt" = C ]; then
+ confopts=("${confopts[@]}" "$1")
+ shift
+ else
+ echo "dcp-init: unknown option '$opt'" >&2
+ exit 1
+ fi
+done
+
+if [ $# -lt 1 ]; then
+ usage >&2
+ exit 1
+fi
+pkg="$1"
+shift
+if [ -z "$repodir" ]; then repodir="$pkg"; fi
+if [[ "$repodir" != */* ]]; then
+ repodir="$defdir/${repodir}.git"
+fi
+
+td="$(mktemp -d "/tmp/dcp-XXXXXX")"
+initrepo
+
+initbase
+rungit commit -q -m "Base control files"
+
+if [ "${#confopts[@]}" -gt 0 ]; then
+ for opt in "${confopts[@]}"; do
+ key="${opt%%=*}"
+ val="${opt#*=}"
+ echo "$key $val" >>"$td/control/conf"
+ done
+ rungit add control/conf
+ rungit commit -q -m "Custom configuration file"
+fi
+
+rungit checkout -q -b upstream empty
+getaptsrc "$pkg"
+rungit commit -q -m "Initial upstream import"
+rungit checkout master
+rungit merge -n upstream
+
+initapt
+rungit commit -q -m "APT control files"
+
+initvals() {
+ level=0
+}
+initvals
+while [ $# -gt 0 ]; do
+ arg="$1"
+ shift
+ if [ "${arg:0:1}" = - ]; then
+ if [ "$arg" = -p ]; then
+ level="$1"
+ shift
+ elif [ "$arg" = -b ]; then
+ rungit checkout -q -b "$1"
+ shift
+ elif [ "$arg" = -B ]; then
+ rungit checkout -q -b "$1" upstream
+ else
+ echo "dcp-init: unknown patch option '$arg'" >&2
+ exit 1
+ fi
+ else
+ (
+ if [[ "$arg" == *.gz ]]; then
+ zcat "$arg"
+ else
+ cat "$arg"
+ fi
+ ) | patch -d "$td/src" -p"$level"
+ rungit add src
+ rungit commit -q -m "Applied $(basename "$arg")"
+ initvals
+ fi
+done
+
+git clone -q --bare "$td" "$repodir"
+
+rm -rf "$td"
--- /dev/null
+#!/bin/sh
+
+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"