#!/bin/sh

cd /root/scripts

dir=/var/lib/moin/dovecot/data/pages/MainConfig
current=`cat $dir/current`

tmp=/tmp/dovecot-config-wiki
./config2wiki.pl < /var/www/hg/dovecot-1.1/dovecot-example.conf > $tmp
if ! `diff -q $dir/revisions/$current $tmp > /dev/null`; then
  next=`expr $current + 1`
  next=`printf "%08d" $next`

  mv $tmp $dir/revisions/$next
  echo $next > $dir/current
  echo "`date +%s000000`	$next	SAVE	MainConfig	127.0.0.1	generator			" >> $dir/edit-log
  /etc/init.d/httpd reload
fi
