fixes
[distro-setup] / mail-setup
index f8cb3ee83e05dec206fb5d9c7fe0103e0b1b1392..f7f1fc56a853dc6c8ddc2a8b8e4e6e51f41cc859 100755 (executable)
@@ -418,21 +418,6 @@ fi
 # our nostart pi fails to avoid enabling
 
 
-# * user forward file
-case $HOSTNAME in
-  $MAIL_HOST)
-    # afaik, these will get ignored on MAIL_HOST because they are routing to my own
-    # machine, but rm them is safer
-    rm -fv $uhome/.forward /root/.forward
-    ;;
-  *)
-    # this can\'t be a symlink and has permission restrictions
-    # it might work in /etc/aliases, but this seems more proper.
-    e setting $uhome/.forward to $forward
-    install -m 644 {-o,-g}$u <(e $forward) $uhome/.forward
-    ;;
-esac
-
 # * Mail clean cronjob
 
 i /etc/systemd/system/mailclean.timer <<'EOF'
@@ -841,9 +826,13 @@ fi
 # * common exim4 config
 
 
+## old, not using forward files anymore
+rm -fv $uhome/.forward /root/.forward
+
+
 # Make all system users be aliases. preventative
-# measure for things like cron mail for user without alias
-awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ { print $1 }' /etc/passwd| while read -r user; do
+# prevents things like cron mail for user without alias
+awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ || $7 ~ /\/nologin$/  { print $1 }' /etc/passwd| while read -r user; do
   if [[ ! $user ]]; then
     continue
   fi
@@ -852,6 +841,20 @@ awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ { print $1 }' /etc/passwd| while read
   fi
 done
 
+
+awk 'BEGIN { FS = ":" } ; $6 ~ /^\/home/ && $7 !~ /\/nologin$/ { print $1 }' /etc/passwd| while read -r user; do
+  case $HOSTNAME in
+    $MAIL_HOST)
+      sed -i "/^user:/d" /etc/aliases
+    ;;
+    *)
+      if ! grep -q "^$user:" /etc/aliases; then
+        echo "$user: root" |m tee -a /etc/aliases
+      fi
+      ;;
+  esac
+done
+
 if ! grep -q "^ncsoft:" /etc/aliases; then
   echo "ncsoft: graceq2323@gmail.com" |m tee -a /etc/aliases
 fi
@@ -2508,10 +2511,12 @@ EOF
     # The debconf questions output is additional documentation that is not
     # easily accessible, but super long, along with the initial default comment in this
     # file, so I've saved that into ./mail-notes.conf.
+    #
+    # # TODO: remove mx.iankelling.org once systems get updated mail-setup from jan 2022
     cat >>/etc/exim4/update-exim4.conf.conf <<EOF
 # man page: is used to build the local_domains list, together with "localhost"
 # this is duplicated in a later router.
-dc_other_hostnames='iankelling.org;zroe.org;r2e.iankelling.org;!je.b8.nz;!bk.b8.nz;*.b8.nz;b8.nz'
+dc_other_hostnames='iankelling.org;zroe.org;r2e.iankelling.org;mx.iankelling.org;!je.b8.nz;!bk.b8.nz;*.b8.nz;b8.nz'
 EOF