From e499c1c450c0ea8c846e0b236afa3adce8358e7d Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 30 Sep 2023 21:11:50 +0100 Subject: [PATCH] refactor: improve conditional statements in install_config.sh The code changes refactor the conditional statements in the `install_config.sh` file. Instead of checking if `${shortname}` is equal to "dst" or "arma3", it now checks if `${clustercfgdir}` or `${networkcfgdir}` are not empty, respectively. This improves readability and maintainability of the code. a --- lgsm/modules/install_config.sh | 45 +++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lgsm/modules/install_config.sh b/lgsm/modules/install_config.sh index 07aeca5552..e838e9735b 100644 --- a/lgsm/modules/install_config.sh +++ b/lgsm/modules/install_config.sh @@ -10,26 +10,47 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" # Checks if server cfg dir exists, creates it if it doesn't. fn_check_cfgdir() { changes="" - if [ "${shortname}" == "dst" ]; then + if [ -n "${clustercfgdir}" ]; then echo -en "creating config directory [ ${italic}${clustercfgdir}${default} ]" changes+=$(mkdir -pv "${clustercfgdir}") - elif [ "${shortname}" == "arma3" ]; then + if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 + fn_print_fail_eol_nl + fn_script_log_fatal "creating ${servercfgdir} config directory" + core_exit.sh + elif [ "${changes}" != "" ]; then + fn_print_ok_eol_nl + fn_script_log_pass "creating ${servercfgdir} config directory" + else + fn_print_skip_eol_nl + fi + elif [ -n "${networkcfgdir}" ]; then echo -en "creating config directory [ ${italic}${networkcfgdir}${default} ]" changes+=$(mkdir -pv "${networkcfgdir}") + if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 + fn_print_fail_eol_nl + fn_script_log_fatal "creating ${servercfgdir} config directory" + core_exit.sh + elif [ "${changes}" != "" ]; then + fn_print_ok_eol_nl + fn_script_log_pass "creating ${servercfgdir} config directory" + else + fn_print_skip_eol_nl + fi else echo -en "creating config directory [ ${italic}${servercfgdir}${default} ]" changes+=$(mkdir -pv "${servercfgdir}") + if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 + fn_print_fail_eol_nl + fn_script_log_fatal "creating ${servercfgdir} config directory" + core_exit.sh + elif [ "${changes}" != "" ]; then + fn_print_ok_eol_nl + fn_script_log_pass "creating ${servercfgdir} config directory" + else + fn_print_skip_eol_nl + fi fi - if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 - fn_print_fail_eol_nl - fn_script_log_fatal "creating ${servercfgdir} config directory" - core_exit.sh - elif [ "${changes}" != "" ]; then - fn_print_ok_eol_nl - fn_script_log_pass "creating ${servercfgdir} config directory" - else - fn_print_skip_eol_nl - fi + unset changes }