#!/bin/bash
#
# update-chagelogs.sh
# 
# Copyright (C) 2006  Josef Kufner <jk@myserver.cz>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# 

major_ver=2
rev=$(svn info | awk '$1 == "Revision:" {print $2}')
username="Josef Kufner <jk@myserver.cz>"

# after commit it will be ok, then pack packages
rev=$(( $rev + 1 ))

for d in */
do
	[ -d $d/debian ] && (
		cd $d ; pwd >&2
		lastrev=$(sed -n '1s/^.*([0-9]\+\.\(.*\)-[0-9]\+).*$/\1/p' debian/changelog)
		if [ "$( svn diff -r HEAD:$lastrev | wc -l )" -ne 0 ]
		then
			new=$(
				echo "$(basename $d) ($major_ver.$rev-1) unstable; urgency=low"
				echo
				svn log -r HEAD:$lastrev \
				| perl -e 'while (<>) { if (/^--*-$/) { <> } elsif (!/^\w*$/) { s/^/  /; print;} }'
				echo
				echo -n " -- $username  "
				date -R
				echo
				cat debian/changelog
			)
			echo "$new" >debian/changelog
			echo "   Updated."
		else
			echo "   Skipped."
		fi
	)
done

