Skip to content
Permalink
Browse files

feat: general code standards improvements (#2730)

* add missing space in ; then

* standardise command if

* standardised True if the length of "STRING" is non-zero.

* changed -e to -f
  • Loading branch information
dgibbs64 committed Mar 10, 2020
1 parent 3a6f7f9 commit abaa614cad3d1e57d6c80fb1ac3496d032b69802
Showing with 174 additions and 173 deletions.
  1. +2 −2 lgsm/config-default/config-lgsm/rustserver/_default.cfg
  2. +1 −1 lgsm/functions/alert_discord.sh
  3. +1 −1 lgsm/functions/alert_email.sh
  4. +1 −1 lgsm/functions/alert_ifttt.sh
  5. +1 −1 lgsm/functions/alert_pushbullet.sh
  6. +1 −1 lgsm/functions/alert_pushover.sh
  7. +1 −1 lgsm/functions/alert_telegram.sh
  8. +1 −1 lgsm/functions/check.sh
  9. +1 −1 lgsm/functions/check_config.sh
  10. +4 −4 lgsm/functions/check_deps.sh
  11. +1 −1 lgsm/functions/check_ip.sh
  12. +1 −1 lgsm/functions/check_logs.sh
  13. +1 −1 lgsm/functions/check_permissions.sh
  14. +1 −1 lgsm/functions/check_system_requirements.sh
  15. +2 −2 lgsm/functions/check_tmuxception.sh
  16. +1 −1 lgsm/functions/command_backup.sh
  17. +5 −5 lgsm/functions/command_debug.sh
  18. +1 −1 lgsm/functions/command_dev_detect_glibc.sh
  19. +1 −1 lgsm/functions/command_fastdl.sh
  20. +1 −1 lgsm/functions/command_install.sh
  21. +1 −1 lgsm/functions/command_mods_install.sh
  22. +1 −1 lgsm/functions/command_mods_update.sh
  23. +4 −4 lgsm/functions/command_monitor.sh
  24. +1 −1 lgsm/functions/command_postdetails.sh
  25. +3 −3 lgsm/functions/command_start.sh
  26. +5 −5 lgsm/functions/command_stop.sh
  27. +1 −1 lgsm/functions/command_update_linuxgsm.sh
  28. +9 −9 lgsm/functions/command_wipe.sh
  29. +1 −1 lgsm/functions/core_dl.sh
  30. +2 −2 lgsm/functions/core_exit.sh
  31. +2 −2 lgsm/functions/core_getopt.sh
  32. +25 −24 lgsm/functions/core_messages.sh
  33. +1 −1 lgsm/functions/fix.sh
  34. +12 −12 lgsm/functions/info_distro.sh
  35. +56 −56 lgsm/functions/info_messages.sh
  36. +1 −1 lgsm/functions/info_stats.sh
  37. +3 −3 lgsm/functions/install_logs.sh
  38. +1 −1 lgsm/functions/install_server_files.sh
  39. +4 −4 lgsm/functions/logs.sh
  40. +2 −2 lgsm/functions/mods_core.sh
  41. +2 −2 linuxgsm.sh
  42. +2 −2 tests/tests_fctrserver.sh
  43. +2 −2 tests/tests_jc2server.sh
  44. +2 −2 tests/tests_mcserver.sh
  45. +2 −2 tests/tests_ts3server.sh
@@ -28,14 +28,14 @@ tickrate="30" # default 30; range : 15 to 100
## Server Start Command | https://docs.linuxgsm.com/configuration/start-parameters#additional-parameters
fn_parms(){
# Specific to Rust
if [ -n "${seed}" ]; then
if [ "${seed}" ]; then
# If set, then add to start parms
conditionalseed="+server.seed ${seed}"
else
# Keep randomness of the number if not set
conditionalseed=""
fi
if [ -n "${salt}" ]; then
if [ "${salt}" ]; then
# If set, then add to start parms
conditionalsalt="+server.salt ${salt}"
else
@@ -57,7 +57,7 @@ fn_print_dots "Sending Discord alert"

discordsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${discordwebhook}")

if [ -n "${discordsend}" ]; then
if [ "${discordsend}" ]; then
fn_print_fail_nl "Sending Discord alert: ${discordsend}"
fn_script_log_fatal "Sending Discord alert: ${discordsend}"
else
@@ -11,7 +11,7 @@ local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
fn_print_dots "Sending Email alert: ${email}"
fn_sleep_time

if [ -n "${emailfrom}" ]; then
if [ "${emailfrom}" ]; then
mail -s "${alertsubject}" -r "${emailfrom}" "${email}" < "${alertlog}"
else
mail -s "${alertsubject}" "${email}" < "${alertlog}"
@@ -20,7 +20,7 @@ EOF
fn_print_dots "Sending IFTTT alert"
iftttsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://maker.ifttt.com/trigger/${iftttevent}/with/key/${ifttttoken}" | grep "Bad Request")

if [ -n "${iftttsend}" ]; then
if [ "${iftttsend}" ]; then
fn_print_fail_nl "Sending IFTTT alert: ${pushbulletsend}"
fn_script_log_fatal "Sending IFTTT alert: ${pushbulletsend}"
else
@@ -21,7 +21,7 @@ EOF
fn_print_dots "Sending Pushbullet alert"
pushbulletsend=$(curl -sSL -u """${pushbullettoken}"":" -H "Content-Type: application/json" -X POST -d """${json}""" "https://api.pushbullet.com/v2/pushes" | grep "error_code")

if [ -n "${pushbulletsend}" ]; then
if [ "${pushbulletsend}" ]; then
fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}"
fn_script_log_fatal "Sending Pushbullet alert: ${pushbulletsend}"
else
@@ -25,7 +25,7 @@ fi

pushoversend=$(curl -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alertemoji} ${alertsubject} ${alertemoji}" -F message=" <b>Message</b><br>${alertbody}<br><br><b>Game</b><br>${gamename}<br><br><b>Server name</b><br>${servername}<br><br><b>Hostname</b><br>${HOSTNAME}<br><br><b>Server IP</b><br><a href='https://www.gametracker.com/server_info/${alertip}:${port}'>${alertip}:${port}</a><br><br><b>More info</b><br><a href='${alerturl}'>${alerturl}</a>" "https://api.pushover.net/1/messages.json" | grep errors)

if [ -n "${pushoversend}" ]; then
if [ "${pushoversend}" ]; then
fn_print_fail_nl "Sending Pushover alert: ${pushoversend}"
fn_script_log_fatal "Sending Pushover alert: ${pushoversend}"
else
@@ -20,7 +20,7 @@ EOF
fn_print_dots "Sending Telegram alert"
telegramsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://api.telegram.org/bot${telegramtoken}/sendMessage" "${curlcustomstring}" | grep "error_code")

if [ -n "${telegramsend}" ]; then
if [ "${telegramsend}" ]; then
fn_print_fail_nl "Sending Telegram alert: ${telegramsend}"
fn_script_log_fatal "Sending Telegram alert: ${telegramsend}"
else
@@ -82,7 +82,7 @@ local allowed_commands_array=( update_steamcmd.sh command_debug.sh command_start
for allowed_command in "${allowed_commands_array[@]}"
do
if [ "${allowed_command}" == "${function_selfname}" ]; then
if [ -n "${appid}" ]; then
if [ "${appid}" ]; then
check_steamcmd.sh
fi
fi
@@ -7,7 +7,7 @@
local modulename="CHECK"
local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

if [ ! -e "${servercfgfullpath}" ]; then
if [ ! -f "${servercfgfullpath}" ]; then
if [ "${shortname}" != "hw" ]&&[ "${shortname}" != "ut3" ]&&[ "${shortname}" != "kf2" ]; then
fn_print_dots ""
fn_print_warn_nl "Configuration file missing!"
@@ -79,7 +79,7 @@ fn_install_mono_repo(){
echo -e " https://www.mono-project.com/download/stable/#download-lin"
monoautoinstall="1"
fi
if [ "${monoautoinstall}" != "1" ];then
if [ "${monoautoinstall}" != "1" ]; then
if [ $? != 0 ]; then
fn_print_failure_nl "Unable to install Mono repository."
fn_script_log_fatal "Unable to installMono repository."
@@ -183,7 +183,7 @@ if [ "${javacheck}" == "1" ]; then
fn_sleep_time
fi
# Define required dependencies for SteamCMD.
if [ -n "${appid}" ]; then
if [ "${appid}" ]; then
if [ "${deptocheck}" == "glibc.i686" ]||[ "${deptocheck}" == "libstdc++64.i686" ]||[ "${deptocheck}" == "lib32gcc1" ]||[ "${deptocheck}" == "lib32stdc++6" ]; then
steamcmdfail=1
fi
@@ -225,10 +225,10 @@ fn_found_missing_deps(){
fn_print_warning_nl "Missing dependencies: ${red}${array_deps_missing[@]}${default}"
fn_script_log_warn "Missing dependencies: ${array_deps_missing[@]}"
fn_sleep_time
if [ -n "${monostatus}" ]; then
if [ "${monostatus}" ]; then
fn_install_mono_repo
fi
if [ -n "${jqstatus}" ]; then
if [ "${jqstatus}" ]; then
fn_print_warning_nl "jq is not available in the ${distroname} repository."
echo -e " * https://docs.linuxgsm.com/requirements/jq"
fi
@@ -76,7 +76,7 @@ if [ "${travistest}" != "1" ]; then
fn_script_log_fatal "IP address not set in game config."
fn_script_log_fatal "Specify the IP you want to bind within: ${servercfgfullpath}."
fn_script_log_fatal "https://linuxgsm.com/network-interfaces\n"
if [ "${function_selfname}" != "command_details.sh" ];then
if [ "${function_selfname}" != "command_details.sh" ]; then
core_exit.sh
fi
else
@@ -21,6 +21,6 @@ fi

# Create gamelogdir.
# If variable exists gamelogdir exists and log/server does not.
if [ -n "${gamelogdir}" ]&&[ -d "${gamelogdir}" ]&&[ ! -d "${logdir}/server" ]; then
if [ "${gamelogdir}" ]&&[ -d "${gamelogdir}" ]&&[ ! -d "${logdir}/server" ]; then
fn_check_logs
fi
@@ -72,7 +72,7 @@ fn_check_permissions(){
fi

# Check rootdir permissions.
if [ -n "${rootdir}" ]; then
if [ "${rootdir}" ]; then
# Get permission numbers on directory under the form 775.
rootdirperm=$(stat -c %a "${rootdir}")
# Grab the first and second digit for user and group permission.
@@ -42,7 +42,7 @@ elif [ "${shortname}" == "st" ]; then
fi

# If the game or engine has a minimum RAM Requirement, compare it to system's available RAM.
if [ -n "${ramrequirementmb}" ]; then
if [ "${ramrequirementmb}" ]; then
if [ "${physmemtotalmb}" -lt "${ramrequirementmb}" ]; then
fn_print_dots "Check RAM"
# Warn the user.
@@ -8,7 +8,7 @@
local modulename="CHECK"

fn_check_is_in_tmux(){
if [ -n "${TMUX}" ]; then
if [ "${TMUX}" ]; then
fn_print_fail_nl "tmuxception error: Sorry Cobb you cannot start a tmux session inside of a tmux session."
fn_script_log_fatal "Tmuxception error: Attempted to start a tmux session inside of a tmux session."
fn_print_information_nl "LinuxGSM creates a tmux session when starting the server."
@@ -19,7 +19,7 @@ fn_check_is_in_tmux(){
}

fn_check_is_in_screen(){
if [ -n "${STY}" ]; then
if [ "${STY}" ]; then
fn_print_fail_nl "tmuxception error: Sorry Cobb you cannot start a tmux session inside of a screen session."
fn_script_log_fatal "Tmuxception error: Attempted to start a tmux session inside of a screen session."
fn_print_information_nl "LinuxGSM creates a tmux session when starting the server."
@@ -159,7 +159,7 @@ fn_backup_compression(){
# Clear old backups according to maxbackups and maxbackupdays variables.
fn_backup_prune(){
# Clear if backup variables are set.
if [ -n "${maxbackups}" ]&&[ -n "${maxbackupdays}" ]; then
if [ "${maxbackups}" ]&&[ -n "${maxbackupdays}" ]; then
# How many backups there are.
info_distro.sh
# How many backups exceed maxbackups.
@@ -37,7 +37,7 @@ fn_print_header
echo -e "${lightblue}Free Disk:\t\t${default}${availspace}"
} | column -s $'\t' -t
# glibc required.
if [ -n "${glibc}" ]; then
if [ "${glibc}" ]; then
if [ "${glibc}" == "null" ]; then
# Glibc is not required.
:
@@ -57,21 +57,21 @@ else
echo -e "${lightblue}Server IP:\t${default}${ip}:${port}"
fi
# External server IP.
if [ -n "${extip}" ]; then
if [ "${extip}" ]; then
if [ "${ip}" != "${extip}" ]; then
echo -e "${lightblue}Internet IP:\t${default}${extip}:${port}"
fi
fi
# Listed on Master Server.
if [ "${displaymasterserver}" ];then
if [ "${displaymasterserver}" == "true" ];then
if [ "${displaymasterserver}" ]; then
if [ "${displaymasterserver}" == "true" ]; then
echo -e "${lightblue}Master Server:\t${green}${displaymasterserver}${default}"
else
echo -e "${lightblue}Master Server:\t${red}${displaymasterserver}${default}"
fi
fi
# Server password.
if [ -n "${serverpassword}" ]; then
if [ "${serverpassword}" ]; then
echo -e "${lightblue}Server password:\t${default}${serverpassword}"
fi
echo -e "${lightblue}Start parameters:${default}"
@@ -13,7 +13,7 @@ echo -e "================================="
echo -e "glibc Requirements Checker"
echo -e "================================="

if [ -z "$(command -v objdump)" ]; then
if [ ! "$(command -v objdump)" ]; then
fn_print_failure_nl "objdump is missing"
fn_script_log_fatal "objdump is missing"
core_exit.sh
@@ -23,7 +23,7 @@ luafastdlfile="lgsm_cl_force_fastdl.lua"
luafastdlfullpath="${luasvautorundir}/${luafastdlfile}"

# Check if bzip2 is installed.
if [ -z "$(command -v bzip2 2>/dev/null)" ]; then
if [ ! "$(command -v bzip2 2>/dev/null)" ]; then
fn_print_fail "bzip2 is not installed"
fn_script_log_fatal "bzip2 is not installed"
core_exit.sh
@@ -25,7 +25,7 @@ else
elif [ -z "${appid}" ]; then
installer=1
install_server_files.sh
elif [ -n "${appid}" ]; then
elif [ "${appid}" ]; then
install_steamcmd.sh
install_server_files.sh
fi
@@ -82,7 +82,7 @@ fn_script_log_info "${modprettyname} selected for install"

# Check if the mod is already installed and warn the user.
if [ -f "${modsinstalledlistfullpath}" ]; then
if [ -n "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
if [ "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
fn_print_warning_nl "${modprettyname} is already installed"
fn_script_log_warn "${modprettyname} is already installed"
echo -e " * Any configs may be overwritten."
@@ -72,7 +72,7 @@ done
installedmodsline="1"
while [ "${installedmodsline}" -le "${installedmodscount}" ]; do
currentmod=$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")
if [ -n "${currentmod}" ]; then
if [ "${currentmod}" ]; then
fn_mod_get_info
# Don not update mod if the policy is set to "NOUPDATE".
if [ "${modkeepfiles}" == "NOUPDATE" ]; then
@@ -141,16 +141,16 @@ for queryattempt in {1..5}; do
fi
if [ "${querystatus}" == "0" ]; then
# Add query data to log.
if [ -n "${gdname}" ]; then
if [ "${gdname}" ]; then
fn_script_log_info "Server name: ${gdname}"
fi
if [ -n "${gdplayers}" ]; then
if [ "${gdplayers}" ]; then
fn_script_log_info "Players: ${gdplayers}/${gdmaxplayers}"
fi
if [ -n "${gdmap}" ]; then
if [ "${gdmap}" ]; then
fn_script_log_info "Map: ${gdmap}"
fi
if [ -n "${gdgamemode}" ]; then
if [ "${gdgamemode}" ]; then
fn_script_log_info "Game Mode: ${gdgamemode}"
fi
fi
@@ -48,7 +48,7 @@ if [ -f "${postdetailslog}" ]; then
fi

# Rather than a one-pass sed parser, default to using a temporary directory.
if [ -n "${exitbypass}" ]; then
if [ "${exitbypass}" ]; then
postdetailslog="${alertlog}"
else
# Run checks and gathers details to display.
@@ -10,7 +10,7 @@ local commandaction="Starting"
local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")

fn_start_teamspeak3(){
if [ ! -e "${servercfgfullpath}" ]; then
if [ ! -f "${servercfgfullpath}" ]; then
fn_print_warn_nl "${servercfgfullpath} is missing"
fn_script_log_warn "${servercfgfullpath} is missing"
echo " * Creating blank ${servercfg}"
@@ -78,7 +78,7 @@ fn_start_tmux(){
if [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
tmux pipe-pane -o -t "${selfname}" "exec cat >> '${consolelog}'"
fi
elif [ -n "${tmuxversion}" ]; then
elif [ "${tmuxversion}" ]; then
# Get the digit version of tmux.
tmuxversion=$(tmux -V | sed "s/tmux //" | sed -n '1 p' | tr -cd '[:digit:]')
# tmux pipe-pane not supported in tmux versions < 1.6.
@@ -176,7 +176,7 @@ if [ "${status}" != "0" ]; then
core_exit.sh
fi
fi
if [ -z "${fixbypass}" ];then
if [ -z "${fixbypass}" ]; then
fix.sh
fi
info_config.sh
@@ -134,22 +134,22 @@ fn_stop_graceful_sdtd(){
fn_stop_graceful_sdtd_telnet
completed=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Completed.")
refused=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Timeout or EOF")
if [ -n "${refused}" ]; then
if [ "${refused}" ]; then
fn_print_error "Graceful: telnet: ${telnetip}:${telnetport} : "
fn_print_fail_eol_nl
fn_script_log_error "Graceful: telnet: ${telnetip}:${telnetport} : FAIL"
elif [ -n "${completed}" ]; then
elif [ "${completed}" ]; then
break
fi
done

# If telnet shutdown was successful will use telnet again to check
# the connection has closed, confirming that the tmux session can now be killed.
if [ -n "${completed}" ]; then
if [ "${completed}" ]; then
for seconds in {1..30}; do
fn_stop_graceful_sdtd_telnet
refused=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Timeout or EOF")
if [ -n "${refused}" ]; then
if [ "${refused}" ]; then
fn_print_ok "Graceful: telnet: ${telnetip}:${telnetport} : "
fn_print_ok_eol_nl
fn_script_log_pass "Graceful: telnet: ${telnetip}:${telnetport} : ${seconds} seconds"
@@ -160,7 +160,7 @@ fn_stop_graceful_sdtd(){
done
# If telnet shutdown fails tmux shutdown will be used, this risks loss of world save.
else
if [ -n "${refused}" ]; then
if [ "${refused}" ]; then
fn_print_error "Graceful: telnet: "
fn_print_fail_eol_nl
fn_script_log_error "Graceful: telnet: ${telnetip}:${telnetport} : FAIL"
@@ -73,7 +73,7 @@ if [ -z "${legacymode}" ]; then
fi

# Check and update functions.
if [ -n "${functionsdir}" ]; then
if [ "${functionsdir}" ]; then
if [ -d "${functionsdir}" ]; then
cd "${functionsdir}" || exit
for functionfile in *

0 comments on commit abaa614

Please sign in to comment.
You can’t perform that action at this time.