#!/bin/bash # # Generate a DKIM key for Postfix # # Project info # https://gitpull.it/w/kiss_libre_hosting_panel/ # # Updates # https://gitpull.it/P13 # # This script is in public domain. # 2020 - Valerio Bozzolan ################################################### # die in case of errors set -e # expected pathnames POSTFIX=/etc/postfix DKIM="$POSTFIX"/dkim KEYTABLE="$DKIM"/keytable SIGNINGTABLE="$DKIM"/signingtable DKIM_KEYS="$DKIM"/dkimkeys # no domain no party domain="$1" if [ -z "$domain" ]; then echo "Please insert the domain name and press enter" read domain fi # no selector no party selector="$2" if [ -z "$2" ]; then date="`date +%Y%m`" # make domain shorter domainshort="${domain:0:10}" # strip dots domainshort=$(echo "$domainshort" | sed 's/\.//g') selector="$domainshort""$date" fi # expected pathnames keytablename="$selector"key expected_filename_prv="$selector".private expected_filename_txt="$selector".txt expected_filepath_prv="$DKIM_KEYS"/"$expected_filename_prv" expected_filepath_txt="$DKIM_KEYS"/"$expected_filename_txt" # key generation opendkim-genkey --verbose --bits=1024 "--domain=$domain" "--selector=$selector" "--directory=$DKIM_KEYS" # this line should be at the beginning of the file sed -i "1s/^/*@$domain $keytablename\n/" "$SIGNINGTABLE" # this line can be appended at the end of the table echo "$keytablename $domain:$selector:$expected_filepath_prv" >> "$KEYTABLE" # eventually fix privileges chown --verbose opendkim: "$expected_filepath_prv" "$expected_filepath_txt" cat "$expected_filepath_txt" echo echo "Done!" echo " systemctl reload opendkim" echo " opendkim-testkey -d '$domain' -s '$selector' -vvv"