#!/bin/bash
# Copyright (C) 2008 - 2013 vortexbox.org
#
# 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.

clear
echo "Please enter the FQDN of this VortexBox system."
echo "This is the Domain name that the internet knows your system as."
echo "If you do not have an FQDN use a dynamic DNS service to get one."
echo -n "FQDN: " 
read FQDN
echo ""
echo "Enter the smart relay host, if you do not need one, leave this blank"
echo -n "Smart Host:"
read SmartHost

if [ "$FQDN" = "" ]; then
        echo "Nothing done."
else
        echo "rewriting main.cf to masquerade as $FQDN ..."
		echo""

cat > /etc/postfix/main.cf <<'EOF'
#
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = host.domain.tld

inet_interfaces = localhost
mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
#relayhost = [your.mailserver.com]
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         xxgdb $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES

#smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
#broken_sasl_auth_clients = yes
#smtpd_sasl_auth_enable = no
#smtp_always_send_ehlo = yes
#smtp_sasl_auth_enable = yes

EOF

cd /etc/postfix
cp main.cf main.bak
sed -i.bak -e 's/host.domain.tld/'$FQDN'/' main.cf

if [ "$SmartHost" = "" ]; then
        echo "Ignoring Smart host."
else
        echo "rewriting main.cf to add Smart Host $SmartHost ..."
	sed -i.bak -e 's/your.mailserver.com/'$SmartHost'/' main.cf
                echo""
fi



postfix reload

echo ""
echo "Done."
		
fi

