From 69aaa0ea66585d1c900ecc0aa282ff61814755eb Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Wed, 21 Oct 2020 09:11:31 -0400 Subject: [PATCH] code cleanup --- mail-setup | 56 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/mail-setup b/mail-setup index 5e07232..9662934 100755 --- a/mail-setup +++ b/mail-setup @@ -363,9 +363,8 @@ EOF # https://selivan.github.io/2017/12/30/systemd-serice-always-restart.html -f=/etc/systemd/system/openvpn-client-mail@.service -if [[ ! -s $f || $(stat -c%s $f) != 1709 ]]; then - cat >$f <<'EOF' +tmpdir=$(mktemp -d) +cat >$tmpdir/openvpn-client-mail@.service <<'EOF' [Unit] Description=OpenVPN tunnel for %I After=syslog.target network-online.target @@ -412,6 +411,9 @@ RestartSec=1 [Install] WantedBy=multi-user.target EOF +tmp=$(install -vC $tmpdir/* /etc/systemd/system) +rm -rf $tmpdir +if [[ $tmp ]]; then m systemctl daemon-reload fi @@ -428,13 +430,11 @@ fi case $HOSTNAME in $MAIL_HOST|bk) reload=false + tmpdir=$(mktemp -d) for unit in exim4 spamassassin; do - f=/etc/systemd/system/$unit.service.d/nn.conf - if [[ ! -s $f || $(stat -c%s $f) != 244 ]]; then - reload=true - echo creating $f - mkdir -p ${f%/*} - cat >$f <<'EOF' + dir=/etc/systemd/system/$unit.service.d + mkdir -p $dir + cat >$tmpdir/nn.conf <<'EOF' [Unit] After=network.target Requires=openvpn-client-mail@mail.service @@ -452,8 +452,12 @@ Restart=always # time to sleep before restarting a service RestartSec=1 EOF + tmp=$(install -vC $tmpdir/* $dir) + if [[ $tmp ]]; then + reload=true fi done + rm -rf $tmpdir if $reload; then m systemctl daemon-reload fi @@ -485,7 +489,7 @@ e CRON=1 >>/etc/default/spamassassin case $HOSTNAME in $MAIL_HOST|bk) - # just noticed this in the config file, seems like a good idea. + # Just noticed this in the config file, seems like a good idea. sed -i '/^\s*NICE\s*=/d' /etc/default/spamassassin e 'NICE="--nicelevel 15"' >>/etc/default/spamassassin @@ -496,7 +500,6 @@ case $HOSTNAME in m systemctl start spamassassin ;; esac - ##### end spamassassin config @@ -509,12 +512,11 @@ if [[ -e /p/c/filesystem ]]; then m /a/exe/vpn-mk-client-cert -b mailclient -n mail -s /b/ds/mail-route li.iankelling.org fi - - m rsync -aiSAX --chown=root:root --chmod=g-s /a/bin/ds/mail-cert-cron /usr/local/bin - -cat >/etc/systemd/system/mailcert.service <<'EOF' +### begin install timer +tmpdir=$(mktemp -d) +cat >$tmpdir/mailcert.service <<'EOF' [Unit] Description=Mail cert rsync After=multi-user.target @@ -523,8 +525,7 @@ After=multi-user.target Type=oneshot ExecStart=/a/bin/log-quiet/sysd-mail-once mailcert /usr/local/bin/mail-cert-cron EOF - -cat >/etc/systemd/system/mailcert.timer <<'EOF' +cat >$tmpdir/mailcert.timer <<'EOF' [Unit] Description=Run mail-cert once a day @@ -534,7 +535,14 @@ OnCalendar=daily [Install] WantedBy=timers.target EOF -m systemctl daemon-reload +tmp=$(install -vC $tmpdir/* /etc/systemd/system) +if [[ $tmp ]]; then + m systemctl daemon-reload +fi +rm -rf $tmpdir +### end install timer + + m systemctl start mailcert m systemctl restart mailcert.timer m systemctl enable mailcert.timer @@ -1725,17 +1733,19 @@ if [[ -e /nocow ]]; then echo "/nocow/exim4 /var/spool/exim4 none bind 0 0" >>/etc/fstab fi reload=false - f=/etc/systemd/system/exim4.service.d/override.conf - if [[ ! -s $f || $(stat -c%s $f) != 220 ]]; then - reload=true - mkdir -p ${f%/*} - cat >$f <<'EOF' + tmpdir=$(mktemp -d) + cat >$tmpdir/override.conf <<'EOF' [Unit] # without this on exim, we get these kind of errors in paniclog on shutdown: # Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied After=local-fs.target After=network.target EOF + dir=/etc/systemd/system/exim4.service.d + mkdir -p $dir + tmp=$(install -vC $tmpdir/* $dir) + rm -rf $tmpdir + if [[ $tmp ]]; then m systemctl daemon-reload fi if ! mountpoint -q $sdir; then -- 2.30.2