Skip to content

Commit

Permalink
feat: change sleep timers (#4339)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dgibbs64 authored Oct 15, 2023
1 parent 9ff3409 commit 68ae13c
Show file tree
Hide file tree
Showing 48 changed files with 171 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/serverlist-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ csvlist="$(ls -1 | grep -E '^(ubuntu|debian|centos|rhel|almalinux|rocky).*\.csv$
# loop though each csv file and make sure the number of lines is the same as the serverlistcount
for csv in $csvlist; do
csvcount="$(wc -l < "${csv}")"
csvcount=$((csvcount-2))
csvcount=$((csvcount - 2))
if [ "$csvcount" -ne "$serverlistcount" ]; then
echo "ERROR: $csv ($csvcount) does not match serverlist.csv ($serverlistcount)"
exitcode=1
Expand Down
2 changes: 1 addition & 1 deletion lgsm/functions/check_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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

status=$(tmux -L "${sessionname}" list-sessions -F "#{session_name}" 2>/dev/null | grep -Ecx "^${sessionname}")
status=$(tmux -L "${sessionname}" list-sessions -F "#{session_name}" 2> /dev/null | grep -Ecx "^${sessionname}")
2 changes: 1 addition & 1 deletion lgsm/functions/command_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn_stop_graceful_ctrlc() {
fn_print_dots "Graceful: CTRL+c"
fn_script_log_info "Graceful: CTRL+c"
# Sends quit.
tmux -L "${sessionname}" send-keys -t "${sessionname}" C-c > /dev/null 2>&1
tmux -L "${sessionname}" send-keys -t "${sessionname}" C-c > /dev/null 2>&1
# Waits up to 30 seconds giving the server time to shutdown gracefuly.
for seconds in {1..30}; do
check_status.sh
Expand Down
3 changes: 0 additions & 3 deletions lgsm/modules/check_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

if [ -n "${servercfgfullpath}" ] && [ ! -f "${servercfgfullpath}" ]; then
fn_print_dots ""
fn_print_warn_nl "Configuration file missing!"
echo -e "${servercfgfullpath}"
fn_script_log_warn "Configuration file missing!"
Expand All @@ -17,11 +16,9 @@ if [ -n "${servercfgfullpath}" ] && [ ! -f "${servercfgfullpath}" ]; then
fi

if [ "${shortname}" == "rust" ] && [ -v rconpassword ] && [ -z "${rconpassword}" ]; then
fn_print_dots ""
fn_print_fail_nl "RCON password is not set"
fn_script_log_warn "RCON password is not set"
elif [ -v rconpassword ] && [ "${rconpassword}" == "CHANGE_ME" ]; then
fn_print_dots ""
fn_print_warn_nl "Default RCON Password detected"
fn_script_log_warn "Default RCON Password detected"
fi
Expand Down
20 changes: 10 additions & 10 deletions lgsm/modules/check_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ fn_install_mono_repo() {
fn_print_information_nl "Automatically adding Mono repository."
fn_script_log_info "Automatically adding Mono repository."
echo -en ".\r"
sleep 1
fn_sleep_time_1
echo -en "..\r"
sleep 1
fn_sleep_time_1
echo -en "...\r"
sleep 1
fn_sleep_time_1
echo -en " \r"
if [ "${distroid}" == "ubuntu" ]; then
if [ "${distroversion}" == "22.04" ]; then
Expand Down Expand Up @@ -160,8 +160,8 @@ fn_install_missing_deps() {
fn_print_information_nl "$(whoami) has sudo access."
fn_script_log_info "$(whoami) has sudo access."
else
fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies."
fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies."
fn_print_warning_nl "$(whoami) does not have sudo access. Manually install dependencies or run ./${selfname} install as root."
fn_script_log_warn "$(whoami) does not have sudo access. Manually install dependencies or run ./${selfname} install as root."
fi
fi

Expand All @@ -177,11 +177,11 @@ fn_install_missing_deps() {
fn_print_information_nl "Automatically installing missing dependencies."
fn_script_log_info "Automatically installing missing dependencies."
echo -en ".\r"
sleep 1
fn_sleep_time_1
echo -en "..\r"
sleep 1
fn_sleep_time_1
echo -en "...\r"
sleep 1
fn_sleep_time_1
echo -en " \r"
if [ "$(command -v apt 2> /dev/null)" ]; then
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[*]}"
Expand Down Expand Up @@ -306,14 +306,14 @@ fn_deps_detector() {
missingdep=0
if [ "${commandname}" == "INSTALL" ]; then
echo -e "${green}${deptocheck}${default}"
sleep 0.1
fn_sleep_time
fi
elif [ "${depstatus}" != "0" ]; then
# If dependency is not found.
missingdep=1
if [ "${commandname}" == "INSTALL" ]; then
echo -e "${red}${deptocheck}${default}"
sleep 0.1
fn_sleep_time
fi
# If SteamCMD requirements are not met install will fail.
if [ -n "${appid}" ]; then
Expand Down
18 changes: 10 additions & 8 deletions lgsm/modules/check_glibc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ if [ "${glibc}" == "null" ]; then
# Glibc is not required.
:
elif [ -z "${glibc}" ]; then
fn_print_dots "glibc"
fn_print_error_nl "glibc requirement unknown"
fn_script_log_error "glibc requirement unknown"
fn_print_dots "Checking glibc"
fn_print_error_nl "Checking glibc: requirement unknown"
fn_script_log_error "Checking 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"
fn_script_log_error "glibc requirements not met"
fn_print_dots "Checking glibc"
fn_print_error_nl "Checking glibc: requirements not met"
fn_script_log_error "Checking glibc: requirements not met"
echo -en "\n"
echo -e " * glibc required: ${glibc}"
echo -e " * glibc installed: ${red}${glibcversion}${default}"
echo -en "\n"
fn_print_information_nl "distro upgrade is required"
fn_script_log_info "distro upgrade is required"
fn_print_information_nl "Distro upgrade is required"
fn_script_log_info "Distro upgrade is required"
fn_sleep_time_5
fi
13 changes: 7 additions & 6 deletions lgsm/modules/check_permissions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -182,8 +182,8 @@ fn_sys_perm_fix_manually_msg() {
# Attempt to fix /sys related permission errors if sudo is available, exits otherwise.
fn_sys_perm_errors_fix() {
if sudo -n true > /dev/null 2>&1; then
fn_print_dots "Automatically fixing /sys permissions"
fn_script_log_info "Automatically fixing /sys permissions."
fn_print_dots "Fixing /sys permissions"
fn_script_log_info "Fixing /sys permissions."
if [ "${sysdirpermerror}" == "1" ]; then
sudo chmod a+rx "/sys"
fi
Expand All @@ -202,7 +202,7 @@ fn_sys_perm_errors_fix() {
# Show the user how to fix.
fn_sys_perm_fix_manually_msg
else
fn_print_ok_nl "Automatically fixing /sys permissions"
fn_print_ok_nl "Fixing /sys permissions"
fn_script_log_pass "Permissions in /sys fixed"
fi
else
Expand All @@ -216,8 +216,9 @@ fn_sys_perm_error_process() {
fn_sys_perm_errors_detect
# If any error was found.
if [ "${sysdirpermerror}" == "1" ] || [ "${classdirpermerror}" == "1" ] || [ "${netdirpermerror}" == "1" ]; then
fn_print_error_nl "Permission error(s) found in /sys"
fn_script_log_error "Permission error(s) found in /sys"
fn_print_dots "Checking /sys permissions"
fn_print_error_nl "Checking /sys permissions"
fn_script_log_error "Checking /sys permissions"
# Run the fix
fn_sys_perm_errors_fix
fi
Expand Down
2 changes: 1 addition & 1 deletion lgsm/modules/check_root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

if [ "$(whoami)" == "root" ]; then
if [ "${commandname}" != "INSTALL" ]; then
fn_print_fail_nl "Do NOT run this script as root!"
fn_print_fail_nl "Do NOT run as root!"
if [ -d "${lgsmlogdir}" ]; then
fn_script_log_fail "${selfname} attempted to run as root."
else
Expand Down
6 changes: 3 additions & 3 deletions lgsm/modules/check_system_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ fi
# If the game or engine has a minimum RAM Requirement, compare it to system's available RAM.
if [ "${ramrequirementmb}" ]; then
if [ "${physmemtotalmb}" -lt "${ramrequirementmb}" ]; then
fn_print_dots "Check RAM"
fn_print_dots "Checking RAM"
# Warn the user.
fn_print_warn_nl "Check RAM: ${ramrequirementgb}G required, ${physmemtotal} available"
fn_print_warn_nl "Checking 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
2 changes: 1 addition & 1 deletion lgsm/modules/check_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 13 additions & 37 deletions lgsm/modules/command_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ commandaction="Backing up"
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_set

check.sh

# Trap to remove lockfile on quit.
fn_backup_trap() {
echo -e ""
Expand Down Expand Up @@ -56,12 +54,14 @@ fn_backup_init() {
backupname="${selfname}-$(date '+%Y-%m-%d-%H%M%S')"

info_distro.sh
fn_print_dots "Backup starting"
fn_script_log_info "Backup starting"
fn_print_ok_nl "Backup starting"
fn_print_dots "Starting backup"
fn_script_log_info "Starting backup"
if [ ! -d "${backupdir}" ] || [ "${backupcount}" == "0" ]; then
fn_print_info_nl "There are no previous backups"
fn_print_info_nl "Starting backup: No previous backups found"
fn_script_log_info "No previous backups found"
else
fn_print_info_nl "Starting backup: Previous backups found"
fn_script_log_info "Previous backups found"
if [ "${lastbackupdaysago}" == "0" ]; then
daysago="less than 1 day ago"
elif [ "${lastbackupdaysago}" == "1" ]; then
Expand Down Expand Up @@ -101,32 +101,6 @@ fn_backup_dir() {
fi
}

# Migrate Backups from old dir before refactor
fn_backup_migrate_olddir() {
# Check if old backup dir is there before the refactor and move the backups
if [ -d "${rootdir}/backups" ]; then
if [ "${rootdir}/backups" != "${backupdir}" ]; then
fn_print_dots "Backup directory is being migrated"
fn_script_log_info "Backup directory is being migrated"
fn_script_log_info "${rootdir}/backups > ${backupdir}"
mv "${rootdir}/backups/"* "${backupdir}" 2> /dev/null
exitcode=$?
if [ "${exitcode}" == 0 ]; then
rmdir "${rootdir}/backups" 2> /dev/null
exitcode=$?
fi
if [ "${exitcode}" != 0 ]; then
fn_print_error_nl "Backup directory is being migrated"
fn_script_log_error "Backup directory is being migrated"
else

fn_print_ok_nl "Backup directory is being migrated"
fn_script_log_pass "Backup directory is being migrated"
fi
fi
fi
}

fn_backup_create_lockfile() {
# Create lockfile.
date '+%s' > "${lockdir:?}/backup.lock"
Expand All @@ -142,7 +116,7 @@ fn_backup_compression() {
fn_print_info "A total of ${rootdirduexbackup} will be compressed."
fn_script_log_info "A total of ${rootdirduexbackup} will be compressed: ${backupdir}/${backupname}.tar.gz"
fn_print_dots "Backup (${rootdirduexbackup}) ${backupname}.tar.gz, in progress..."
fn_script_log_info "backup ${rootdirduexbackup} ${backupname}.tar.gz, in progress"
fn_script_log_info "Backup ${rootdirduexbackup} ${backupname}.tar.gz, in progress"
excludedir=$(fn_backup_relpath)

# Check that excludedir is a valid path.
Expand Down Expand Up @@ -187,7 +161,7 @@ fn_backup_prune() {
# Display how many backups will be cleared.
echo -e "* Pruning: ${backupquotadiff} backup(s) has exceeded the ${maxbackups} backups limit"
fn_script_log_info "Pruning: ${backupquotadiff} backup(s) has exceeded the ${maxbackups} backups limit"
fn_sleep_time
fn_sleep_time_1
fn_print_dots "Pruning: Clearing ${backupquotadiff} backup(s)"
fn_script_log_info "Pruning: Clearing ${backupquotadiff} backup(s)"
# Clear backups over quota.
Expand All @@ -199,7 +173,7 @@ fn_backup_prune() {
# Display how many backups will be cleared.
echo -e "* Pruning: ${backupsoudatedcount} backup(s) are older than ${maxbackupdays} days."
fn_script_log_info "Pruning: ${backupsoudatedcount} backup(s) older than ${maxbackupdays} days."
fn_sleep_time
fn_sleep_time_1
fn_print_dots "Pruning: Clearing ${backupquotadiff} backup(s)."
fn_script_log_info "Pruning: Clearing ${backupquotadiff} backup(s)"
# Clear backups over quota
Expand Down Expand Up @@ -264,12 +238,14 @@ fn_backup_start_server() {
fi
}

# Run functions.
fn_print_dots ""
check.sh
core_logs.sh

fn_backup_check_lockfile
fn_backup_init
fn_backup_stop_server
fn_backup_dir
fn_backup_migrate_olddir
fn_backup_create_lockfile
fn_backup_compression
fn_backup_prune
Expand Down
4 changes: 4 additions & 0 deletions lgsm/modules/command_dev_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ commandaction="Developer debug"
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_reset

fn_print_dots ""
check.sh
core_logs.sh

if [ -f "${rootdir}/.dev-debug" ]; then
rm -f "${rootdir:?}/.dev-debug"
fn_print_ok_nl "Disabled dev-debug"
Expand Down
2 changes: 1 addition & 1 deletion lgsm/modules/command_dev_details.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
11 changes: 5 additions & 6 deletions lgsm/modules/command_fastdl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ commandaction="Fastdl"
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_set

check.sh

# Directories.
if [ -z "${webdir}" ]; then
webdir="${rootdir}/public_html"
Expand Down Expand Up @@ -209,7 +207,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
Expand Down Expand Up @@ -276,7 +274,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
Expand All @@ -291,7 +289,7 @@ fn_fastdl_gmod() {
# Correct content that may be into a lua directory by mistake like some darkrpmodification addons.
if [ -d "${fastdldir}/lua" ]; then
echo -en "correcting DarkRP files..."
fn_sleep_time
fn_sleep_time_1
cp -Rf "${fastdldir}/lua/"* "${fastdldir}"
exitcode=$?
if [ "${exitcode}" != 0 ]; then
Expand Down Expand Up @@ -335,7 +333,7 @@ fn_fastdl_source() {
tput rc
tput el
echo -e "copying ${directory} ${allowed_extention} : ${fileswc}..."
fn_sleep_time
fn_sleep_time_1
# get relative path of file in the dir
tmprelfilepath="${fastdlfile#"${systemdir}/"}"
copytodir="${tmprelfilepath%/*}"
Expand Down Expand Up @@ -427,6 +425,7 @@ fn_fastdl_bzip2() {
fn_print_ok_eol_nl
}

check.sh
# Run functions.
fn_fastdl_preview
fn_clear_old_fastdl
Expand Down
Loading

0 comments on commit 68ae13c

Please sign in to comment.