Amazon Web Services - AWS EC2 - Ubuntu 14.04

Shell script to associate DKIM to domain

#! /bin/bash
#This script is adding DKIM key to domain
#
# Usage: $source /etc/opendkim/bin/dkim2domain.sh
#
###########################################

echo "This script will add DKIM key to DNS zone file (/etc/bind/db.domain.com)"
echo "What is your domain (domain.com)?"
read DOMAIN

# creating dir environment
mkdir /etc/opendkim/keys/$DOMAIN
/usr/bin/opendkim-genkey -D /etc/opendkim/keys/$DOMAIN/ -d $DOMAIN -s default
chmod 755 /etc/opendkim/keys/$DOMAIN
chmod 640 /etc/opendkim/keys/$DOMAIN/default.private
chmod 600 /etc/opendkim/keys/$DOMAIN/default.txt
chown -R opendkim:opendkim /etc/opendkim/keys

# add DKIM into DNS zone file
echo >>/etc/bind/db.$DOMAIN
cat /etc/opendkim/keys/$DOMAIN/default.txt >> /etc/bind/db.$DOMAIN

# add record into /etc/opendkim/KeyTable SigningTable and TrustedHosts
echo "default._domainkey.$DOMAIN $DOMAIN:default:/etc/opendkim/keys/$DOMAIN/default.private" >> /etc/opendkim/KeyTable
echo "*@$DOMAIN default._domainkey.$DOMAIN" >> /etc/opendkim/SigningTable
echo "$DOMAIN" >> /etc/opendkim/TrustedHosts

# restart services
service opendkim restart
service bind9 restart
service postfix restart

## show config files
echo
echo "++++++++++++ /etc/bind/db.$DOMAIN"
cat /etc/bind/db.$DOMAIN
echo
echo "++++++++++++ /etc/opendkim/KeyTable"
cat /etc/opendkim/KeyTable
echo
echo "++++++++++++ /etc/opendkim/SigningTable"
cat /etc/opendkim/SigningTable
echo
echo "++++++++++++ /etc/opendkim/TrustedHosts"
cat /etc/opendkim/TrustedHosts
echo