Solved DKIM script modification

Hi Guys,

I am not a script guru but I try my best..
I have created a very simple script that generate the DKIM file for me on the mail server..
Code:
#!/bin/sh
#
# sophimail DKIM keys generation
#       - Create domain directory
#       - Generate DKIM keys
#       - add entry to KeyTable
#       - add entry to SigningTable
#
echo "================================="
echo "|  DKIM Keys Generator Script  |"
echo "================================="

read -p 'Enter Domain name: ' domain

clear
echo "================================="
echo "|  Proceed with the following?  |"
echo "================================="
echo ""
echo "DKIM keys Directory:      /usr/local/etc/opendkim/keys/$domain"
echo "KeyTable entry:           default._domainkey.$domain $domain:default:/usr/local/etc/opendkim/keys/$domain/default"
echo "SigningTable entry:       *@$domain default._domainkey.$domain"
echo ""

read -p "run install? [y/n]" REPLY
if [ "$REPLY" == n ] ; then
        echo "Exiting..."
    exit 1
else

 # create key directory
 mkdir /usr/local/etc/opendkim/keys/$domain

 # generate key file
 opendkim-genkey -D /usr/local/etc/opendkim/keys/$domain/ -d $domain -s default

 # set ownership
 chown -R opendkim: /usr/local/etc/opendkim/keys/$domain

 # rename file
 mv /usr/local/etc/opendkim/keys/$domain/default.private /usr/local/etc/opendkim/keys/$domain/default

 # add entry to tables
 echo "default._domainkey.$domain $domain:default:/usr/local/etc/opendkim/keys/$domain/default" >> /usr/local/etc/opendkim/KeyTable
 echo "*@$domain default._domainkey.$domain" >> /usr/local/etc/opendkim/SigningTable

fi
This script work but I would like to be able to pass the domain name as part of the command like:
dkimgen mydomain.com
Could anyone please advise on how I would need to update the script to achive this?
Aslo can i pass a file with multiple domain?

Thank you
 
Code:
#!/bin/sh 

 if [ "$#" -eq  "0" ]
   then
    echo "No arguments supplied. Usage: dkimgen <domain>"
 else

domain=$1
mkdir /usr/local/etc/opendkim/keys/$domain;
opendkim-genkey -D /usr/local/etc/opendkim/keys/$domain/ -d $domain -s default;
chown -R opendkim: /usr/local/etc/opendkim/keys/$domain;
mv /usr/local/etc/opendkim/keys/$domain/default.private /usr/local/etc/opendkim/keys/$domain/default;
echo "default._domainkey.$domain $domain:default:/usr/local/etc/opendkim/keys/$domain/default" >> /usr/local/etc/opendkim/KeyTable;
echo "*@$domain default._domainkey.$domain" >> /usr/local/etc/opendkim/SigningTable

fi
 
Totally untested but change this line:
Code:
read -p 'Enter Domain name: ' domain
To something like this:
Code:
if [ $# -eq 1 ]; then
 $domain = $1
else
 read -p 'Enter Domain name: ' domain
fi

The idea is that dkimgen mydomain.com would work and dkimgen asks for the domain.

See http://www.grymoire.com/Unix/Sh.html
 
Back
Top