summaryrefslogtreecommitdiff
path: root/static/adddomain.sh
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-31 10:01:12 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-31 10:01:12 +0900
commit8b536f408596e3a7c38d7d0c1617a1b7068d0e2f (patch)
tree9f20952f16e7891d5c0deb77ec2d9ee9304732c0 /static/adddomain.sh
parentdecdb559d2e475c4e973f09331419c4b4bd663c0 (diff)
created public/adddomain.sh, created public/emailwiz.sh, created static/adddomain.sh, created static/emailwiz.sh
Diffstat (limited to 'static/adddomain.sh')
-rwxr-xr-xstatic/adddomain.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/static/adddomain.sh b/static/adddomain.sh
new file mode 100755
index 0000000..d44b567
--- /dev/null
+++ b/static/adddomain.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+domain="$1"
+[ -z "$1" ] && exit
+
+domain="$1"
+subdom="mail"
+
+# Add the domain to the valid postfix addresses.
+grep -q "^mydestination.*$domain" /etc/postfix/main.cf ||
+ sed -i "s/^mydestination.*/&, $domain/" /etc/postfix/main.cf
+
+# Create DKIM for new domain.
+mkdir -p "/etc/postfix/dkim/$domain"
+opendkim-genkey -D "/etc/postfix/dkim/$domain" -d "$domain" -s "$subdom"
+chgrp -R opendkim /etc/postfix/dkim/*
+chmod -R g+r /etc/postfix/dkim/*
+
+# Add entries to keytable and signing table.
+echo "$subdom._domainkey.$domain $domain:$subdom:/etc/postfix/dkim/$domain/$subdom.private" >> /etc/postfix/dkim/keytable
+echo "*@$domain $subdom._domainkey.$domain" >> /etc/postfix/dkim/signingtable
+
+systemctl reload opendkim postfix
+
+# Print out DKIM TXT entry.
+pval="$(tr -d '\n' <"/etc/postfix/dkim/$domain/$subdom.txt" | sed "s/k=rsa.* \"p=/k=rsa; p=/;s/\"\s*\"//;s/\"\s*).*//" | grep -o 'p=.*')"
+
+dkimentry="$subdom._domainkey.$domain TXT v=DKIM1; k=rsa; $pval"
+dmarcentry="_dmarc.$domain TXT v=DMARC1; p=reject; rua=mailto:dmarc@$domain; fo=1"
+spfentry="$domain TXT v=spf1 mx a:$maildomain -all"
+mxentry="$domain MX 10 $maildomain 300"
+
+echo "$dkimentry
+$dmarcentry
+$spfentry
+$mxentry" >> "$HOME/dns_emailwizard_added"
+
+echo "=== ADD THE FOLLOWING TO YOUR DNS TXT RECORDS ==="
+echo "$dkimentry
+$dmarcentry
+$spfentry
+$mxentry"
+echo "They have also been stored in ~/dns_emailwizard_added"