From 8ec5dbec74839e0460252bcc2115035310f49327 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> Date: Sat, 4 Mar 2023 10:57:42 +0100 Subject: [PATCH] scripts: touchups for v12.0.0 (#3144) --- target/scripts/start-mailserver.sh | 2 +- target/scripts/startup/setup-stack.sh | 27 +++---------------- target/scripts/startup/setup.d/log.sh | 11 ++++++++ target/scripts/startup/setup.d/mail_state.sh | 14 +++++----- .../scripts/startup/setup.d/security/misc.sh | 9 +++++++ 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/target/scripts/start-mailserver.sh b/target/scripts/start-mailserver.sh index 94a6fc15..82d48013 100755 --- a/target/scripts/start-mailserver.sh +++ b/target/scripts/start-mailserver.sh @@ -39,7 +39,7 @@ function _register_functions # ? >> Setup - _register_setup_function '_setup_file_permissions' + _register_setup_function '_setup_logs_general' _register_setup_function '_setup_timezone' if [[ ${SMTP_ONLY} -ne 1 ]] diff --git a/target/scripts/startup/setup-stack.sh b/target/scripts/startup/setup-stack.sh index f677dfed..ca2cfc12 100644 --- a/target/scripts/startup/setup-stack.sh +++ b/target/scripts/startup/setup-stack.sh @@ -10,7 +10,7 @@ function _register_setup_function function _setup { - # requires `shopt -s globstar` because of `**` which in + # Requires `shopt -s globstar` because of `**` which in # turn is required as we're decending through directories for FILE in /usr/local/bin/setup.d/**/*.sh do @@ -57,27 +57,6 @@ function _early_supervisor_setup return 0 } -# File/folder permissions are fine when using docker volumes, but may be wrong -# when file system folders are mounted into the container. -# Set the expected values and create missing folders/files just in case. -function _setup_file_permissions -{ - _log 'debug' 'Setting file and directory permissions' - - mkdir -p /var/log/supervisor - - mkdir -p /var/log/mail - chown syslog:root /var/log/mail - - touch /var/log/mail/clamav.log - chown clamav:adm /var/log/mail/clamav.log - chmod 640 /var/log/mail/clamav.log - - touch /var/log/mail/freshclam.log - chown clamav:adm /var/log/mail/freshclam.log - chmod 640 /var/log/mail/freshclam.log -} - function _setup_timezone { [[ -n ${TZ} ]] || return 0 @@ -110,8 +89,8 @@ function _setup_apply_fixes_after_configuration _log 'debug' 'Checking /var/mail permissions' _chown_var_mail_if_necessary || _shutdown 'Failed to fix /var/mail permissions' - _log 'trace' 'Remove left-over files and directories from older versions' - rm -rf /var/spool/postfix/{dev,etc,lib,usr,private/auth} + _log 'debug' 'Removing files and directories from older versions' + rm -rf /var/mail-state/spool-postfix/{dev,etc,lib,pid,usr,private/auth} } function _run_user_patches diff --git a/target/scripts/startup/setup.d/log.sh b/target/scripts/startup/setup.d/log.sh index 5c9d3cc6..95c32d14 100644 --- a/target/scripts/startup/setup.d/log.sh +++ b/target/scripts/startup/setup.d/log.sh @@ -1,5 +1,16 @@ #!/bin/bash +function _setup_logs_general +{ + _log 'debug' 'Setting up general log files' + + # File/folder permissions are fine when using docker volumes, but may be wrong + # when file system folders are mounted into the container. + # Set the expected values and create missing folders/files just in case. + mkdir -p /var/log/{mail,supervisor} + chown syslog:root /var/log/mail +} + function _setup_logrotate { _log 'debug' 'Setting up logrotate' diff --git a/target/scripts/startup/setup.d/mail_state.sh b/target/scripts/startup/setup.d/mail_state.sh index e3d9fff2..c44b90b0 100644 --- a/target/scripts/startup/setup.d/mail_state.sh +++ b/target/scripts/startup/setup.d/mail_state.sh @@ -82,13 +82,11 @@ function _setup_save_states chown -R postfix:root /var/mail-state/spool-postfix chown root:root /var/mail-state/spool-postfix # These two require the postdrop(103) group: - chgrp -R postdrop /var/mail-state/spool-postfix/maildrop - chgrp -R postdrop /var/mail-state/spool-postfix/public - # These all have root ownership at the src location: - chown -R root /var/mail-state/spool-postfix/dev - chown -R root /var/mail-state/spool-postfix/etc - chown -R root /var/mail-state/spool-postfix/lib - chown -R root /var/mail-state/spool-postfix/pid - chown -R root /var/mail-state/spool-postfix/usr + chgrp -R postdrop /var/mail-state/spool-postfix/{maildrop,public} + elif [[ ${ONE_DIR} -eq 1 ]] + then + _log 'warn' "'ONE_DIR=1' but no volume was mounted to '${STATEDIR}'" + else + _log 'debug' 'Not consolidating state (because it has been disabled)' fi } diff --git a/target/scripts/startup/setup.d/security/misc.sh b/target/scripts/startup/setup.d/security/misc.sh index 4feb0344..d441f7d1 100644 --- a/target/scripts/startup/setup.d/security/misc.sh +++ b/target/scripts/startup/setup.d/security/misc.sh @@ -174,6 +174,15 @@ function __setup__security__clamav if [[ ${ENABLE_CLAMAV} -eq 1 ]] then _log 'debug' 'Enabling and configuring ClamAV' + + local FILE + for FILE in /var/log/mail/{clamav,freshclam}.log + do + touch "${FILE}" + chown clamav:adm "${FILE}" + chmod 640 "${FILE}" + done + if [[ ${CLAMAV_MESSAGE_SIZE_LIMIT} != '25M' ]] then _log 'trace' "Setting ClamAV message scan size limit to '${CLAMAV_MESSAGE_SIZE_LIMIT}'"