From 174a6d12f8e2f91116ef237bda50b92ea32b27f5 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 10 Oct 2023 20:59:00 +0100 Subject: [PATCH] refactor: optimize sleep time functions - Refactored the code to optimize the sleep time functions. - Updated the `fn_sleep_time` function calls to `fn_sleep_time_1` in multiple files. - Removed unnecessary sleep time calls in some files. --- lgsm/modules/check_deps.sh | 4 ++-- lgsm/modules/check_glibc.sh | 2 ++ lgsm/modules/check_permissions.sh | 2 +- lgsm/modules/check_system_requirements.sh | 2 +- lgsm/modules/check_version.sh | 2 +- lgsm/modules/command_dev_details.sh | 2 +- lgsm/modules/command_fastdl.sh | 4 ++-- lgsm/modules/command_wipe.sh | 4 ++-- lgsm/modules/install_gslt.sh | 3 ++- lgsm/modules/install_logs.sh | 2 -- lgsm/modules/install_squad_license.sh | 2 +- lgsm/modules/install_stats.sh | 1 - lgsm/modules/install_ts3db.sh | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lgsm/modules/check_deps.sh b/lgsm/modules/check_deps.sh index 83742208e..251cd365c 100644 --- a/lgsm/modules/check_deps.sh +++ b/lgsm/modules/check_deps.sh @@ -306,14 +306,14 @@ fn_deps_detector() { missingdep=0 if [ "${commandname}" == "INSTALL" ]; then echo -e "${green}${deptocheck}${default}" - fn_sleep_time + fn_sleep_time_1 fi elif [ "${depstatus}" != "0" ]; then # If dependency is not found. missingdep=1 if [ "${commandname}" == "INSTALL" ]; then echo -e "${red}${deptocheck}${default}" - fn_sleep_time + fn_sleep_time_1 fi # If SteamCMD requirements are not met install will fail. if [ -n "${appid}" ]; then diff --git a/lgsm/modules/check_glibc.sh b/lgsm/modules/check_glibc.sh index 25357a461..43dbe1bb9 100644 --- a/lgsm/modules/check_glibc.sh +++ b/lgsm/modules/check_glibc.sh @@ -16,6 +16,7 @@ elif [ -z "${glibc}" ]; then fn_print_dots "glibc" fn_print_error_nl "glibc requirement unknown" fn_script_log_error "glibc requirement unknown" + fn_sleep_time_5 elif [ "$(printf '%s\n'${glibc}'\n' "${glibcversion}" | sort -V | head -n 1)" != "${glibc}" ]; then fn_print_dots "glibc" fn_print_error_nl "glibc requirements not met" @@ -26,4 +27,5 @@ elif [ "$(printf '%s\n'${glibc}'\n' "${glibcversion}" | sort -V | head -n 1)" != echo -en "\n" fn_print_information_nl "distro upgrade is required" fn_script_log_info "distro upgrade is required" + fn_sleep_time_5 fi diff --git a/lgsm/modules/check_permissions.sh b/lgsm/modules/check_permissions.sh index a6a37ce5c..fca5b1f70 100644 --- a/lgsm/modules/check_permissions.sh +++ b/lgsm/modules/check_permissions.sh @@ -171,7 +171,7 @@ fn_sys_perm_fix_manually_msg() { fn_script_log_info "To fix this issue, run the following command as root:" echo -e " chmod a+rx /sys /sys/class /sys/class/net" fn_script_log "chmod a+rx /sys /sys/class /sys/class/net" - fn_sleep_time + fn_sleep_time_5 if [ "${monitorflag}" == 1 ]; then alert="permissions" alert.sh diff --git a/lgsm/modules/check_system_requirements.sh b/lgsm/modules/check_system_requirements.sh index 88fb9d15a..09074d7e7 100644 --- a/lgsm/modules/check_system_requirements.sh +++ b/lgsm/modules/check_system_requirements.sh @@ -50,6 +50,6 @@ if [ "${ramrequirementmb}" ]; then # Warn the user. fn_print_warn_nl "Check RAM: ${ramrequirementgb}G required, ${physmemtotal} available" echo "* ${gamename} server may fail to run or experience poor performance." - fn_sleep_time + fn_sleep_time_5 fi fi diff --git a/lgsm/modules/check_version.sh b/lgsm/modules/check_version.sh index 3ca015843..5369fd832 100644 --- a/lgsm/modules/check_version.sh +++ b/lgsm/modules/check_version.sh @@ -16,8 +16,8 @@ if [ -n "${modulesversion}" ] && [ -n "${version}" ] && [ "${version}" != "${mod echo -e "* ${selfname}: ${version}" echo -e "* modules: ${modulesversion}" echo -e "" - fn_sleep_time fn_script_log_error "LinuxGSM Version mismatch: ${selfname}: ${version}: modules: ${modulesversion}" + fn_sleep_time_1 command_update_linuxgsm.sh fn_firstcommand_reset fi diff --git a/lgsm/modules/command_dev_details.sh b/lgsm/modules/command_dev_details.sh index 2659465d3..93dae77bc 100644 --- a/lgsm/modules/command_dev_details.sh +++ b/lgsm/modules/command_dev_details.sh @@ -19,8 +19,8 @@ carriagereturn=$(file -b "${servercfgfullpath}" | grep -q CRLF && echo "${red}CR echo -e "" echo -e "${bold}${lightgreen}Server Details${default}" fn_messages_separator -echo -e "" +echo -e "" echo -e "Game: ${gamename}" echo -e "Config type: ${configtype}" echo -e "Config file: ${servercfgfullpath}" diff --git a/lgsm/modules/command_fastdl.sh b/lgsm/modules/command_fastdl.sh index acc3a1ba4..e1b25ec97 100644 --- a/lgsm/modules/command_fastdl.sh +++ b/lgsm/modules/command_fastdl.sh @@ -209,7 +209,7 @@ fn_fastdl_preview() { fi if [ -f "${tmpdir}/fastdl_files_to_compress.txt" ]; then echo -e "calculating total file size..." - fn_sleep_time + fn_sleep_time_1 totalfiles=$(wc -l < "${tmpdir}/fastdl_files_to_compress.txt") # Calculates total file size. while read -r dufile; do @@ -276,7 +276,7 @@ fn_fastdl_gmod() { fi # Clear addons directory in fastdl. echo -en "clearing addons dir from fastdl dir..." - fn_sleep_time + fn_sleep_time_1 rm -rf "${fastdldir:?}/addons" exitcode=$? if [ "${exitcode}" != 0 ]; then diff --git a/lgsm/modules/command_wipe.sh b/lgsm/modules/command_wipe.sh index 589f2ca6b..7527c8b85 100644 --- a/lgsm/modules/command_wipe.sh +++ b/lgsm/modules/command_wipe.sh @@ -79,7 +79,7 @@ fn_map_wipe_warning() { fn_script_log_warn "Map wipe will reset the map data and keep blueprint data" totalseconds=3 for seconds in {3..1}; do - fn_print_warn "Map wipe will reset the map data and keep blueprint data: ${totalseconds}" + fn_print_warn "map wipe will reset the map data and keep blueprint data: ${totalseconds}" totalseconds=$((totalseconds - 1)) fn_sleep_time_1 if [ "${seconds}" == "0" ]; then @@ -94,7 +94,7 @@ fn_full_wipe_warning() { fn_script_log_warn "Server wipe will reset the map data and remove blueprint data" totalseconds=3 for seconds in {3..1}; do - fn_print_warn "Server wipe will reset the map data and remove blueprint data: ${totalseconds}" + fn_print_warn "server wipe will reset the map data and remove blueprint data: ${totalseconds}" totalseconds=$((totalseconds - 1)) fn_sleep_time_1 if [ "${seconds}" == "0" ]; then diff --git a/lgsm/modules/install_gslt.sh b/lgsm/modules/install_gslt.sh index 772885d64..344f21ceb 100644 --- a/lgsm/modules/install_gslt.sh +++ b/lgsm/modules/install_gslt.sh @@ -36,7 +36,7 @@ if [ -z "${autoinstall}" ]; then fi fi fi -fn_sleep_time + if [ "${shortname}" == "tu" ]; then echo -e "The GSLT can be changed by editing ${servercfgdir}/${servercfg}." fn_script_log_info "The GSLT can be changed by editing ${servercfgdir}/${servercfg}." @@ -44,4 +44,5 @@ else echo -e "The GSLT can be changed by editing ${configdirserver}/${selfname}.cfg." fn_script_log_info "The GSLT can be changed by editing ${configdirserver}/${selfname}.cfg." fi +fn_sleep_time_1 echo -e "" diff --git a/lgsm/modules/install_logs.sh b/lgsm/modules/install_logs.sh index 5b12dd3e1..294bc1e46 100644 --- a/lgsm/modules/install_logs.sh +++ b/lgsm/modules/install_logs.sh @@ -11,9 +11,7 @@ if [ "${checklogs}" != "1" ]; then echo -e "" echo -e "${bold}${lightyellow}Creating Log Directories${default}" fn_messages_separator - fn_sleep_time fi -fn_sleep_time # Create LinuxGSM logs. echo -en "installing log dir: ${logdir}..." mkdir -p "${logdir}" diff --git a/lgsm/modules/install_squad_license.sh b/lgsm/modules/install_squad_license.sh index 604b3bcad..28f4456a5 100644 --- a/lgsm/modules/install_squad_license.sh +++ b/lgsm/modules/install_squad_license.sh @@ -18,7 +18,7 @@ echo -e "https://squad.fandom.com/wiki/Server_licensing" fn_script_log_info "Get more info and a server license here:" fn_script_log_info "https://squad.fandom.com/wiki/Server_licensing" echo -e "" -fn_sleep_time +fn_sleep_time_1 echo -e "The Squad server license can be changed by editing ${servercfgdir}/License.cfg." fn_script_log_info "The Squad server license can be changed by editing ${selfname}." echo -e "" diff --git a/lgsm/modules/install_stats.sh b/lgsm/modules/install_stats.sh index c3e92323d..40a13434d 100644 --- a/lgsm/modules/install_stats.sh +++ b/lgsm/modules/install_stats.sh @@ -10,7 +10,6 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" echo -e "" echo -e "${bold}${lightyellow}LinuxGSM Stats${default}" fn_messages_separator -fn_sleep_time echo -e "Assist LinuxGSM development by sending anonymous stats to developers." echo -e "Collected data is publicly available: ${italic}https://linuxgsm.com/data/usage${default}" echo -e "More info: ${italic}https://docs.linuxgsm.com/configuration/linuxgsm-stats${default}" diff --git a/lgsm/modules/install_ts3db.sh b/lgsm/modules/install_ts3db.sh index b88099183..464bd686a 100644 --- a/lgsm/modules/install_ts3db.sh +++ b/lgsm/modules/install_ts3db.sh @@ -45,7 +45,7 @@ fn_install_ts3db_mariadb() { sed -i "s/dbpluginparameter=/dbpluginparameter=ts3db_mariadb.ini/g" "${servercfgfullpath}" sed -i "s/dbsqlcreatepath=create_sqlite\//dbsqlcreatepath=create_mariadb\//g" "${servercfgfullpath}" echo -e "updating ts3db_mariadb.ini." - fn_sleep_time + fn_sleep_time_1 } echo -e ""