X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=setup_opendkim.sh;h=ce1e3d5a4790871297064ddcb1a470c4bc4f6d5f;hb=8d3cd074591a3ebc0f9782a1d4bc785352fc74fc;hp=a8b5402176c676169cc1db875c04494ef9d8d7a8;hpb=ec7cf5e045fbdc6f415a47851e15caf593dcaa46;p=config
diff --git a/setup_opendkim.sh b/setup_opendkim.sh
index a8b5402..ce1e3d5 100755
--- a/setup_opendkim.sh
+++ b/setup_opendkim.sh
@@ -1,29 +1,49 @@
#!/bin/sh
-set -x
set -e
selector=$1
file=$2
+if [ ! -n "$selector" ]; then
+ cat << EOF
+Usage: $0 SELECTOR [KEYFILE] - set up DKIM system and configuration
+
+If existing KEYFILE is given, set up DKIM to use SELECTOR and apply key from
+KEYFILE.
+
+If existing KEYFILE is not given, generate KEYFILE and DNS TXT file for
+SELECTOR.
+EOF
+ exit
+fi
+
if [ ! "$(id -u)" -eq "0" ]; then
echo "Must be run as root."
- exit
+ exit 1
fi
+set -x
apt-get -y install opendkim
-if [ -n $file ] || [ ! -f $file ]; then
+if [ ! -n "$file" ]; then
apt-get -y install opendkim-tools
opendkim-genkey -d plomlompom.com -s $selector
- apt-get --purge autoremove opendkim-tools
+ apt-get -y --purge autoremove opendkim-tools
set +x
echo
echo 'Generated key file at '$selector'.private.'
- echo 'APPLY the content of '$selector'.txt below to your DNS record.'
+ echo 'Also generated '$selector'.txt, APPLY its content below to your DNS' \
+ 'record.'
echo 'AFTER the waiting time for DNS propagation RERUN this script with' \
'the key file as SECOND parameter (still use selector as first one).'
echo
cat $selector.txt
else
+ if [ ! -f "$file" ]; then
+ set +x
+ echo
+ echo "Keyfile $file does not exist."
+ exit 1
+ fi
cp ~/config/systemfiles/opendkim.conf /etc/opendkim.conf
sed -r -i 's/^#Selector .*$/Selector '$selector'/' /etc/opendkim.conf
mkdir -p /etc/opendkim