From 9f1448983d0e596a6c7bfe8acd216f5f3504cf05 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Thu, 28 Sep 2023 23:39:48 +0100 Subject: [PATCH] refactor: improve code readability and fix typos - Refactored the code to improve readability and organization. - Fixed typos in the comments and echo statements. - Changed some echo statements to use variables for better consistency. - Updated URLs in the echo statements to be clickable links. Co-authored-by: [co-author name] --- lgsm/modules/install_complete.sh | 10 ++-- lgsm/modules/install_config.sh | 85 ++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/lgsm/modules/install_complete.sh b/lgsm/modules/install_complete.sh index b936d6102..cc2488477 100644 --- a/lgsm/modules/install_complete.sh +++ b/lgsm/modules/install_complete.sh @@ -11,21 +11,21 @@ echo -e "" echo -e "${bold}=================================${default}" if [ "${exitcode}" == "1" ]; then - echo -e "Install Failed!" + echo -e "${red}Install Failed!${default}" fn_script_log_fatal "Install Failed!" elif [ "${exitcode}" == "2" ]; then - echo -e "Install Completed with Errors!" + echo -e "${red}Install Completed with Errors!${default}}" fn_script_log_error "Install Completed with Errors!" elif [ "${exitcode}" == "3" ]; then - echo -e "Install Completed with Warnings!" + echo -e "${lightyellow}Install Completed with Warnings!${default}}" fn_script_log_warn "Install Completed with Warnings!" elif [ -z "${exitcode}" ] || [ "${exitcode}" == "0" ]; then - echo -e "Install Complete!" + echo -e "${green}Install Complete!${default}}" fn_script_log_pass "Install Complete!" fi echo -e "" echo -e "To start the ${gamename} server type:" -echo -e "./${selfname} start" +echo -e "${italic}./${selfname} start${default}" echo -e "" core_exit.sh diff --git a/lgsm/modules/install_config.sh b/lgsm/modules/install_config.sh index 2a4d607d0..22cd9f19c 100644 --- a/lgsm/modules/install_config.sh +++ b/lgsm/modules/install_config.sh @@ -9,17 +9,24 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" # Checks if server cfg dir exists, creates it if it doesn't. fn_check_cfgdir() { - if [ ! -d "${servercfgdir}" ]; then + + if [ "${shortname}" == "dst" ]; then + echo -en "creating ${clustercfgfullpath} config directory" + mkdir -p "${clustercfgfullpath}" + elif [ "${shortname}" == "arma3" ]; then + echo -en "creating ${networkcfgfullpath} config directory" + mkdir -p "${networkcfgfullpath}" + else echo -en "creating ${servercfgdir} config directory" - mkdir -pv "${servercfgdir}" - if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 - fn_print_fail_eol - fn_script_log_fatal "creating ${servercfgdir} config directory" - core_exit.sh - else - fn_print_ok_eol - fn_script_log_pass "creating ${servercfgdir} config directory" - fi + mkdir -p "${servercfgdir}" + fi + if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 + fn_print_fail_eol + fn_script_log_fatal "creating ${servercfgdir} config directory" + core_exit.sh + else + fn_print_ok_eol + fn_script_log_pass "creating ${servercfgdir} config directory" fi } @@ -36,31 +43,35 @@ fn_default_config_remote() { fn_sleep_time githuburl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/main" for config in "${array_configs[@]}"; do - fn_fetch_file "${githuburl}/${shortname}/${config}" "${remote_fileurl_backup}" "GitHub" "Bitbucket" "${lgsmdir}/config-default/config-game" "${config}" "nochmodx" "norun" "forcedl" "nohash" - done - fn_check_cfgdir - for config in "${array_configs[@]}"; do - # every config is copied - echo -en "copying config file [ ${italic}${servercfgfullpath}${default} ]" - if [ "${config}" == "${servercfgdefault}" ]; then - mkdir -p "${servercfgdir}" - cp -nv "${lgsmdir}/config-default/config-game/${config}" "${servercfgfullpath}" - elif [ "${shortname}" == "arma3" ] && [ "${config}" == "${networkcfgdefault}" ]; then - mkdir -p "${servercfgdir}" - cp -nv "${lgsmdir}/config-default/config-game/${config}" "${networkcfgfullpath}" - elif [ "${shortname}" == "dst" ] && [ "${config}" == "${clustercfgdefault}" ]; then - mkdir -p "${clustercfgfullpath}" - cp -nv "${lgsmdir}/config-default/config-game/${clustercfgdefault}" "${clustercfgfullpath}" - else - mkdir -p "${servercfgdir}" - cp -nv "${lgsmdir}/config-default/config-game/${config}" "${servercfgdir}/${config}" - fi - if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 - fn_print_failure_eol_nl - fn_script_log_fatal "copying config file ${servercfgfullpath}" - else - fn_print_ok_eol_nl - fn_script_log_pass "copying config file ${servercfgfullpath}" + if [ ! -f "${lgsmdir}/config-default/config-game/${config}" ]; then + fn_fetch_file "${githuburl}/${shortname}/${config}" "${remote_fileurl_backup}" "GitHub" "Bitbucket" "${lgsmdir}/config-default/config-game" "${config}" "nochmodx" "norun" "forcedl" "nohash" + + fn_check_cfgdir + + changes="" + if [ "${config}" == "${servercfgdefault}" ]; then + echo -en "copying config file [ ${italic}${servercfgfullpath}${default} ]" + changes+=$(cp -n "${lgsmdir}/config-default/config-game/${config}" "${servercfgfullpath}") + elif [ "${shortname}" == "arma3" ] && [ "${config}" == "${networkcfgdefault}" ]; then + echo -en "copying config file [ ${italic}${networkcfgfullpath}${default} ]" + changes+=$(cp -n "${lgsmdir}/config-default/config-game/${config}" "${networkcfgfullpath}") + elif [ "${shortname}" == "dst" ] && [ "${config}" == "${clustercfgdefault}" ]; then + echo -en "copying config file [ ${italic}${clustercfgdefault}${default} ]" + changes+=$(cp -n "${lgsmdir}/config-default/config-game/${clustercfgdefault}" "${clustercfgfullpath}") + else + echo -en "copying config file [ ${italic}${servercfgdir}/${config}${default} ]" + changes+=$(cp -n "${lgsmdir}/config-default/config-game/${config}" "${servercfgdir}/${config}") + fi + if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181 + fn_print_failure_eol_nl + fn_script_log_fatal "copying config file ${servercfgfullpath}" + elif [ "${changes}" != "" ]; then + fn_print_ok_eol_nl + fn_script_log_pass "copying config file ${servercfgfullpath}" + else + fn_print_skip_eol_nl + fi + fi done } @@ -69,7 +80,7 @@ fn_default_config_remote() { fn_default_config_local() { fn_check_cfgdir echo -en "copying config file [ ${italic}${servercfgdefault}${default} ]" - cp -nv "${servercfgdir}/${servercfgdefault}" "${servercfgfullpath}" + cp -n "${servercfgdir}/${servercfgdefault}" "${servercfgfullpath}" if [ "${exitcode}" != 0 ]; then fn_print_fail_eol fn_script_log_fatal "copying config file [ ${servercfgdefault} ]" @@ -176,7 +187,7 @@ fn_list_config_locations() { fi fi echo -e "LinuxGSM config: ${italic}${lgsmdir}/config-lgsm/${gameservername}${default}" - echo -e "Config documentation: ${italic}https://docs.linuxgsm.com/configuration{default}" + echo -e "Config documentation: ${italic}https://docs.linuxgsm.com/configuration${default}" } if [ "${shortname}" == "sdtd" ]; then