From bbcf07603d05c72b8d05a51738cbbcc497a53f08 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 17:37:22 +0000 Subject: [PATCH 01/35] removed which command as per shellcheck command is a POSIX and will exclusivly use this moving forward. https://github.com/koalaman/shellcheck/wiki/SC2230 --- lgsm/functions/check_deps.sh | 4 ++-- lgsm/functions/command_stop.sh | 2 +- lgsm/functions/core_dl.sh | 8 +------- lgsm/functions/update_ts3.sh | 2 +- linuxgsm.sh | 13 ++++--------- tests/tests_jc2server.sh | 13 ++++--------- tests/tests_ts3server.sh | 13 ++++--------- 7 files changed, 17 insertions(+), 38 deletions(-) diff --git a/lgsm/functions/check_deps.sh b/lgsm/functions/check_deps.sh index 31a2fb077..705d36a9c 100644 --- a/lgsm/functions/check_deps.sh +++ b/lgsm/functions/check_deps.sh @@ -149,7 +149,7 @@ if [ -n "$(command -v dpkg-query 2>/dev/null)" ]; then # All servers except ts3 require tmux if [ "${gamename}" != "TeamSpeak 3" ]; then - if [ "$(command -v tmux 2>/dev/null)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then + if [ "$(command -v tmux 2>/dev/null)" ]; then tmuxcheck=1 # Added for users compiling tmux from source to bypass check. else array_deps_required+=( tmux ) @@ -246,7 +246,7 @@ elif [ -n "$(command -v yum 2>/dev/null)" ]; then # All servers except ts3 require tmux if [ "${gamename}" != "TeamSpeak 3" ]; then - if [ "$(command -v tmux 2>/dev/null)" ]||[ "$(which tmux 2>/dev/null)" ]||[ -f "/usr/bin/tmux" ]||[ -f "/bin/tmux" ]; then + if [ "$(command -v tmux 2>/dev/null)" ]; then tmuxcheck=1 # Added for users compiling tmux from source to bypass check. else array_deps_required+=( tmux ) diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index 13040a00f..97fdf6566 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -118,7 +118,7 @@ fn_stop_graceful_sdtd(){ sleep 1 if [ "${telnetenabled}" == "false" ]; then fn_print_info_nl "Graceful: telnet: DISABLED: Enable in ${servercfg}" - elif [ "$(command -v expect 2>/dev/null)" ]||[ "$(which expect >/dev/null 2>&1)" ]; then + elif [ "$(command -v expect 2>/dev/null)" ]; then # Tries to shutdown with both localhost and server IP. for telnetip in 127.0.0.1 ${ip}; do fn_print_dots "Graceful: telnet: ${telnetip}" diff --git a/lgsm/functions/core_dl.sh b/lgsm/functions/core_dl.sh index d279ab85b..f45b8938d 100644 --- a/lgsm/functions/core_dl.sh +++ b/lgsm/functions/core_dl.sh @@ -238,13 +238,7 @@ fn_update_function(){ } # Defines curl path -curl_paths_array=($(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl) -for curlpath in "${curl_paths_array}" -do - if [ -x "${curlpath}" ]; then - break - fi -done +curlpath=$(command -v curl 2>/dev/null) if [ "$(basename ${curlpath})" != "curl" ]; then echo "[ FAIL ] Curl is not installed" diff --git a/lgsm/functions/update_ts3.sh b/lgsm/functions/update_ts3.sh index 2e33c9203..e2f2691ef 100644 --- a/lgsm/functions/update_ts3.sh +++ b/lgsm/functions/update_ts3.sh @@ -206,7 +206,7 @@ fn_update_ts3_compare(){ fn_update_ts3_arch if [ "${installer}" == "1" ]; then # if jq available uses json update checker - if [ "$(command -v jq)" ]||[ "$(which jq >/dev/null 2>&1)" ]; then + if [ "$(command -v jq >/dev/null 2>&1)" ]; then fn_update_ts3_availablebuild else fn_update_ts3_availablebuild_legacy diff --git a/linuxgsm.sh b/linuxgsm.sh index 1b87bb284..95cb95562 100755 --- a/linuxgsm.sh +++ b/linuxgsm.sh @@ -70,13 +70,8 @@ fn_bootstrap_fetch_file(){ mkdir -p "${local_filedir}" fi # Defines curl path - curl_paths_array=($(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl) - for curlpath in "${curl_paths_array}" - do - if [ -x "${curlpath}" ]; then - break - fi - done + curlpath=$(command -v curl 2>/dev/null) + # If curl exists download file if [ "$(basename ${curlpath})" == "curl" ]; then # trap to remove part downloaded files @@ -198,8 +193,8 @@ fn_install_menu() { options=$4 # Get menu command for menucmd in whiptail dialog bash; do - if [ -x $(which ${menucmd}) ]; then - menucmd=$(which ${menucmd}) + if [ -x $(command -v ${menucmd}) ]; then + menucmd=$(command -v ${menucmd}) break fi done diff --git a/tests/tests_jc2server.sh b/tests/tests_jc2server.sh index c0d6d0b19..1b2b744e8 100644 --- a/tests/tests_jc2server.sh +++ b/tests/tests_jc2server.sh @@ -65,13 +65,8 @@ fn_bootstrap_fetch_file(){ mkdir -p "${local_filedir}" fi # Defines curl path - curl_paths_array=($(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl) - for curlpath in "${curl_paths_array}" - do - if [ -x "${curlpath}" ]; then - break - fi - done + curlpath=$(command -v curl 2>/dev/null) + # If curl exists download file if [ "$(basename ${curlpath})" == "curl" ]; then # trap to remove part downloaded files @@ -193,8 +188,8 @@ fn_install_menu() { options=$4 # Get menu command for menucmd in whiptail dialog bash; do - if [ -x $(which ${menucmd}) ]; then - menucmd=$(which ${menucmd}) + if [ -x $(command -v ${menucmd}) ]; then + menucmd=$(command -v ${menucmd}) break fi done diff --git a/tests/tests_ts3server.sh b/tests/tests_ts3server.sh index 7f327dc13..bd36cf34c 100644 --- a/tests/tests_ts3server.sh +++ b/tests/tests_ts3server.sh @@ -65,13 +65,8 @@ fn_bootstrap_fetch_file(){ mkdir -p "${local_filedir}" fi # Defines curl path - curl_paths_array=($(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl) - for curlpath in "${curl_paths_array}" - do - if [ -x "${curlpath}" ]; then - break - fi - done + curlpath=$(command -v curl 2>/dev/null) + # If curl exists download file if [ "$(basename ${curlpath})" == "curl" ]; then # trap to remove part downloaded files @@ -193,8 +188,8 @@ fn_install_menu() { options=$4 # Get menu command for menucmd in whiptail dialog bash; do - if [ -x $(which ${menucmd}) ]; then - menucmd=$(which ${menucmd}) + if [ -x $(command -v ${menucmd}) ]; then + menucmd=$(command -v ${menucmd}) break fi done From bd3e088fb213cad0e7144f86be361632f77c789f Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:05:18 +0000 Subject: [PATCH 02/35] SC2012 --- lgsm/functions/info_distro.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/info_distro.sh b/lgsm/functions/info_distro.sh index 661123a80..497b6bfd1 100644 --- a/lgsm/functions/info_distro.sh +++ b/lgsm/functions/info_distro.sh @@ -124,7 +124,7 @@ if [ -d "${backupdir}" ]; then # number of backups. backupcount=$(find "${backupdir}"/*.tar.gz | wc -l) # most recent backup. - lastbackup=$(ls -t "${backupdir}"/*.tar.gz | head -1) + lastbackup=$(find "${backupdir}"/*.tar.gz | head -1) # date of most recent backup. lastbackupdate=$(date -r "${lastbackup}") # no of days since last backup. From cb38c8d4ed0d2c09aa41b08bbb623e0717f1546d Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:07:31 +0000 Subject: [PATCH 03/35] SC2086 --- lgsm/functions/command_dev_detect_glibc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lgsm/functions/command_dev_detect_glibc.sh b/lgsm/functions/command_dev_detect_glibc.sh index 4fb472a94..eb1249a95 100644 --- a/lgsm/functions/command_dev_detect_glibc.sh +++ b/lgsm/functions/command_dev_detect_glibc.sh @@ -28,8 +28,8 @@ elif [ -f "${serverfiles}" ]; then fi echo "" -files=$(find ${serverfiles} | wc -l) -find ${serverfiles} -type f -print0 | +files=$(find "${serverfiles}" | wc -l) +find "${serverfiles}" -type f -print0 | while IFS= read -r -d $'\0' line; do glibcversion=$(objdump -T "${line}" 2>/dev/null|grep -oP "GLIBC[^ ]+" |grep -v GLIBCXX|sort|uniq|sort -r --version-sort| head -n 1) if [ "${glibcversion}" ]; then From d93519d57256cf537c7121060671169dded5696d Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:11:02 +0000 Subject: [PATCH 04/35] SC2115 --- lgsm/functions/command_mods_update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_mods_update.sh b/lgsm/functions/command_mods_update.sh index 50c4b611f..a5f513997 100644 --- a/lgsm/functions/command_mods_update.sh +++ b/lgsm/functions/command_mods_update.sh @@ -27,7 +27,7 @@ fn_remove_cfg_files(){ echo -e " * serverfiles/${filetopreserve}" # If it matches an existing file that have been extracted delete the file if [ -f "${extractdir}/${filetopreserve}" ]||[ -d "${extractdir}/${filetopreserve}" ]; then - rm -r "${extractdir}/${filetopreserve}" + rm -r "${extractdir:?}/${filetopreserve}" # Write the file path in a tmp file, to rebuild a full file list as it is rebuilt upon update if [ ! -f "${modsdir}/.removedfiles.tmp" ]; then touch "${modsdir}/.removedfiles.tmp" From 56630ab66d42e0182e6090339f9f55740d796ed8 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:11:37 +0000 Subject: [PATCH 05/35] SC2086 --- lgsm/functions/command_mods_update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_mods_update.sh b/lgsm/functions/command_mods_update.sh index a5f513997..7b71194f5 100644 --- a/lgsm/functions/command_mods_update.sh +++ b/lgsm/functions/command_mods_update.sh @@ -72,7 +72,7 @@ sleep 1 # List all installed mods and apply update # Reset line value installedmodsline="1" -while [ ${installedmodsline} -le ${installedmodscount} ]; do +while [ "${installedmodsline}" -le "${installedmodscount}" ]; do currentmod="$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")" if [ -n "${currentmod}" ]; then fn_mod_get_info From d7eada1a318653d5d7cdc4962f80bada867126b4 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:12:44 +0000 Subject: [PATCH 06/35] SC2006 --- lgsm/functions/mods_core.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/mods_core.sh b/lgsm/functions/mods_core.sh index fbf2c0b29..9ba3736e7 100644 --- a/lgsm/functions/mods_core.sh +++ b/lgsm/functions/mods_core.sh @@ -43,7 +43,7 @@ fn_mod_lowercase(){ fileswc=$(find "${extractdir}" -depth | wc -l) echo -en "\r" while read -r src; do - dst=`dirname "${src}"`/`basename "${src}" | tr '[A-Z]' '[a-z]'` + dst=$(dirname "${src}"`/`basename "${src}" | tr '[A-Z]' '[a-z]') if [ "${src}" != "${dst}" ] then [ ! -e "${dst}" ] && mv -T "${src}" "${dst}" || echo "${src} was not renamed" From 12c0ac6adb46a617c7248e43506fa14079023ceb Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:14:26 +0000 Subject: [PATCH 07/35] SC2086 --- lgsm/functions/mods_core.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/mods_core.sh b/lgsm/functions/mods_core.sh index 9ba3736e7..b8d84b745 100644 --- a/lgsm/functions/mods_core.sh +++ b/lgsm/functions/mods_core.sh @@ -219,7 +219,7 @@ fn_mods_installed_list(){ moddescriptionmaxlength="0" modcommandmaxlength="0" # Loop through every line of the installed mods list ${modsinstalledlistfullpath} - while [ ${installedmodsline} -le ${installedmodscount} ]; do + while [ "${installedmodsline}" -le "${installedmodscount}" ]; do currentmod="$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")" # Get mod info to make sure mod exists fn_mod_get_info From a9c588fe325010746af0bf24f8b4923bc6e67cda Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:19:39 +0000 Subject: [PATCH 08/35] SC2066 --- lgsm/functions/core_dl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/core_dl.sh b/lgsm/functions/core_dl.sh index f45b8938d..1230cac4a 100644 --- a/lgsm/functions/core_dl.sh +++ b/lgsm/functions/core_dl.sh @@ -240,7 +240,7 @@ fn_update_function(){ # Defines curl path curlpath=$(command -v curl 2>/dev/null) -if [ "$(basename ${curlpath})" != "curl" ]; then +if [ "$(basename "${curlpath}")" != "curl" ]; then echo "[ FAIL ] Curl is not installed" exit 1 fi \ No newline at end of file From 0193817b7982c906ca1a0c88a80a5164bfd08b6e Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:21:22 +0000 Subject: [PATCH 09/35] SC2164 --- lgsm/functions/compress_unreal2_maps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/compress_unreal2_maps.sh b/lgsm/functions/compress_unreal2_maps.sh index 2b0f35951..94907d596 100644 --- a/lgsm/functions/compress_unreal2_maps.sh +++ b/lgsm/functions/compress_unreal2_maps.sh @@ -22,7 +22,7 @@ if ! fn_prompt_yn "Start compression?" Y; then fi mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1 rm -rfv "${serverfiles}/Maps/"*.ut2.uz2 -cd "${systemdir}" +cd "${systemdir}" || exit for map in "${serverfiles}/Maps/"*; do ./ucc-bin compress "${map}" --nohomedir done From 3300ddc3e9ec5fae5c7508fa36320b97d93c7066 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:26:12 +0000 Subject: [PATCH 10/35] SC2196 --- lgsm/functions/update_minecraft.sh | 4 ++-- lgsm/functions/update_mumble.sh | 4 ++-- lgsm/functions/update_ts3.sh | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lgsm/functions/update_minecraft.sh b/lgsm/functions/update_minecraft.sh index 5fb3fa648..9050109d4 100644 --- a/lgsm/functions/update_minecraft.sh +++ b/lgsm/functions/update_minecraft.sh @@ -47,7 +47,7 @@ fn_update_currentbuild(){ fi # Get current build from logs - currentbuild=$(cat "${serverfiles}/logs/latest.log" 2> /dev/null | grep version | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') + currentbuild=$(cat "${serverfiles}/logs/latest.log" 2> /dev/null | grep version | grep -Eo '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') if [ -z "${currentbuild}" ]; then fn_print_error_nl "Checking for update: mojang.com: Current build version not found" fn_script_log_error "Checking for update: mojang.com: Current build version not found" @@ -58,7 +58,7 @@ fn_update_currentbuild(){ command_stop.sh exitbypass=1 command_start.sh - currentbuild=$(cat "${serverfiles}/logs/latest.log" 2> /dev/null | grep version | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') + currentbuild=$(cat "${serverfiles}/logs/latest.log" 2> /dev/null | grep version | grep -Eo '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') if [ -z "${currentbuild}" ]; then fn_print_fail_nl "Checking for update: mojang.com: Current build version still not found" fn_script_log_fatal "Checking for update: mojang.com: Current build version still not found" diff --git a/lgsm/functions/update_mumble.sh b/lgsm/functions/update_mumble.sh index 765710f08..549bb4d36 100644 --- a/lgsm/functions/update_mumble.sh +++ b/lgsm/functions/update_mumble.sh @@ -49,7 +49,7 @@ fn_update_mumble_currentbuild(){ fi # Get current build from logs - currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | egrep 'Murmur ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | awk '{print $4}') + currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | grep -E 'Murmur ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | awk '{print $4}') if [ -z "${currentbuild}" ]; then fn_print_error_nl "Checking for update: GitHub: Current build version not found" fn_script_log_error "Checking for update: GitHub: Current build version not found" @@ -60,7 +60,7 @@ fn_update_mumble_currentbuild(){ command_stop.sh exitbypass=1 command_start.sh - currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | egrep 'Murmur ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | awk '{print $4}') + currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | grep -E 'Murmur ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | awk '{print $4}') if [ -z "${currentbuild}" ]; then fn_print_fail_nl "Checking for update: GitHub: Current build version still not found" fn_script_log_fatal "Checking for update: GitHub: Current build version still not found" diff --git a/lgsm/functions/update_ts3.sh b/lgsm/functions/update_ts3.sh index e2f2691ef..96e941118 100644 --- a/lgsm/functions/update_ts3.sh +++ b/lgsm/functions/update_ts3.sh @@ -48,7 +48,7 @@ fn_update_ts3_currentbuild(){ fi # Get current build from logs - currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | sort -V | tail -1) + currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | grep -Ev '${rootdir}/.ts3version' | tail -1) | grep -Eo 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | grep -Eo '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | sort -V | tail -1) if [ -z "${currentbuild}" ]; then fn_print_error_nl "Checking for update: teamspeak.com: Current build version not found" fn_script_log_error "Checking for update: teamspeak.com: Current build version not found" @@ -59,7 +59,7 @@ fn_update_ts3_currentbuild(){ command_stop.sh exitbypass=1 command_start.sh - currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') + currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | grep -Ev '${rootdir}/.ts3version' | tail -1) | grep -Eo 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | grep -Eo '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') if [ -z "${currentbuild}" ]; then fn_print_fail_nl "Checking for update: teamspeak.com: Current build version still not found" fn_script_log_fatal "Checking for update: teamspeak.com: Current build version still not found" @@ -112,7 +112,7 @@ fn_update_ts3_availablebuild_legacy(){ # Gets latest build info. # Grabs all version numbers but not in correct order. - wget "http://dl.4players.de/ts/releases/?C=M;O=D" -q -O -| grep -i dir | egrep -o '.*\/<\/a>' | egrep -o '[0-9\.?]+'|uniq > "${tmpdir}/.ts3_version_numbers_unsorted.tmp" + wget "http://dl.4players.de/ts/releases/?C=M;O=D" -q -O -| grep -i dir | grep -Eo '.*\/<\/a>' | grep -Eo '[0-9\.?]+'|uniq > "${tmpdir}/.ts3_version_numbers_unsorted.tmp" # Sort version numbers cat "${tmpdir}/.ts3_version_numbers_unsorted.tmp" | sort -r --version-sort -o "${tmpdir}/.ts3_version_numbers_sorted.tmp" From a3bd278272e462a2f2def63360fcc0931db36db3 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:27:56 +0000 Subject: [PATCH 11/35] SC2162 --- lgsm/functions/update_ts3.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/update_ts3.sh b/lgsm/functions/update_ts3.sh index 96e941118..930344d17 100644 --- a/lgsm/functions/update_ts3.sh +++ b/lgsm/functions/update_ts3.sh @@ -118,7 +118,7 @@ fn_update_ts3_availablebuild_legacy(){ cat "${tmpdir}/.ts3_version_numbers_unsorted.tmp" | sort -r --version-sort -o "${tmpdir}/.ts3_version_numbers_sorted.tmp" # Finds directory with most recent server version. - while read ts3_version_number; do + while read -r ts3_version_number; do wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2" if [ $? -eq 0 ]; then availablebuild="${ts3_version_number}" From c4bef413672cfe0b58e35bc3a93c33bdf83570ee Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:29:43 +0000 Subject: [PATCH 12/35] SC2162 --- lgsm/functions/command_ts3_server_pass.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_ts3_server_pass.sh b/lgsm/functions/command_ts3_server_pass.sh index 0525a283c..e57f33efa 100644 --- a/lgsm/functions/command_ts3_server_pass.sh +++ b/lgsm/functions/command_ts3_server_pass.sh @@ -19,7 +19,7 @@ fn_serveradmin_password_prompt(){ echo Exiting; exit fi fn_script_log_info "Initiating ${gamename} ServerAdmin password change" - read -p "Enter new password : " newpassword + read -rp "Enter new password : " newpassword } fn_serveradmin_password_set(){ From 4b577c4e587a6030d30adeec35c386cf1a106417 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:30:10 +0000 Subject: [PATCH 13/35] SC2046 --- lgsm/functions/check_root.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/check_root.sh b/lgsm/functions/check_root.sh index 6efdf34f4..0b986ef88 100644 --- a/lgsm/functions/check_root.sh +++ b/lgsm/functions/check_root.sh @@ -7,7 +7,7 @@ local commandname="CHECK" local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -if [ $(whoami) = "root" ]; then +if [ "$(whoami)" = "root" ]; then fn_print_fail_nl "Do NOT run this script as root!" if [ -d "${lgsmlogdir}" ]; then fn_script_log_fatal "${selfname} attempted to run as root." From a4140cbca654740f84c05fc8bd6cb97781c46d91 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:31:07 +0000 Subject: [PATCH 14/35] SC2046 --- lgsm/functions/command_stop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index 97fdf6566..a5b13925b 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -226,7 +226,7 @@ fn_stop_ark(){ pid=${pid//[!0-9]/} let pid+=0 # turns an empty string into a valid number, '0', # and a valid numeric pid remains unchanged. - if [ "${pid}" -gt 1 ]&&[ "${pid}" -le $(cat /proc/sys/kernel/pid_max) ]; then + if [ "${pid}" -gt 1 ]&&[ "${pid}" -le $(cat "/proc/sys/kernel/pid_max") ]; then fn_print_dots "Process still bound. Awaiting graceful exit: ${pidcheck}" sleep 1 else From bd59b54ac4b42b23e58bdb2c9990b183fb57a1d1 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:32:57 +0000 Subject: [PATCH 15/35] SC2046 --- lgsm/functions/install_config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh index b7939d290..261339992 100644 --- a/lgsm/functions/install_config.sh +++ b/lgsm/functions/install_config.sh @@ -62,7 +62,7 @@ fn_set_config_vars(){ fn_script_log_info "changing hostname." sleep 1 - if [ $(grep SERVERNAME=SERVERNAME \"${lgsmdir}/config-default/config-game/${config}\" 2>/dev/null) ]; then + if [ "$(grep SERVERNAME=SERVERNAME \"${lgsmdir}/config-default/config-game/${config}\" 2>/dev/null)" ]; then sed -i "s/SERVERNAME=SERVERNAME/SERVERNAME=${servername}/g" "${servercfgfullpath}" else sed -i "s/SERVERNAME/${servername}/g" "${servercfgfullpath}" From 1077ab2abf12010035f25a8af3072ec1ac5cc1b0 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:33:24 +0000 Subject: [PATCH 16/35] SC2164 --- lgsm/functions/update_steamcmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/update_steamcmd.sh b/lgsm/functions/update_steamcmd.sh index e1925cc4c..bda7a72a7 100644 --- a/lgsm/functions/update_steamcmd.sh +++ b/lgsm/functions/update_steamcmd.sh @@ -17,7 +17,7 @@ fn_update_steamcmd_dl(){ fn_print_ok_nl "SteamCMD" fn_script_log_info "Starting SteamCMD" - cd "${steamcmddir}" + cd "${steamcmddir}" || exit # Detects if unbuffer command is available for 32 bit distributions only. info_distro.sh From 2a0d4562f1af2edb9a107be3a1dd12b6fae8528a Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:33:55 +0000 Subject: [PATCH 17/35] SC2162 --- lgsm/functions/update_steamcmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/update_steamcmd.sh b/lgsm/functions/update_steamcmd.sh index bda7a72a7..e2cf4d7c3 100644 --- a/lgsm/functions/update_steamcmd.sh +++ b/lgsm/functions/update_steamcmd.sh @@ -157,7 +157,7 @@ fn_update_steamcmd_check(){ fi # Set branch for updateinfo - IFS=' ' read -a branchsplits <<< "${branch}" + IFS=' ' read -ra branchsplits <<< "${branch}" if [ "${#branchsplits[@]}" -gt 1 ]; then branchname="${branchsplits[1]}" else From 0b6d5dfb2800c0424c38fd71d07e92ff32168a2f Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:34:28 +0000 Subject: [PATCH 18/35] SC2162 --- lgsm/functions/install_gslt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/install_gslt.sh b/lgsm/functions/install_gslt.sh index 918753d74..2d1dfd1ed 100644 --- a/lgsm/functions/install_gslt.sh +++ b/lgsm/functions/install_gslt.sh @@ -29,7 +29,7 @@ if [ -z "${autoinstall}" ]; then if [ "${gamename}" != "Tower Unite" ]; then echo "Enter token below (Can be blank)." echo -n "GSLT TOKEN: " - read token + read -r token if ! grep -q "^gslt=" "${configdirserver}/${servicename}.cfg" > /dev/null 2>&1; then echo -e "\ngslt=\"${token}\"" >> "${configdirserver}/${servicename}.cfg" else From 66151c574eedeb982b45763e8d4fcf5f03495ce3 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:35:06 +0000 Subject: [PATCH 19/35] SC2086 --- lgsm/functions/core_exit.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lgsm/functions/core_exit.sh b/lgsm/functions/core_exit.sh index 02b471c78..e7b65f8c2 100644 --- a/lgsm/functions/core_exit.sh +++ b/lgsm/functions/core_exit.sh @@ -26,12 +26,12 @@ elif [ -n "${exitcode}" ]&&[ "${exitcode}" != "0" ]; then fn_exit_dev_debug # remove trap. trap - INT - exit ${exitcode} + exit "${exitcode}" else exitcode=0 fn_script_log_pass "${function_selfname} exiting with code: ${exitcode}" fn_exit_dev_debug # remove trap. trap - INT - exit ${exitcode} + exit "${exitcode}" fi From ec855898b901e2265b6cb90fb314554a1388ac3b Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:35:43 +0000 Subject: [PATCH 20/35] SC2162 --- lgsm/functions/install_dst_token.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/install_dst_token.sh b/lgsm/functions/install_dst_token.sh index a350577e8..38bb872da 100644 --- a/lgsm/functions/install_dst_token.sh +++ b/lgsm/functions/install_dst_token.sh @@ -30,7 +30,7 @@ if [ -z "${autoinstall}" ]; then if [ "${overwritetoken}" == "true" ]; then echo "Once you have the cluster token, enter it below" echo -n "Cluster Token: " - read token + read -r token mkdir -pv "${clustercfgdir}" echo "${token}" > "${clustercfgdir}/cluster_token.txt" if [ -f "${clustercfgdir}/cluster_token.txt" ]; then From fe16698ec4ecef7c144d9c703f45b47a792f0115 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:36:25 +0000 Subject: [PATCH 21/35] SC2046 --- lgsm/functions/command_validate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_validate.sh b/lgsm/functions/command_validate.sh index 09d31a436..e15a67c0a 100644 --- a/lgsm/functions/command_validate.sh +++ b/lgsm/functions/command_validate.sh @@ -22,7 +22,7 @@ fn_validation(){ cd "${steamcmddir}" # Detects if unbuffer command is available for 32 bit distributions only. info_distro.sh - if [ $(command -v stdbuf) ]&&[ "${arch}" != "x86_64" ]; then + if [ "$(command -v stdbuf)" ]&&[ "${arch}" != "x86_64" ]; then unbuffer="stdbuf -i0 -o0 -e0" fi From 20c33da6ba9a8b4266ed03ad5d9ae7458c4806ed Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:37:32 +0000 Subject: [PATCH 22/35] SC2115 --- lgsm/functions/command_mods_remove.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_mods_remove.sh b/lgsm/functions/command_mods_remove.sh index df24a2675..8ed26abfb 100644 --- a/lgsm/functions/command_mods_remove.sh +++ b/lgsm/functions/command_mods_remove.sh @@ -68,7 +68,7 @@ while [ "${modfileline}" -le "${modsfilelistsize}" ]; do # If file or directory exists, then remove it if [ -f "${modinstalldir}/${currentfileremove}" ]||[ -d "${modinstalldir}/${currentfileremove}" ]; then - rm -rf "${modinstalldir}/${currentfileremove}" + rm -rf "${modinstalldir:?}/${currentfileremove}" ((exitcode=$?)) if [ ${exitcode} -ne 0 ]; then fn_script_log_fatal "Removing ${modinstalldir}/${currentfileremove}" From 8ce79afc75f182bdd540ad3d68be4dddeb7a50ba Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:38:37 +0000 Subject: [PATCH 23/35] SC2059 --- lgsm/functions/command_mods_remove.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_mods_remove.sh b/lgsm/functions/command_mods_remove.sh index 8ed26abfb..71e57a1cb 100644 --- a/lgsm/functions/command_mods_remove.sh +++ b/lgsm/functions/command_mods_remove.sh @@ -78,7 +78,7 @@ while [ "${modfileline}" -le "${modsfilelistsize}" ]; do fi fi tput rc; tput el - printf "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..." + echo "removing ${modprettyname} ${modfileline} / ${modsfilelistsize} : ${currentfileremove}..." ((modfileline++)) done if [ ${exitcode} -ne 0 ]; then From 2876befb315d2fb0a96a9770d4d7a42678546b98 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:39:49 +0000 Subject: [PATCH 24/35] SC2086 SC2162 --- lgsm/functions/command_dev_detect_deps.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lgsm/functions/command_dev_detect_deps.sh b/lgsm/functions/command_dev_detect_deps.sh index 8e7e18a6c..140b7013c 100644 --- a/lgsm/functions/command_dev_detect_deps.sh +++ b/lgsm/functions/command_dev_detect_deps.sh @@ -20,7 +20,7 @@ elif [ "$(command -v readelf 2>/dev/null)" ]; then else echo "readelf/eu-readelf not installed" fi -files=$(find ${serverfiles} | wc -l) +files=$(find "${serverfiles}" | wc -l) find "${serverfiles}" -type f -print0 | while IFS= read -r -d $'\0' line; do if [ "${readelf}" == "eu-readelf" ]; then @@ -34,7 +34,7 @@ done sort "${tmpdir}/.depdetect_readelf" |uniq >"${tmpdir}/.depdetect_readelf_uniq" -while read lib; do +while read -r lib; do if [ "${lib}" == "libm.so.6" ]||[ "${lib}" == "libc.so.6" ]||[ "${lib}" == "libtcmalloc_minimal.so.4" ]||[ "${lib}" == "libpthread.so.0" ]||[ "${lib}" == "libdl.so.2" ]||[ "${lib}" == "libnsl.so.1" ]||[ "${lib}" == "libgcc_s.so.1" ]||[ "${lib}" == "librt.so.1" ]||[ "${lib}" == "ld-linux.so.2" ]; then echo "glibc.i686" >> "${tmpdir}/.depdetect_centos_list" echo "lib32gcc1" >> "${tmpdir}/.depdetect_ubuntu_list" From 9131f9e65447bd06c59f67fb08e92b52b4481851 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:41:03 +0000 Subject: [PATCH 25/35] SC2086 --- lgsm/functions/command_dev_detect_ldd.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lgsm/functions/command_dev_detect_ldd.sh b/lgsm/functions/command_dev_detect_ldd.sh index d80ad0895..c250559eb 100644 --- a/lgsm/functions/command_dev_detect_ldd.sh +++ b/lgsm/functions/command_dev_detect_ldd.sh @@ -26,11 +26,11 @@ files=$(find "${serverfiles}" | wc -l) find "${serverfiles}" -type f -print0 | while IFS= read -r -d $'\0' line; do #ldd -v $line 2>/dev/null|grep "=>" >>"${tmpdir}/detect_ldd.tmp" - if [ -n "$(ldd ${line} 2>/dev/null |grep -v "not a dynamic executable")" ]; then + if [ -n "$(ldd "${line}" 2>/dev/null |grep -v "not a dynamic executable")" ]; then echo "${line}" >> "${tmpdir}/detect_ldd.tmp" ldd "${line}" 2>/dev/null |grep -v "not a dynamic executable" >> "${tmpdir}/detect_ldd.tmp" - if [ -n "$(ldd $line 2>/dev/null |grep -v "not a dynamic executable"|grep "not found")" ]; then + if [ -n "$(ldd "${line}" 2>/dev/null |grep -v "not a dynamic executable"|grep "not found")" ]; then echo "${line}" >> "${tmpdir}/detect_ldd_not_found.tmp" ldd "${line}" 2>/dev/null |grep -v "not a dynamic executable"|grep "not found" >> "${tmpdir}/detect_ldd_not_found.tmp" fi From 37f568ea471a9f00d0316afe9c7aeb03775bbdd0 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 14 Mar 2018 22:42:58 +0000 Subject: [PATCH 26/35] SC2027 --- lgsm/functions/logs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lgsm/functions/logs.sh b/lgsm/functions/logs.sh index 927185ecf..20fc32fe1 100644 --- a/lgsm/functions/logs.sh +++ b/lgsm/functions/logs.sh @@ -42,8 +42,8 @@ if [ $(find "${lgsmlogdir}"/ -type f -mtime +"${logdays}"|wc -l) -ne "0" ]; then scriptcount="0" ; consolecount="0" ; gamecount="0" ; srcdscount="0" ; smcount="0" ; ulxcount="0" ; darkrpcount="0" ; legacycount="0" sleep 1 fn_print_ok_nl "Starting" - fn_print_info_nl "Removing logs older than "${logdays}" days" - fn_script_log_info "Removing logs older than "${logdays}" days" + fn_print_info_nl "Removing logs older than ${logdays} days" + fn_script_log_info "Removing logs older than ${logdays} days" # Logging logfiles to be removed according to "${logdays}", counting and removing them # Script logfiles find "${lgsmlogdir}"/ -type f -mtime +"${logdays}"| tee >> "${lgsmlog}" From b79819b96896c49f5a7969ba9b2068e1f1dd0ecf Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:41:21 +0000 Subject: [PATCH 27/35] SC2129 --- lgsm/functions/install_ts3db.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lgsm/functions/install_ts3db.sh b/lgsm/functions/install_ts3db.sh index 1509c8f62..fc200fa79 100644 --- a/lgsm/functions/install_ts3db.sh +++ b/lgsm/functions/install_ts3db.sh @@ -26,19 +26,21 @@ fn_install_ts3db_mariadb(){ echo "Configuring ${gamename} Server for MariaDB/MySQL" echo "=================================" sleep 1 - read -p "Enter MariaDB hostname: " mariahostname - read -p "Enter MariaDB port: " mariaport - read -p "Enter MariaDB username: " mariausername - read -p "Enter MariaDB password: " mariapassword - read -p "Enter MariaDB database name: " mariadbname + read -rp "Enter MariaDB hostname: " mariahostname + read -rp "Enter MariaDB port: " mariaport + read -rp "Enter MariaDB username: " mariausername + read -rp "Enter MariaDB password: " mariapassword + read -rp "Enter MariaDB database name: " mariadbname + { echo "updating config." - echo "[config]" >> ${servercfgdir}/ts3db_mariadb.ini - echo "host='${mariahostname}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "port='${mariaport}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "username='${mariausername}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "password='${mariapassword}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "database='${mariadbname}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "socket=" >> ${servercfgdir}/ts3db_mariadb.ini + echo "[config]" + echo "host='${mariahostname}'" + echo "port='${mariaport}'" + echo "username='${mariausername}'" + echo "password='${mariapassword}'" + echo "database='${mariadbname}'" + echo "socket=" + } >> "${servercfgdir}/ts3db_mariadb.ini" sed -i "s/dbplugin=ts3db_sqlite3/dbplugin=ts3db_mariadb/g" "${servercfgfullpath}" sed -i "s/dbpluginparameter=/dbpluginparameter=ts3db_mariadb.ini/g" "${servercfgfullpath}" sed -i "s/dbsqlcreatepath=create_sqlite\//dbsqlcreatepath=create_mariadb\//g" "${servercfgfullpath}" From abf3cd12ca957d4ecf6cb0e924a407682abdff16 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:42:13 +0000 Subject: [PATCH 28/35] SC2164 --- lgsm/functions/install_ts3db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/install_ts3db.sh b/lgsm/functions/install_ts3db.sh index fc200fa79..b5ec4b3a9 100644 --- a/lgsm/functions/install_ts3db.sh +++ b/lgsm/functions/install_ts3db.sh @@ -71,7 +71,7 @@ echo "=================================" sleep 1 echo "IMPORANT! Save these details for later." sleep 1 -cd "${executabledir}" +cd "${executabledir}" || exit ./ts3server_startscript.sh start inifile=ts3-server.ini sleep 5 ./ts3server_startscript.sh stop From e384b6c77a9c0ed8558432f36e6ad84de3126d4c Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:43:26 +0000 Subject: [PATCH 29/35] SC2086 --- lgsm/functions/install_ts3db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/install_ts3db.sh b/lgsm/functions/install_ts3db.sh index b5ec4b3a9..7cfc3205f 100644 --- a/lgsm/functions/install_ts3db.sh +++ b/lgsm/functions/install_ts3db.sh @@ -14,7 +14,7 @@ fn_install_ts3db_mariadb(){ echo "checking if libmariadb2 is installed" echo "=================================" sleep 1 - ldd ${serverfiles}/libts3db_mariadb.so | grep "libmariadb.so.2 => not found" + ldd "${serverfiles}/libts3db_mariadb.so" | grep "libmariadb.so.2 => not found" if [ $? -eq 0 ]; then echo "libmariadb2 not installed. Please install it first." echo "exiting..." From f09769bd21de143591669ba1ef23ad4b39e2874b Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:46:59 +0000 Subject: [PATCH 30/35] SC2062 --- lgsm/functions/command_stop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index 46c1d55ed..44bf94359 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -219,7 +219,7 @@ fn_stop_ark(){ if [ "${#queryport}" -gt 0 ] ; then for (( pidcheck=0 ; pidcheck < ${maxpiditer} ; pidcheck++ )) ; do pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ - grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ + grep ":${queryport}[[:space:]]" | rev | awk '{print $1}' |\ rev | cut -d\/ -f1) # # check for a valid pid From b6acd560637ed2f36f4d54f8dc16ea2dcf187517 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:47:42 +0000 Subject: [PATCH 31/35] SC2046 --- lgsm/functions/command_stop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index 44bf94359..4740f2f92 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -226,7 +226,7 @@ fn_stop_ark(){ pid=${pid//[!0-9]/} let pid+=0 # turns an empty string into a valid number, '0', # and a valid numeric pid remains unchanged. - if [ "${pid}" -gt 1 ]&&[ "${pid}" -le $(cat "/proc/sys/kernel/pid_max") ]; then + if [ "${pid}" -gt 1 ]&&[ "${pid}" -le "$(cat "/proc/sys/kernel/pid_max")" ]; then fn_print_dots "Process still bound. Awaiting graceful exit: ${pidcheck}" sleep 1 else From 6438fff13a71973d67addcc53d55d2cc716af0e9 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:49:53 +0000 Subject: [PATCH 32/35] SC2143 --- lgsm/functions/install_config.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh index 00fdd5431..190afbcd3 100644 --- a/lgsm/functions/install_config.sh +++ b/lgsm/functions/install_config.sh @@ -61,8 +61,7 @@ fn_set_config_vars(){ echo "changing hostname." fn_script_log_info "changing hostname." sleep 1 - - if [ "$(grep SERVERNAME=SERVERNAME \"${lgsmdir}/config-default/config-game/${config}\" 2>/dev/null)" ]; then + if grep -q "SERVERNAME=SERVERNAME" "${lgsmdir}/config-default/config-game/${config}" 2>/dev/null; then sed -i "s/SERVERNAME=SERVERNAME/SERVERNAME=${servername}/g" "${servercfgfullpath}" else sed -i "s/SERVERNAME/${servername}/g" "${servercfgfullpath}" From dd902e6431cc82280b4765523fac4b55488e2838 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:51:56 +0000 Subject: [PATCH 33/35] SC2086 --- lgsm/functions/check_glibc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/check_glibc.sh b/lgsm/functions/check_glibc.sh index 2690eb7c5..3a99b009b 100644 --- a/lgsm/functions/check_glibc.sh +++ b/lgsm/functions/check_glibc.sh @@ -17,7 +17,7 @@ elif [ "${glibcrequired}" == "UNKNOWN" ]; then fn_print_error_nl "Glibc fix: ${red}${glibcrequired}${default}" echo -e " * glibc required: ${red}${glibcrequired}${default}" echo -e " * glibc installed: ${glibcversion}" -elif [ "$(printf '%s\n'${glibcrequired}'\n' ${glibcversion} | sort -V | head -n 1)" != "${glibcrequired}" ]; then +elif [ "$(printf "%s\n'${glibcrequired}'\n" "${glibcversion}" | sort -V | head -n 1)" != "${glibcrequired}" ]; then if [ "${glibcfix}" == "yes" ]; then if [ "${function_selfname}" != "command_install.sh" ]; then fn_print_dots "Glibc fix" From a576e0248a6d3e33bc4917b6a8097b84572748b7 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 00:52:10 +0000 Subject: [PATCH 34/35] SC2164 --- lgsm/functions/update_steamcmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/update_steamcmd.sh b/lgsm/functions/update_steamcmd.sh index fc9aa8cd4..1b0663df0 100644 --- a/lgsm/functions/update_steamcmd.sh +++ b/lgsm/functions/update_steamcmd.sh @@ -165,7 +165,7 @@ fn_update_steamcmd_check(){ fi # Gets availablebuild info - cd "${steamcmddir}" + cd "${steamcmddir}" || exit availablebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +app_info_print "${appid}" +quit | sed -n '/branch/,$p' | grep -m 1 buildid | tr -cd '[:digit:]') if [ -z "${availablebuild}" ]; then fn_print_fail "Checking for update: SteamCMD" From 64701aceae15c28f5d96d18e3fe8140fd0f89981 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 17 Mar 2018 20:12:13 +0000 Subject: [PATCH 35/35] Shellcheck code tidy SC2164 SC2086 SC2062 SC2046 SC2143 SC2086 SC2164 --- lgsm/functions/check_glibc.sh | 2 +- lgsm/functions/command_stop.sh | 4 ++-- lgsm/functions/install_config.sh | 3 +-- lgsm/functions/install_ts3db.sh | 30 ++++++++++++++++-------------- lgsm/functions/update_steamcmd.sh | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lgsm/functions/check_glibc.sh b/lgsm/functions/check_glibc.sh index 2690eb7c5..3a99b009b 100644 --- a/lgsm/functions/check_glibc.sh +++ b/lgsm/functions/check_glibc.sh @@ -17,7 +17,7 @@ elif [ "${glibcrequired}" == "UNKNOWN" ]; then fn_print_error_nl "Glibc fix: ${red}${glibcrequired}${default}" echo -e " * glibc required: ${red}${glibcrequired}${default}" echo -e " * glibc installed: ${glibcversion}" -elif [ "$(printf '%s\n'${glibcrequired}'\n' ${glibcversion} | sort -V | head -n 1)" != "${glibcrequired}" ]; then +elif [ "$(printf "%s\n'${glibcrequired}'\n" "${glibcversion}" | sort -V | head -n 1)" != "${glibcrequired}" ]; then if [ "${glibcfix}" == "yes" ]; then if [ "${function_selfname}" != "command_install.sh" ]; then fn_print_dots "Glibc fix" diff --git a/lgsm/functions/command_stop.sh b/lgsm/functions/command_stop.sh index 46c1d55ed..4740f2f92 100644 --- a/lgsm/functions/command_stop.sh +++ b/lgsm/functions/command_stop.sh @@ -219,14 +219,14 @@ fn_stop_ark(){ if [ "${#queryport}" -gt 0 ] ; then for (( pidcheck=0 ; pidcheck < ${maxpiditer} ; pidcheck++ )) ; do pid=$(netstat -nap 2>/dev/null | grep ^udp[[:space:]] |\ - grep :${queryport}[[:space:]] | rev | awk '{print $1}' |\ + grep ":${queryport}[[:space:]]" | rev | awk '{print $1}' |\ rev | cut -d\/ -f1) # # check for a valid pid pid=${pid//[!0-9]/} let pid+=0 # turns an empty string into a valid number, '0', # and a valid numeric pid remains unchanged. - if [ "${pid}" -gt 1 ]&&[ "${pid}" -le $(cat "/proc/sys/kernel/pid_max") ]; then + if [ "${pid}" -gt 1 ]&&[ "${pid}" -le "$(cat "/proc/sys/kernel/pid_max")" ]; then fn_print_dots "Process still bound. Awaiting graceful exit: ${pidcheck}" sleep 1 else diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh index 00fdd5431..190afbcd3 100644 --- a/lgsm/functions/install_config.sh +++ b/lgsm/functions/install_config.sh @@ -61,8 +61,7 @@ fn_set_config_vars(){ echo "changing hostname." fn_script_log_info "changing hostname." sleep 1 - - if [ "$(grep SERVERNAME=SERVERNAME \"${lgsmdir}/config-default/config-game/${config}\" 2>/dev/null)" ]; then + if grep -q "SERVERNAME=SERVERNAME" "${lgsmdir}/config-default/config-game/${config}" 2>/dev/null; then sed -i "s/SERVERNAME=SERVERNAME/SERVERNAME=${servername}/g" "${servercfgfullpath}" else sed -i "s/SERVERNAME/${servername}/g" "${servercfgfullpath}" diff --git a/lgsm/functions/install_ts3db.sh b/lgsm/functions/install_ts3db.sh index 1509c8f62..7cfc3205f 100644 --- a/lgsm/functions/install_ts3db.sh +++ b/lgsm/functions/install_ts3db.sh @@ -14,7 +14,7 @@ fn_install_ts3db_mariadb(){ echo "checking if libmariadb2 is installed" echo "=================================" sleep 1 - ldd ${serverfiles}/libts3db_mariadb.so | grep "libmariadb.so.2 => not found" + ldd "${serverfiles}/libts3db_mariadb.so" | grep "libmariadb.so.2 => not found" if [ $? -eq 0 ]; then echo "libmariadb2 not installed. Please install it first." echo "exiting..." @@ -26,19 +26,21 @@ fn_install_ts3db_mariadb(){ echo "Configuring ${gamename} Server for MariaDB/MySQL" echo "=================================" sleep 1 - read -p "Enter MariaDB hostname: " mariahostname - read -p "Enter MariaDB port: " mariaport - read -p "Enter MariaDB username: " mariausername - read -p "Enter MariaDB password: " mariapassword - read -p "Enter MariaDB database name: " mariadbname + read -rp "Enter MariaDB hostname: " mariahostname + read -rp "Enter MariaDB port: " mariaport + read -rp "Enter MariaDB username: " mariausername + read -rp "Enter MariaDB password: " mariapassword + read -rp "Enter MariaDB database name: " mariadbname + { echo "updating config." - echo "[config]" >> ${servercfgdir}/ts3db_mariadb.ini - echo "host='${mariahostname}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "port='${mariaport}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "username='${mariausername}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "password='${mariapassword}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "database='${mariadbname}'" >> ${servercfgdir}/ts3db_mariadb.ini - echo "socket=" >> ${servercfgdir}/ts3db_mariadb.ini + echo "[config]" + echo "host='${mariahostname}'" + echo "port='${mariaport}'" + echo "username='${mariausername}'" + echo "password='${mariapassword}'" + echo "database='${mariadbname}'" + echo "socket=" + } >> "${servercfgdir}/ts3db_mariadb.ini" sed -i "s/dbplugin=ts3db_sqlite3/dbplugin=ts3db_mariadb/g" "${servercfgfullpath}" sed -i "s/dbpluginparameter=/dbpluginparameter=ts3db_mariadb.ini/g" "${servercfgfullpath}" sed -i "s/dbsqlcreatepath=create_sqlite\//dbsqlcreatepath=create_mariadb\//g" "${servercfgfullpath}" @@ -69,7 +71,7 @@ echo "=================================" sleep 1 echo "IMPORANT! Save these details for later." sleep 1 -cd "${executabledir}" +cd "${executabledir}" || exit ./ts3server_startscript.sh start inifile=ts3-server.ini sleep 5 ./ts3server_startscript.sh stop diff --git a/lgsm/functions/update_steamcmd.sh b/lgsm/functions/update_steamcmd.sh index fc9aa8cd4..1b0663df0 100644 --- a/lgsm/functions/update_steamcmd.sh +++ b/lgsm/functions/update_steamcmd.sh @@ -165,7 +165,7 @@ fn_update_steamcmd_check(){ fi # Gets availablebuild info - cd "${steamcmddir}" + cd "${steamcmddir}" || exit availablebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +app_info_print "${appid}" +quit | sed -n '/branch/,$p' | grep -m 1 buildid | tr -cd '[:digit:]') if [ -z "${availablebuild}" ]; then fn_print_fail "Checking for update: SteamCMD"