From c2d0b748b24814db1eb2b827b36d17f5d95bd31c Mon Sep 17 00:00:00 2001 From: Casper Date: Fri, 26 May 2023 01:39:39 +0200 Subject: [PATCH] Change 'while' style (#3365) --- setup.sh | 3 +-- target/bin/delmailuser | 3 +-- target/bin/listalias | 3 +-- target/bin/listdovecotmasteruser | 3 +-- target/bin/listmailuser | 3 +-- target/bin/open-dkim | 6 ++---- target/bin/rspamd-dkim | 3 +-- target/scripts/check-for-changes.sh | 3 +-- target/scripts/helpers/accounts.sh | 9 +++------ target/scripts/helpers/lock.sh | 3 +-- target/scripts/helpers/postfix.sh | 6 ++---- target/scripts/helpers/relay.sh | 3 +-- target/scripts/helpers/utils.sh | 3 +-- target/scripts/startup/setup.d/fetchmail.sh | 3 +-- target/scripts/startup/setup.d/networking.sh | 3 +-- target/scripts/startup/setup.d/postfix.sh | 3 +-- target/scripts/startup/setup.d/security/rspamd.sh | 3 +-- target/scripts/update-check.sh | 3 +-- 18 files changed, 22 insertions(+), 44 deletions(-) diff --git a/setup.sh b/setup.sh index 71739686..6a89a436 100755 --- a/setup.sh +++ b/setup.sh @@ -124,8 +124,7 @@ function _main() { _set_default_config_path local OPTIND - while getopts ":c:i:p:zZR" OPT - do + while getopts ":c:i:p:zZR" OPT; do case ${OPT} in ( i ) IMAGE_NAME="${OPTARG}" ;; ( z | Z ) USE_SELINUX=":${OPT}" ;; diff --git a/target/bin/delmailuser b/target/bin/delmailuser index 974a2375..d796f2a7 100755 --- a/target/bin/delmailuser +++ b/target/bin/delmailuser @@ -70,8 +70,7 @@ ${ORANGE}EXIT STATUS${RESET} } function _parse_options() { - while getopts ":yY" OPT - do + while getopts ":yY" OPT; do case "${OPT}" in ( 'y' | 'Y' ) MAILDEL=1 diff --git a/target/bin/listalias b/target/bin/listalias index efb48fd2..7081ea48 100755 --- a/target/bin/listalias +++ b/target/bin/listalias @@ -12,8 +12,7 @@ function _list_entries() { local DATABASE=${1} _db_should_exist_with_content "${DATABASE}" - while read -r LINE - do + while read -r LINE; do echo -e "* ${LINE}\n" done < <(_get_valid_lines_from_file "${DATABASE}") } diff --git a/target/bin/listdovecotmasteruser b/target/bin/listdovecotmasteruser index 214befd3..193eaa96 100755 --- a/target/bin/listdovecotmasteruser +++ b/target/bin/listdovecotmasteruser @@ -13,8 +13,7 @@ function _list_entries() { _db_should_exist_with_content "${DATABASE}" local MASTER_ACCOUNT - while read -r LINE - do + while read -r LINE; do MASTER_ACCOUNT=$(echo "${LINE}" | cut -d'|' -f1) echo -e "* ${MASTER_ACCOUNT}\n" diff --git a/target/bin/listmailuser b/target/bin/listmailuser index c1ab9d8e..1253c448 100755 --- a/target/bin/listmailuser +++ b/target/bin/listmailuser @@ -19,8 +19,7 @@ function _list_entries() { _db_should_exist_with_content "${DATABASE}" local ENTRY_TO_DISPLAY - while read -r LINE - do + while read -r LINE; do ENTRY_TO_DISPLAY=$(_format_list_item "${LINE}") echo -e "* ${ENTRY_TO_DISPLAY}\n" diff --git a/target/bin/open-dkim b/target/bin/open-dkim index c3e65678..50b18f6c 100755 --- a/target/bin/open-dkim +++ b/target/bin/open-dkim @@ -57,8 +57,7 @@ ${ORANGE}EXIT STATUS${RESET} _require_n_parameters_or_print_usage 0 "${@}" -while [[ ${#} -gt 0 ]] -do +while [[ ${#} -gt 0 ]]; do case "${1}" in ( 'keysize' ) if [[ -n ${2+set} ]]; then @@ -124,8 +123,7 @@ if [[ ! -s ${DATABASE_VHOST} ]]; then exit 0 fi -while read -r DKIM_DOMAIN -do +while read -r DKIM_DOMAIN; do mkdir -p "/tmp/docker-mailserver/opendkim/keys/${DKIM_DOMAIN}" if [[ ! -f "/tmp/docker-mailserver/opendkim/keys/${DKIM_DOMAIN}/${SELECTOR}.private" ]]; then diff --git a/target/bin/rspamd-dkim b/target/bin/rspamd-dkim index e4250d8b..7aa76773 100755 --- a/target/bin/rspamd-dkim +++ b/target/bin/rspamd-dkim @@ -79,8 +79,7 @@ function _parse_arguments() { _log 'trace' "Options given to this script: '${*}'" - while [[ ${#} -gt 0 ]] - do + while [[ ${#} -gt 0 ]]; do case "${1}" in ( 'keytype' ) diff --git a/target/scripts/check-for-changes.sh b/target/scripts/check-for-changes.sh index 58f0d96f..a8cdeb68 100755 --- a/target/scripts/check-for-changes.sh +++ b/target/scripts/check-for-changes.sh @@ -174,8 +174,7 @@ function _ssl_changes() { # They presently have no special handling other than to trigger a change that will restart Postfix/Dovecot. } -while true -do +while true; do _check_for_changes sleep 2 done diff --git a/target/scripts/helpers/accounts.sh b/target/scripts/helpers/accounts.sh index 3637ff4f..82b626c1 100644 --- a/target/scripts/helpers/accounts.sh +++ b/target/scripts/helpers/accounts.sh @@ -38,8 +38,7 @@ function _create_accounts() { # creating users ; 'pass' is encrypted # comments and empty lines are ignored local LOGIN PASS USER_ATTRIBUTES - while IFS=$'|' read -r LOGIN PASS USER_ATTRIBUTES - do + while IFS=$'|' read -r LOGIN PASS USER_ATTRIBUTES; do # Setting variables for better readability USER=$(echo "${LOGIN}" | cut -d @ -f1) DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2) @@ -104,8 +103,7 @@ function _create_dovecot_alias_dummy_accounts() { # adding aliases to Dovecot's userdb # ${REAL_FQUN} is a user's fully-qualified username local ALIAS REAL_FQUN DOVECOT_USERDB_LINE - while read -r ALIAS REAL_FQUN - do + while read -r ALIAS REAL_FQUN; do # alias is assumed to not be a proper e-mail # these aliases do not need to be added to Dovecot's userdb [[ ! ${ALIAS} == *@* ]] && continue @@ -177,8 +175,7 @@ function _create_masters() { # creating users ; 'pass' is encrypted # comments and empty lines are ignored local LOGIN PASS - while IFS=$'|' read -r LOGIN PASS - do + while IFS=$'|' read -r LOGIN PASS; do _log 'debug' "Creating master user '${LOGIN}'" local DOVECOT_MASTERDB_LINE diff --git a/target/scripts/helpers/lock.sh b/target/scripts/helpers/lock.sh index 7156c3ec..9aa55200 100644 --- a/target/scripts/helpers/lock.sh +++ b/target/scripts/helpers/lock.sh @@ -9,8 +9,7 @@ LOCK_ID=$(uuid) function _create_lock() { LOCK_FILE="/tmp/docker-mailserver/${SCRIPT_NAME}.lock" - while [[ -e "${LOCK_FILE}" ]] - do + while [[ -e "${LOCK_FILE}" ]]; do # Handle stale lock files left behind on crashes # or premature/non-graceful exits of containers while they're making changes if [[ -n "$(find "${LOCK_FILE}" -mmin +1 2>/dev/null)" ]]; then diff --git a/target/scripts/helpers/postfix.sh b/target/scripts/helpers/postfix.sh index 47e57733..32897d0e 100644 --- a/target/scripts/helpers/postfix.sh +++ b/target/scripts/helpers/postfix.sh @@ -45,8 +45,7 @@ function _vhost_collect_postfix_domains() { # getting domains FROM mail accounts if [[ -f ${DATABASE_ACCOUNTS} ]]; then - while IFS=$'|' read -r LOGIN _ - do + while IFS=$'|' read -r LOGIN _; do DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2) echo "${DOMAIN}" >>"${TMP_VHOST}" done < <(_get_valid_lines_from_file "${DATABASE_ACCOUNTS}") @@ -54,8 +53,7 @@ function _vhost_collect_postfix_domains() { # getting domains FROM mail aliases if [[ -f ${DATABASE_VIRTUAL} ]]; then - while read -r FROM _ - do + while read -r FROM _; do UNAME=$(echo "${FROM}" | cut -d @ -f1) DOMAIN=$(echo "${FROM}" | cut -d @ -f2) diff --git a/target/scripts/helpers/relay.sh b/target/scripts/helpers/relay.sh index 4a1d8641..c2713651 100644 --- a/target/scripts/helpers/relay.sh +++ b/target/scripts/helpers/relay.sh @@ -149,8 +149,7 @@ function _populate_relayhost_map() { { _list_domain_parts "${PRINT_DOMAIN_PART_ACCOUNTS}" /tmp/docker-mailserver/postfix-accounts.cf _list_domain_parts "${PRINT_DOMAIN_PART_VIRTUAL}" /tmp/docker-mailserver/postfix-virtual.cf - } | sort -u | while read -r DOMAIN_PART - do + } | sort -u | while read -r DOMAIN_PART; do # DOMAIN_PART not already present in `/etc/postfix/relayhost_map`, and not listed as a relay opt-out domain in `postfix-relaymap.cf` # `^@${DOMAIN_PART}\b` - To check for existing entry, the `\b` avoids accidental partial matches on similar domain parts. # `^\s*@${DOMAIN_PART}\s*$` - Matches line with only a domain part (eg: @example.test) to avoid including a mapping for those domains to the RELAY_HOST. diff --git a/target/scripts/helpers/utils.sh b/target/scripts/helpers/utils.sh index 59e0f63b..0c5a0321 100644 --- a/target/scripts/helpers/utils.sh +++ b/target/scripts/helpers/utils.sh @@ -97,8 +97,7 @@ function _replace_by_env_in_file() { local ENV_PREFIX=${1} CONFIG_FILE=${2} local ESCAPED_VALUE ESCAPED_KEY - while IFS='=' read -r KEY VALUE - do + while IFS='=' read -r KEY VALUE; do KEY=${KEY#"${ENV_PREFIX}"} # strip prefix ESCAPED_KEY=$(sed -E 's#([\=\&\|\$\.\*\/\[\\^]|\])#\\\1#g' <<< "${KEY,,}") ESCAPED_VALUE=$(sed -E 's#([\=\&\|\$\.\*\/\[\\^]|\])#\\\1#g' <<< "${VALUE}") diff --git a/target/scripts/startup/setup.d/fetchmail.sh b/target/scripts/startup/setup.d/fetchmail.sh index 1d5b9570..d019f7a8 100644 --- a/target/scripts/startup/setup.d/fetchmail.sh +++ b/target/scripts/startup/setup.d/fetchmail.sh @@ -51,8 +51,7 @@ function _setup_fetchmail_parallel() { fi local COUNTER=0 SERVER=0 - while read -r LINE - do + while read -r LINE; do if [[ ${LINE} =~ poll ]]; then # If we read "poll" then we reached a new server definition # We need to create a new file with fetchmail defaults from diff --git a/target/scripts/startup/setup.d/networking.sh b/target/scripts/startup/setup.d/networking.sh index 8bf019e9..fd918520 100644 --- a/target/scripts/startup/setup.d/networking.sh +++ b/target/scripts/startup/setup.d/networking.sh @@ -22,8 +22,7 @@ function _setup_docker_permit() { _dms_panic__misconfigured 'NETWORK_INTERFACE' 'Network Setup [docker_permit]' fi - while read -r IP - do + while read -r IP; do CONTAINER_NETWORKS+=("${IP}") done < <(ip -o -4 addr show type veth | grep -E -o '[0-9\.]+/[0-9]+') diff --git a/target/scripts/startup/setup.d/postfix.sh b/target/scripts/startup/setup.d/postfix.sh index 5a57ee7c..0d7cb1ae 100644 --- a/target/scripts/startup/setup.d/postfix.sh +++ b/target/scripts/startup/setup.d/postfix.sh @@ -107,8 +107,7 @@ function __postfix__setup_override_configuration() { fi if [[ -f /tmp/docker-mailserver/postfix-master.cf ]]; then - while read -r LINE - do + while read -r LINE; do if [[ ${LINE} =~ ^[0-9a-z] ]]; then postconf -P "${LINE}" fi diff --git a/target/scripts/startup/setup.d/security/rspamd.sh b/target/scripts/startup/setup.d/security/rspamd.sh index e56433b0..d6051177 100644 --- a/target/scripts/startup/setup.d/security/rspamd.sh +++ b/target/scripts/startup/setup.d/security/rspamd.sh @@ -316,8 +316,7 @@ function __rspamd__handle_user_modules_adjustments() { if [[ -f "${RSPAMD_CUSTOM_COMMANDS_FILE}" ]]; then __rspamd__log 'debug' "Found file '${RSPAMD_CUSTOM_COMMANDS_FILE}' - parsing and applying it" - while read -r COMMAND ARGUMENT1 ARGUMENT2 ARGUMENT3 - do + while read -r COMMAND ARGUMENT1 ARGUMENT2 ARGUMENT3; do case "${COMMAND}" in ('disable-module') diff --git a/target/scripts/update-check.sh b/target/scripts/update-check.sh index a542bdbb..9010371f 100755 --- a/target/scripts/update-check.sh +++ b/target/scripts/update-check.sh @@ -15,8 +15,7 @@ if [[ ! ${UPDATE_CHECK_INTERVAL} =~ ^[0-9]+[smhd]{1}$ ]]; then UPDATE_CHECK_INTERVAL='1d' fi -while true -do +while true; do # get remote version information LATEST=$(curl -Lsf "${VERSION_URL}")