Updated control files for adding changelog entries.
[dcp.git] / dcp-init
index 7bd3d7e..f8f3667 100755 (executable)
--- a/dcp-init
+++ b/dcp-init
@@ -3,10 +3,11 @@
 set -e
 
 usage() {
-    echo "usage: dcp-init [-C key=val] [-d REPODIR] PACKAGE [PATCH...]"
+    echo "usage: dcp-init [-sh] [-C key=val] [-d REPODIR] PACKAGE [(PATCH|-m)...]"
     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"
+    echo "       -m merges the current branch into the master branch"
 }
 
 rungit() {
@@ -20,9 +21,6 @@ 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
@@ -45,7 +43,7 @@ getaptsrc() {
 }
 
 initrepo() {
-    rungit init -q
+    rungit init
     mkdir "$td/control"
     touch "$td/control/conf"
     rungit add control
@@ -58,6 +56,16 @@ initbase() {
     mkdir "$td/control/update.d"
     cat >"$td/control/functions" <<EOF
 readconf() {
+    if [ -r "\$HOME/.dcp-build-conf" ]; then
+        while read key val; do
+            export "CONF_\$key"="\$val"
+        done <"\$HOME/.dcp-build-conf"
+    fi
+    if [ -r "/etc/dcp-conf" ]; then
+        while read key val; do
+            export "CONF_\$key"="\$val"
+        done <"/etc/dcp-conf"
+    fi
     while read key val; do
         export "CONF_\$key"="\$val"
     done <control/conf
@@ -66,6 +74,24 @@ readconf() {
 rungit() {
     (cd repo; git "\$@") || false
 }
+
+logchange() {
+    tag="\${CONF_VERTAG:-dcp}"
+    ver="\$(dpkg-parsechangelog -lrepo/src/debian/changelog | sed -n 's/^Version: \(.*\)$/\1/p')"
+    [ -n "\$ver" ]
+    maint="\$CONF_MAINTAINER"
+    if [ -z "\$maint" ]; then
+        maint="\$(id -un) <\$(id -un)@\$(hostname -f)>"
+    fi
+    cat - repo/src/debian/changelog >repo/src/debian/changelog.new <<ENDCL
+\${CONF_APTPKG} (\${ver}+\${tag}1) unstable; urgency=low
+  
+  * Remerged changes in DCP
+
+ -- \${maint}  \$(date -R)
+ENDCL
+    mv -f repo/src/debian/changelog.new repo/src/debian/changelog
+}
 EOF
     cat >"$td/control/build" <<EOF
 #!/bin/sh
@@ -88,6 +114,7 @@ set -e
 . control/functions
 readconf
 
+updated=n
 for branch in repo/.git/refs/heads/*; do
     branch="\${branch##*/}"
     if [ -x "control/update.d/\$branch" ]; then
@@ -98,9 +125,16 @@ for branch in repo/.git/refs/heads/*; do
         rungit checkout master
         if [ "\$newrev" != "\$lastrev" ]; then
             rungit merge -n "\$branch"
+            updated=y
         fi
     fi
 done
+
+if [ "\$updated" = y ]; then
+    for file in control/update.d/post-*; do
+        if [ -x "\$file" ]; then "\$file"; fi
+    done
+fi
 EOF
     chmod 755 "$td/control/update"
     rungit add control
@@ -112,7 +146,7 @@ initapt() {
 
 set -e
 
-cmd=(dpkg-buildpackage -b)
+cmd=(dpkg-buildpackage -b -rfakeroot)
 if [ -n "\$CONF_MAINTAINER" ]; then
     cmd=("\${cmd[@]}" "-m\$CONF_MAINTAINER")
 fi
@@ -129,12 +163,24 @@ EOF
 
 set -e
 
+. control/functions
+
 cd repo
 dcp-update-apt "\$CONF_APTPKG"
-
 EOF
     chmod 755 "$td/control/update.d/upstream"
     rungit add control/update.d/upstream
+    cat >"$td/control/update.d/post-logchange" <<EOF
+#!/bin/sh
+
+set -e
+. control/functions
+
+logchange
+rungit add src/debian/changelog
+rungit commit -q -m "Added changelog entry"
+
+EOF
     echo "APTPKG $pkg" >>"$td/control/conf"
     rungit add control/conf
 }
@@ -142,6 +188,7 @@ EOF
 defdir=/srv/dcp
 repodir=
 confopts=()
+shared=n
 
 while [ "${1:0:1}" = - ]; do
     opt="${1:1}"
@@ -152,6 +199,8 @@ while [ "${1:0:1}" = - ]; do
     elif [ "$opt" = h ]; then
        usage
        exit 0
+    elif [ "$opt" = s ]; then
+       shared=y
     elif [ "$opt" = C ]; then
        confopts=("${confopts[@]}" "$1")
        shift
@@ -201,6 +250,7 @@ initvals() {
     level=0
 }
 initvals
+curbranch=master
 while [ $# -gt 0 ]; do
     arg="$1"
     shift
@@ -209,10 +259,16 @@ while [ $# -gt 0 ]; do
            level="$1"
            shift
        elif [ "$arg" = -b ]; then
-           rungit checkout -q -b "$1"
+           curbranch="$1"
            shift
+           rungit checkout -q -b "$curbranch"
        elif [ "$arg" = -B ]; then
-           rungit checkout -q -b "$1" upstream
+           curbranch="$1"
+           shift
+           rungit checkout -q -b "$curbranch" upstream
+       elif [ "$arg" = -m ]; then
+           rungit checkout -q master
+           rungit merge -n "$curbranch"
        else
            echo "dcp-init: unknown patch option '$arg'" >&2
            exit 1
@@ -232,5 +288,9 @@ while [ $# -gt 0 ]; do
 done
 
 git clone -q --bare "$td" "$repodir"
+if [ "$shared" = y ]; then
+    chmod -R g+w "$repodir"
+    td="$repodir" rungit config core.sharedrepository 1
+fi
 
 rm -rf "$td"