#!/bin/sh
if [ -d /etc/postfix/.git ]; then
    echo "postfix already initialized !"
    exit 1
fi
if [ -d /etc/dovecot/.git ]; then
    echo "dovecot already initialized !"
    exit 1
fi
p=$(mktemp -d)
d=$(mktemp -d)
git clone git@git.geekwu.org:config/postfix.git $p
git clone git@git.geekwu.org:config/dovecot.git $d
mv $p/.git /etc/postfix
mv $d/.git /etc/dovecot
rm -Rf $p $d
cd /etc/postfix
test -d .hooks && ln -s `pwd`/.hooks/* .git/hooks
git reset --hard
sed -i "s/mailHost=test-postfix.geekwu.org/mailHost=`hostname -f`/" *.cf
/etc/init.d/postfix restart
cd /etc/dovecot
test -d .hooks && ln -s `pwd`/.hooks/* .git/hooks
git reset --hard
cat >> local.conf <<EOF
auth_proxy_self = `hostname -f`
EOF
/etc/init.d/dovecot restart
