Apply suggestions from code review
Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
This commit is contained in:
parent
3a2e32aeb8
commit
ccbadc35f7
|
@ -26,11 +26,13 @@ function _get_valid_lines_from_file() {
|
|||
# This is to sanitize configs from users that unknowingly introduced CRLF:
|
||||
function _convert_crlf_to_lf_if_necessary() {
|
||||
if [[ $(file "${1}") =~ 'CRLF' ]]; then
|
||||
_log 'warn' "${1} contains CRLF line-endings."
|
||||
_log 'warn' "File '${1}' contains CRLF line-endings"
|
||||
|
||||
if [[ -w "${1}" ]]; then
|
||||
if [[ -w ${1} ]]; then
|
||||
_log 'debug' 'Converting CRLF to LF'
|
||||
sed -i 's|\r||g' "${1}"
|
||||
else
|
||||
_log 'warn' "File '${1}' is not writable - cannot change CRLF to LF"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -43,12 +45,12 @@ function _append_final_newline_if_missing() {
|
|||
# https://unix.stackexchange.com/questions/159557/how-to-non-invasively-test-for-write-access-to-a-file
|
||||
if [[ $(tail -c1 "${1}" | wc -l) -eq 0 ]]; then
|
||||
# Avoid fixing when the destination is read-only:
|
||||
if [[ -w "${1}" ]]; then
|
||||
if [[ -w ${1} ]]; then
|
||||
printf '\n' >> "${1}"
|
||||
|
||||
_log 'warn' "${1} was missing a final newline. This has been fixed."
|
||||
_log 'info' "File '${1}' was missing a final newline - this has been fixed"
|
||||
else
|
||||
_log 'warn' "${1} is missing a final newline. The last line will not be processed!"
|
||||
_log 'warn' "File '${1}' is missing a final newline - it is not writable, hence it was not fixed - the last line will not be processed!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -127,9 +127,7 @@ function __postfix__setup_override_configuration() {
|
|||
local OVERRIDE_CONFIG_POSTFIX_MASTER='/tmp/docker-mailserver/postfix-master.cf'
|
||||
if [[ -f ${OVERRIDE_CONFIG_POSTFIX_MASTER} ]]; then
|
||||
while read -r LINE; do
|
||||
if [[ ${LINE} =~ ^[0-9a-z] ]]; then
|
||||
postconf -P "${LINE}"
|
||||
fi
|
||||
[[ ${LINE} =~ ^[0-9a-z] ]] && postconf -P "${LINE}"
|
||||
done < <(_get_valid_lines_from_file "${OVERRIDE_CONFIG_POSTFIX_MASTER}")
|
||||
__postfix__log 'trace' "Adjusted '/etc/postfix/master.cf' according to '${OVERRIDE_CONFIG_POSTFIX_MASTER}'"
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue