Skip to content

Instantly share code, notes, and snippets.

@vojty
Last active August 29, 2015 14:17
Show Gist options
  • Save vojty/59a8149dab6f93d2a987 to your computer and use it in GitHub Desktop.
Save vojty/59a8149dab6f93d2a987 to your computer and use it in GitHub Desktop.
Nastavení DKIM - ./script domena.cz
#!/bin/bash
# http://linuxaria.com/howto/using-opendkim-to-sign-postfix-mails-on-debian
#
# Note:
# opendkim-genkey has been changed (-h sha256)
redColor='\033[0;31m'
greenColor='\033[0;32m'
noColor='\033[0m'
function echoRed(){
echo -e "${redColor}$1${noColor}"
}
function echoGreen(){
echo -e "${greenColor}$1${noColor}"
}
function checkDomainDir(){
# Directory for domain keys
if ! [ -d "$domainDir" ]; then
mkdir "$domainDir"
echo "Creating directory $domainDir"
else
if [ -f "$publicKeyFile" ] && [ -f "$privateKeyFile" ]; then
echoRed "Keys already exist!"
exit
fi
fi
}
if [ "$#" != 1 ]; then
echoRed "Usage $0 domain.com"
exit
fi
domain="$1"
echo "Using domain $domain"
# Variables
dkimUser="opendkim"
dkimGroup="opendkim"
dkimDir="/etc/opendkim"
keyTableFile="$dkimDir/KeyTable"
signingTableFile="$dkimDir/SigningTable"
#domain="wavevision.cz"
domainDir="$dkimDir/$domain"
publicKeyFile="$domainDir/mail.txt"
privateKeyFile="$domainDir/mail.private"
checkDomainDir
# Generate keys
opendkim-genkey -r -h sha256 -d "$domain" -s mail -D "$domainDir"
echo "Public key: $publicKeyFile"
echoGreen "$(cat $publicKeyFile)"
# Permission
chown -R "$dkimUser:$dkimGroup" "$domainDir"
chmod 700 "$domainDir"
chmod 600 "$publicKeyFile"
chmod 600 "$privateKeyFile"
echo "Editing $keyTableFile"
echo -e "$domain $domain:mail:$privateKeyFile\n" >> "$keyTableFile"
echo "Editing $signingTableFile"
echo -e "*@$domain $domain\n" >> "$signingTableFile"
echoGreen "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment