various fixes, add emacs wrappers
[distro-setup] / mail-setup
index db4daa7615c4508a3eaa3aae09b6b6244b380e33..ffd6f8ca90a0374fd4af11b53b72e21d60e5c8f9 100755 (executable)
@@ -73,6 +73,8 @@ smarthost="$host::587" # exim
 # it might work in /etc/aliases, but this seems more proper.
 e $forward > ~/.forward
 e $forward | s tee /root/.forward
+# exim log complains about 664 permissions.
+s chmod 644 ~/.forward /root/.forward
 
 
 # offlineimap uses this too, it is much easier to use one location than to
@@ -82,7 +84,7 @@ case $distro in
     *) :
 esac
 
-read -r domain pass < <(s cat /etc/mailpass)
+read -r domain pass < <(s cat /etc/mailpass) # format: domain user:pass
 if postfix; then
     # dunno why, but debian installed postfix with builddep emacs
     # but I will just explicitly install it here since
@@ -131,7 +133,7 @@ EOF
     f=/etc/postfix/sasl_passwd
     s touch $f
     s chmod 600 $f
-    echo "[$domain]:587 ${pass/@/#}" | s dd of=/etc/postfix/sasl_passwd >/dev/null
+    printf "[%s]:587 %s" "$domain" "${pass/@/#}" | s dd of=/etc/postfix/sasl_passwd 2>/dev/null
     s postmap hash:/etc/postfix/sasl_passwd
     s service postfix reload
 else
@@ -159,7 +161,9 @@ EOF
     f=/etc/exim4/passwd.client
     s touch $f
     s chmod 640 $f # before writing sensitive info
-    echo "$domain:${pass/:/::}" | s dd of=$f >/dev/null
+    s chown root:Debian-exim $f
+    # reference: exim4_passwd_client(5)
+    printf "%s:%s" "$domain" "$pass" | s dd of=$f 2>/dev/null
     # https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost
     # i only need .forwards, so just doing that one.
     cd /etc/exim4/conf.d/router
@@ -168,8 +172,8 @@ EOF
     tmp=$(mktemp)
     of=175_$b
     # sed to make the router name unique
-    sed -r s/^\\S+:/$b:/ 600_exim4-config_$a >$tmp
-    if diff -q >/dev/null $tmp $of; then
+    sed -r s/^\\S+:/$b:/ 600_exim4-config_$a | s dd of=$tmp 2>/dev/null
+    if diff -q >/dev/null $tmp $of; then
         s dd if=$tmp of=$of >/dev/null
         ser restart exim4
     fi