Skip to content

Commit 68ae13c

Browse files
authored
feat: change sleep timers (#4339)
* refactor: simplify sleep time functions The `fn_sleep_time` function has been refactored to remove unnecessary conditions and set a default sleep time of 0.5 seconds. Additionally, four new functions (`fn_sleep_time_1`, `fn_sleep_time_5`, `fn_sleep_time_10`) have been added to provide different sleep times of 1, 5, and 10 seconds respectively. This improves code readability and allows for more flexibility in setting sleep times. * change sleep to fn_sleep_time * 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. * refactor: simplify sleep time function call The code changes refactor the sleep time function call in the check_deps.sh file. Instead of calling fn_sleep_time_1, it now calls fn_sleep_time. This change simplifies the code and improves readability. * feat: add sleep time before checking session Add a sleep time of 1 second before checking the session in the command_monitor.sh file. This allows for better synchronization and improves the accuracy of the session check. * changes * refactor: optimize sleep time function The code changes refactor the sleep time function in multiple files to improve efficiency. The fn_sleep_time function is replaced with fn_sleep_time_1. This change reduces unnecessary delays during execution. * refactor: update sleep time function names The sleep time functions in the core_messages.sh file have been updated to use more descriptive names. The fn_sleep_time function has been renamed to fn_sleep_time_1 for clarity and consistency. This change improves code readability and maintainability. * refactor: optimize sleep time in core_messages.sh The commit optimizes the sleep time in the core_messages.sh file. The fn_sleep_time and fn_print_dots functions now use a shorter sleep time of 0.5 seconds instead of 1 second, resulting in faster execution. * refactor: improve readability and consistency in code - Refactored the log messages to use consistent capitalization and wording. - Updated log messages in check_glibc.sh, check_permissions.sh, command_backup.sh, command_update_linuxgsm.sh, command_wipe.sh, fix_samp.sh, install_config.sh, and set_dst_config_vars() functions. feat: add more descriptive log messages - Added more descriptive log messages to provide clearer information about the actions being performed. - Updated log messages in check_glibc.sh, check_permissions.sh, command_backup.sh, command_update_linuxgsm.sh, command_wipe.sh, fix_samp.sh, install_config.sh. fix: correct spelling errors in log messages - Corrected spelling errors in some of the log messages for better clarity. - Updated log messages in check_glibc.sh and fix_samp.sh. * refactor: remove unnecessary print statements This commit refactors the code by removing unnecessary print statements in multiple files. The removed print statements were used for displaying dots and warnings, but they are not needed anymore. This improves the readability and cleanliness of the code. * refactor: improve commit messages for code changes - Refactored check_glibc.sh to improve readability and clarity of error messages. - Refactored check_permissions.sh to provide more informative error messages when checking /sys permissions. - Refactored check_system_requirements.sh to provide clearer warning message when checking RAM requirements. - Refactored command_backup.sh to provide more descriptive messages when starting a backup. * remove legacy code * fix: remove \t * fix: run check_root check root was never running because of logic in linuxgsm.sh * fix: update warning message for missing sudo access The warning message for users without sudo access has been updated to provide clearer instructions. Instead of just suggesting manual installation, it now also suggests running the script as root using `./${selfname} install`. This change improves user experience and helps them resolve dependency installation issues more effectively. * tidy
1 parent 9ff3409 commit 68ae13c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+171
-181
lines changed

.github/workflows/serverlist-validate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ csvlist="$(ls -1 | grep -E '^(ubuntu|debian|centos|rhel|almalinux|rocky).*\.csv$
1010
# loop though each csv file and make sure the number of lines is the same as the serverlistcount
1111
for csv in $csvlist; do
1212
csvcount="$(wc -l < "${csv}")"
13-
csvcount=$((csvcount-2))
13+
csvcount=$((csvcount - 2))
1414
if [ "$csvcount" -ne "$serverlistcount" ]; then
1515
echo "ERROR: $csv ($csvcount) does not match serverlist.csv ($serverlistcount)"
1616
exitcode=1

lgsm/functions/check_status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
99

10-
status=$(tmux -L "${sessionname}" list-sessions -F "#{session_name}" 2>/dev/null | grep -Ecx "^${sessionname}")
10+
status=$(tmux -L "${sessionname}" list-sessions -F "#{session_name}" 2> /dev/null | grep -Ecx "^${sessionname}")

lgsm/functions/command_stop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn_stop_graceful_ctrlc() {
1515
fn_print_dots "Graceful: CTRL+c"
1616
fn_script_log_info "Graceful: CTRL+c"
1717
# Sends quit.
18-
tmux -L "${sessionname}" send-keys -t "${sessionname}" C-c > /dev/null 2>&1
18+
tmux -L "${sessionname}" send-keys -t "${sessionname}" C-c > /dev/null 2>&1
1919
# Waits up to 30 seconds giving the server time to shutdown gracefuly.
2020
for seconds in {1..30}; do
2121
check_status.sh

lgsm/modules/check_config.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
99

1010
if [ -n "${servercfgfullpath}" ] && [ ! -f "${servercfgfullpath}" ]; then
11-
fn_print_dots ""
1211
fn_print_warn_nl "Configuration file missing!"
1312
echo -e "${servercfgfullpath}"
1413
fn_script_log_warn "Configuration file missing!"
@@ -17,11 +16,9 @@ if [ -n "${servercfgfullpath}" ] && [ ! -f "${servercfgfullpath}" ]; then
1716
fi
1817

1918
if [ "${shortname}" == "rust" ] && [ -v rconpassword ] && [ -z "${rconpassword}" ]; then
20-
fn_print_dots ""
2119
fn_print_fail_nl "RCON password is not set"
2220
fn_script_log_warn "RCON password is not set"
2321
elif [ -v rconpassword ] && [ "${rconpassword}" == "CHANGE_ME" ]; then
24-
fn_print_dots ""
2522
fn_print_warn_nl "Default RCON Password detected"
2623
fn_script_log_warn "Default RCON Password detected"
2724
fi

lgsm/modules/check_deps.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ fn_install_mono_repo() {
2525
fn_print_information_nl "Automatically adding Mono repository."
2626
fn_script_log_info "Automatically adding Mono repository."
2727
echo -en ".\r"
28-
sleep 1
28+
fn_sleep_time_1
2929
echo -en "..\r"
30-
sleep 1
30+
fn_sleep_time_1
3131
echo -en "...\r"
32-
sleep 1
32+
fn_sleep_time_1
3333
echo -en " \r"
3434
if [ "${distroid}" == "ubuntu" ]; then
3535
if [ "${distroversion}" == "22.04" ]; then
@@ -160,8 +160,8 @@ fn_install_missing_deps() {
160160
fn_print_information_nl "$(whoami) has sudo access."
161161
fn_script_log_info "$(whoami) has sudo access."
162162
else
163-
fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies."
164-
fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies."
163+
fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies or run ./${selfname} install as root."
164+
fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies or run ./${selfname} install as root."
165165
fi
166166
fi
167167

@@ -177,11 +177,11 @@ fn_install_missing_deps() {
177177
fn_print_information_nl "Automatically installing missing dependencies."
178178
fn_script_log_info "Automatically installing missing dependencies."
179179
echo -en ".\r"
180-
sleep 1
180+
fn_sleep_time_1
181181
echo -en "..\r"
182-
sleep 1
182+
fn_sleep_time_1
183183
echo -en "...\r"
184-
sleep 1
184+
fn_sleep_time_1
185185
echo -en " \r"
186186
if [ "$(command -v apt 2> /dev/null)" ]; then
187187
cmd="echo steamcmd steam/question select \"I AGREE\" | sudo debconf-set-selections; echo steamcmd steam/license note '' | sudo debconf-set-selections; ${i386installcommand}sudo apt-get update; sudo apt-get -y install ${array_deps_missing[*]}"
@@ -306,14 +306,14 @@ fn_deps_detector() {
306306
missingdep=0
307307
if [ "${commandname}" == "INSTALL" ]; then
308308
echo -e "${green}${deptocheck}${default}"
309-
sleep 0.1
309+
fn_sleep_time
310310
fi
311311
elif [ "${depstatus}" != "0" ]; then
312312
# If dependency is not found.
313313
missingdep=1
314314
if [ "${commandname}" == "INSTALL" ]; then
315315
echo -e "${red}${deptocheck}${default}"
316-
sleep 0.1
316+
fn_sleep_time
317317
fi
318318
# If SteamCMD requirements are not met install will fail.
319319
if [ -n "${appid}" ]; then

lgsm/modules/check_glibc.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ if [ "${glibc}" == "null" ]; then
1313
# Glibc is not required.
1414
:
1515
elif [ -z "${glibc}" ]; then
16-
fn_print_dots "glibc"
17-
fn_print_error_nl "glibc requirement unknown"
18-
fn_script_log_error "glibc requirement unknown"
16+
fn_print_dots "Checking glibc"
17+
fn_print_error_nl "Checking glibc: requirement unknown"
18+
fn_script_log_error "Checking glibc: requirement unknown"
19+
fn_sleep_time_5
1920
elif [ "$(printf '%s\n'${glibc}'\n' "${glibcversion}" | sort -V | head -n 1)" != "${glibc}" ]; then
20-
fn_print_dots "glibc"
21-
fn_print_error_nl "glibc requirements not met"
22-
fn_script_log_error "glibc requirements not met"
21+
fn_print_dots "Checking glibc"
22+
fn_print_error_nl "Checking glibc: requirements not met"
23+
fn_script_log_error "Checking glibc: requirements not met"
2324
echo -en "\n"
2425
echo -e " * glibc required: ${glibc}"
2526
echo -e " * glibc installed: ${red}${glibcversion}${default}"
2627
echo -en "\n"
27-
fn_print_information_nl "distro upgrade is required"
28-
fn_script_log_info "distro upgrade is required"
28+
fn_print_information_nl "Distro upgrade is required"
29+
fn_script_log_info "Distro upgrade is required"
30+
fn_sleep_time_5
2931
fi

lgsm/modules/check_permissions.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn_sys_perm_fix_manually_msg() {
171171
fn_script_log_info "To fix this issue, run the following command as root:"
172172
echo -e " chmod a+rx /sys /sys/class /sys/class/net"
173173
fn_script_log "chmod a+rx /sys /sys/class /sys/class/net"
174-
fn_sleep_time
174+
fn_sleep_time_5
175175
if [ "${monitorflag}" == 1 ]; then
176176
alert="permissions"
177177
alert.sh
@@ -182,8 +182,8 @@ fn_sys_perm_fix_manually_msg() {
182182
# Attempt to fix /sys related permission errors if sudo is available, exits otherwise.
183183
fn_sys_perm_errors_fix() {
184184
if sudo -n true > /dev/null 2>&1; then
185-
fn_print_dots "Automatically fixing /sys permissions"
186-
fn_script_log_info "Automatically fixing /sys permissions."
185+
fn_print_dots "Fixing /sys permissions"
186+
fn_script_log_info "Fixing /sys permissions."
187187
if [ "${sysdirpermerror}" == "1" ]; then
188188
sudo chmod a+rx "/sys"
189189
fi
@@ -202,7 +202,7 @@ fn_sys_perm_errors_fix() {
202202
# Show the user how to fix.
203203
fn_sys_perm_fix_manually_msg
204204
else
205-
fn_print_ok_nl "Automatically fixing /sys permissions"
205+
fn_print_ok_nl "Fixing /sys permissions"
206206
fn_script_log_pass "Permissions in /sys fixed"
207207
fi
208208
else
@@ -216,8 +216,9 @@ fn_sys_perm_error_process() {
216216
fn_sys_perm_errors_detect
217217
# If any error was found.
218218
if [ "${sysdirpermerror}" == "1" ] || [ "${classdirpermerror}" == "1" ] || [ "${netdirpermerror}" == "1" ]; then
219-
fn_print_error_nl "Permission error(s) found in /sys"
220-
fn_script_log_error "Permission error(s) found in /sys"
219+
fn_print_dots "Checking /sys permissions"
220+
fn_print_error_nl "Checking /sys permissions"
221+
fn_script_log_error "Checking /sys permissions"
221222
# Run the fix
222223
fn_sys_perm_errors_fix
223224
fi

lgsm/modules/check_root.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
99

1010
if [ "$(whoami)" == "root" ]; then
1111
if [ "${commandname}" != "INSTALL" ]; then
12-
fn_print_fail_nl "Do NOT run this script as root!"
12+
fn_print_fail_nl "Do NOT run as root!"
1313
if [ -d "${lgsmlogdir}" ]; then
1414
fn_script_log_fail "${selfname} attempted to run as root."
1515
else

lgsm/modules/check_system_requirements.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ fi
4646
# If the game or engine has a minimum RAM Requirement, compare it to system's available RAM.
4747
if [ "${ramrequirementmb}" ]; then
4848
if [ "${physmemtotalmb}" -lt "${ramrequirementmb}" ]; then
49-
fn_print_dots "Check RAM"
49+
fn_print_dots "Checking RAM"
5050
# Warn the user.
51-
fn_print_warn_nl "Check RAM: ${ramrequirementgb}G required, ${physmemtotal} available"
51+
fn_print_warn_nl "Checking RAM: ${ramrequirementgb}G required, ${physmemtotal} available"
5252
echo "* ${gamename} server may fail to run or experience poor performance."
53-
fn_sleep_time
53+
fn_sleep_time_5
5454
fi
5555
fi

lgsm/modules/check_version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ if [ -n "${modulesversion}" ] && [ -n "${version}" ] && [ "${version}" != "${mod
1616
echo -e "* ${selfname}: ${version}"
1717
echo -e "* modules: ${modulesversion}"
1818
echo -e ""
19-
fn_sleep_time
2019
fn_script_log_error "LinuxGSM Version mismatch: ${selfname}: ${version}: modules: ${modulesversion}"
20+
fn_sleep_time_1
2121
command_update_linuxgsm.sh
2222
fn_firstcommand_reset
2323
fi

0 commit comments

Comments
 (0)