X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=mail-setup;h=abe98d97b61762b9f92339fc7bce1734baf29b0e;hb=9d21aed0c95e0c343f2769a724d9dbb220874185;hp=c062362c18b70409db760268fc74a0ef40ea167b;hpb=c8f87d4173949b8d96c9c34e2d2c0730caeba0eb;p=distro-setup diff --git a/mail-setup b/mail-setup index c062362..abe98d9 100755 --- a/mail-setup +++ b/mail-setup @@ -50,6 +50,8 @@ EOF # hamburger -> preferences -> preferences -> advanced tab -> config editor button -> security.ssl.enable_ocsp_must_staple = false # background: ovecot does not yet have ocsp stapling support # reference: https://community.letsencrypt.org/t/simple-guide-using-lets-encrypt-ssl-certs-with-dovecot/2921 +# +# for phone, same thing but username alerts, pass in ivy-pass. ####### @@ -64,12 +66,13 @@ EOF # apg -m 50 -x 70 -n 1 -a 1 -M CLN >$f # s sed -i "/^$user:/d" /p/c/filesystem/etc/exim4/passwd # echo "$user:$(mkpasswd -m sha-512 -s <$f)" >>/p/c/filesystem/etc/exim4/passwd +# # todo: port is no longer used in mailpass, remove it. # echo "mail.iankelling.org 587 $user:$(<$f)" >> /p/c/machine_specific/$user/filesystem/etc/mailpass # # then run this script, or part of it which uses /etc/mailpass # # dovecot password, i just need 1 as I\'m the only user # mkdir /p/c/filesystem/etc/dovecot -# echo "iank:$(doveadm pw -s ssha256)::::::" >/p/c/filesystem/etc/dovecot/users +# echo "iank:$(doveadm pw -s ssha256)::::::" >>/p/c/filesystem/etc/dovecot/users # conflink @@ -177,15 +180,9 @@ EOF #exim4 -bt iank@localhost -postconfin() { - local MAPFILE - mapfile -t - local s - postconf -ev "${MAPFILE[@]}" -} e() { printf "%s\n" "$*"; } pi() { # package install - local s f + local f if dpkg -s -- "$@" &> /dev/null; then return 0; fi; @@ -197,7 +194,7 @@ pi() { # package install apt-get -y install --purge --auto-remove "$@" } -postmaster=$u +postmaster=alerts mxhost=mail.iankelling.org mxport=587 forward=$u@$mxhost @@ -218,11 +215,11 @@ fi if [[ $HOSTNAME == $MAIL_HOST ]]; then # afaik, these will get ignored because they are routing to my own # machine, but rm them is safer - rm -f $(eval echo ~$postmaster)/.forward /root/.forward + rm -f $(eval echo ~$u)/.forward /root/.forward else # this can\'t be a symlink and has permission restrictions # it might work in /etc/aliases, but this seems more proper. - install -m 644 {-o,-g}$postmaster <(e $forward) $(eval echo ~$postmaster)/.forward + install -m 644 {-o,-g}$u <(e $forward) $(eval echo ~$u)/.forward fi @@ -245,27 +242,6 @@ if [[ -e /p/c/filesystem ]]; then fi fi -cat >/etc/systemd/system/offlineimapsync.timer <<'EOF' -[Unit] -Description=Run offlineimap-sync once every min - -[Timer] -OnCalendar=*:0/1 - -[Install] -WantedBy=timers.target -EOF - -cat >/etc/systemd/system/offlineimapsync.service </etc/systemd/system/mailclean.timer <<'EOF' [Unit] @@ -291,36 +267,8 @@ EOF systemctl daemon-reload -# wording of question from dpkg-reconfigure exim4-config -# 1. internet site; mail is sent and received directly using SMTP -# 2. mail sent by smarthost; received via SMTP or fetchmail -# 3. mail sent by smarthost; no local mail -# 4. local delivery only; not on a network -# 5. no configuration at this time -# -# Note, I have used option 2 in the past for receiving mail -# from lan hosts, sending external mail via another smtp server. -# -# Note, other than configtype, we could set all the options in -# both types of configs without harm, they would either be -# ignored or be disabled by other settings, but the default -# local_interfaces definitely makes things more secure. - -# most of these settings get translated into settings -# in /etc/exim4/update-exim4.conf.conf -# how /etc/exim4/update-exim4.conf.conf translates into actual exim settings is -# documented in man update-exim4.conf, which outputs to the config that -# exim actually reads. except the man page is not perfect, for example, -# it doesn't document that it sets -# DCconfig_${dc_eximconfig_configtype}" "1" -# which is a line from update-exim4.conf, which is a relatively short bash script. -# mailname setting sets /etc/mailname - -debconf-set-selections </etc/exim4/rcpt_local_acl <<'EOF' @@ -417,7 +365,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR [[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@" -f=/a/bin/bash_unpublished/source-semi-priv +f=/a/bin/bash_unpublished/source-state if [[ -e $f ]]; then source $f fi @@ -470,120 +418,69 @@ systemctl enable mailcert.timer ##### end mailcert setup ##### +# comon stuff +cat >/etc/exim4/update-exim4.conf.conf <<'EOF' +# default stuff, i havent checked if its needed +dc_minimaldns='false' +dc_relay_nets='' +CFILEMODE='644' +dc_use_split_config='true' +dc_local_interfaces='' +dc_mailname_in_oh='true' +EOF if [[ $HOSTNAME == $MAIL_HOST ]]; then - debconf-set-selections <>/etc/exim4/update-exim4.conf.conf < /etc/mailname # MAIN_HARDCODE_PRIMARY_HOSTNAME might mess up the @@ -676,10 +573,10 @@ EOF # sieve option, we wouldn\'t need this, but I\'d rather not modify a # default config if not needed. This won\'t work as a symlink in /a/c # unfortunately. - sudo -u $postmaster /a/exe/lnf -T sieve/main.sieve $(eval echo ~$postmaster)/.dovecot.sieve + sudo -u $u /a/exe/lnf -T sieve/main.sieve $(eval echo ~$u)/.dovecot.sieve + # we set this later in local.conf sed -ri -f - /etc/dovecot/conf.d/10-mail.conf <<'EOF' -1i mail_location = maildir:/m/md:LAYOUT=fs:INBOX=/m/md/INBOX /^\s*mail_location\s*=/d EOF @@ -733,11 +630,16 @@ ssl_cert = /dev/null ||: - systemctl stop offlineimapsync.timer &>/dev/null ||: + # remove mail. 2 lines to properly remove whitespace + sed -ri -f - /etc/hosts <<'EOF' +s#^(127\.0\.1\.1 .*) +mail\.iankelling\.org$#\1# +s#^(127\.0\.1\.1 .*)mail\.iankelling\.org +(.*)#\1\2# +EOF + + echo | /a/exe/cedit mail /etc/dnsmasq-servers.conf || [[ $? == 1 ]] + systemctl reload dnsmasq + systemctl disable mailclean.timer &>/dev/null ||: systemctl stop mailclean.timer &>/dev/null ||: systemctl disable $vpn_ser@mail @@ -782,27 +689,20 @@ else # $HOSTNAME != $MAIL_HOST # would only exist because I wrote it i the previous condition, # it\'s not part of exim rm -f /etc/exim4/conf.d/main/000_localmacros - debconf-set-selections <>/etc/exim4/update-exim4.conf.conf < /etc/mailname fi # end $HOSTNAME != $MAIL_HOST -# if we already have it installed, need to reconfigure, without being prompted -if dpkg -s exim4-config &>/dev/null; then - # gotta remove this, otherwise the set-selections are completely - # ignored. It woulda been nice if this was documented somewhere! - rm -f /etc/exim4/update-exim4.conf.conf - while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done - dpkg-reconfigure -u -fnoninteractive exim4-config -fi +systemctl reload exim4 # i have the spool directory be common to distro multi-boot, so # we need the uid to be the same. 608 cuz it's kind of in the middle @@ -885,10 +785,10 @@ sed -r s/^\\S+:/$b:/ 600_exim4-config_userforward >175_$b f=/etc/exim4/passwd.client rm -f /etc/exim4/passwd.client install -m 640 -g Debian-exim /dev/null $f -cat /etc/mailpass| while read -r domain port pass; do +while read -r domain _ pass; do # reference: exim4_passwd_client(5) printf "%s:%s\n" "$domain" "$pass" >>$f -done +done > /etc/fstab + fi + if ! mountpoint -q $sdir; then + systemctl stop exim4 + if [[ -L $sdir ]]; then + rm $sdir + fi + if [[ ! -e $dir && -d $sdir ]]; then + mv $sdir $dir + fi + if [[ ! -d $sdir ]]; then + mkdir $sdir + chmod 000 $sdir # only want it to be used when its mounted + fi + mount $sdir fi - /a/exe/lnf -T $dir $sdir fi systemctl restart exim4 systemctl enable exim4 + +if [[ $HOSTNAME == $MAIL_HOST ]]; then + cat >/etc/cron.d/mailtest <<'EOF' +*/10 * * * * iank echo body_test | mail -s "primary_test $(date +%s) $(date +%Y-%m-%dT%H:%M:%S%z)" iank@posteo.de +2/10 * * * * root /usr/local/bin/mailtest-check +EOF + cp /a/bin/distro-setup/filesystem/usr/local/bin/mailtest-check /usr/local/bin +else + rm -f /etc/cron.d/mailtest +fi + # MAIL_HOST also does radicale, and easier to start and stop it here # for when MAIL_HOST changes, so radicale gets the synced files and # does not stop us from remounting /o.