#!/bin/sh -e

#
# Figure out the system's mailname
#

syshostname=`hostname --fqdn`
if [ ! -f /etc/mailname ]; then
  echo 'Please enter the "mail name" of your system.  This is the hostname'
  echo 'portion of the address to be shown on outgoing news and mail messages.'
  echo "The default is $syshostname, your system's host name."
  echo
  echo -n "Mail name [$syshostname]: "
  read mailname
  echo
  if [ ! "$mailname" ]; then
    mailname=$syshostname
  fi
else
  mailname=`cat /etc/mailname`
fi


#
# Generate configuration file
#

if [ -s $1 ]; then
    echo Configuration file $1 already exists.
    exit
fi
cat >>$1 <<EOF
#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# The person who gets all mail for userids < 10
root=postmaster
# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and you mailhub is so named.
mailhub=mail
# Where will the mail seem to come from?
#rewriteDomain=`echo -n $mailname`
# The full hostname
hostname=`hostname --fqdn`
EOF

echo
echo
echo "Please check the configuration file $1 for correctness."
echo
echo