From 287475b4916c08668ccf3ea1e5d56b8f4cda2e75 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 16 Apr 2017 20:07:15 +0100 Subject: [PATCH] A good tidy up --- .../config-lgsm/arkserver/_default.cfg | 5 +++-- .../config-lgsm/arma3server/_default.cfg | 4 ++-- .../config-lgsm/csgoserver/_default.cfg | 4 ++-- .../config-lgsm/sdtdserver/_default.cfg | 6 +++--- lgsm/functions/check_steamcmd.sh | 15 +-------------- lgsm/functions/command_install_resources_mta.sh | 5 ++--- lgsm/functions/command_start.sh | 2 +- lgsm/functions/command_validate.sh | 3 +-- lgsm/functions/core_dl.sh | 4 +++- lgsm/functions/fix_steamcmd.sh | 6 +++--- lgsm/functions/install_logs.sh | 10 +++++----- lgsm/functions/install_mta_resources.sh | 9 ++++----- lgsm/functions/install_server_files.sh | 4 ++-- lgsm/functions/logs.sh | 2 +- lgsm/functions/monitor_gsquery.sh | 5 ----- lgsm/functions/update_mta.sh | 5 ++--- lgsm/functions/update_steamcmd.sh | 6 ++++-- linuxgsm.sh | 1 + 18 files changed, 40 insertions(+), 56 deletions(-) diff --git a/lgsm/config-default/config-lgsm/arkserver/_default.cfg b/lgsm/config-default/config-lgsm/arkserver/_default.cfg index 8378e9cec..35a8d1949 100644 --- a/lgsm/config-default/config-lgsm/arkserver/_default.cfg +++ b/lgsm/config-default/config-lgsm/arkserver/_default.cfg @@ -77,9 +77,10 @@ servercfgfullpath="${servercfgdir}/${servercfg}" backupdir="${rootdir}/backups" ## Logging Directories +logdir="${logdir}" gamelogdir="${systemdir}/Saved/Logs" -scriptlogdir="${rootdir}/log/script" -consolelogdir="${rootdir}/log/console" +scriptlogdir="${logdir}/script" +consolelogdir="${logdir}/console" scriptlog="${scriptlogdir}/${servicename}-script.log" consolelog="${consolelogdir}/${servicename}-console.log" emaillog="${scriptlogdir}/${servicename}-email.log" diff --git a/lgsm/config-default/config-lgsm/arma3server/_default.cfg b/lgsm/config-default/config-lgsm/arma3server/_default.cfg index 4dc8a264c..ac83b822d 100644 --- a/lgsm/config-default/config-lgsm/arma3server/_default.cfg +++ b/lgsm/config-default/config-lgsm/arma3server/_default.cfg @@ -89,8 +89,8 @@ backupdir="${rootdir}/backups" ## Logging Directories #gamelogdir="" # No server logs available -scriptlogdir="${rootdir}/log/script" -consolelogdir="${rootdir}/log/console" +scriptlogdir="${logdir}/script" +consolelogdir="${logdir}/console" scriptlog="${scriptlogdir}/${servicename}-script.log" consolelog="${consolelogdir}/${servicename}-console.log" emaillog="${scriptlogdir}/${servicename}-email.log" diff --git a/lgsm/config-default/config-lgsm/csgoserver/_default.cfg b/lgsm/config-default/config-lgsm/csgoserver/_default.cfg index fdbb7a272..718d8d132 100644 --- a/lgsm/config-default/config-lgsm/csgoserver/_default.cfg +++ b/lgsm/config-default/config-lgsm/csgoserver/_default.cfg @@ -102,8 +102,8 @@ backupdir="${rootdir}/backups" ## Logging Directories gamelogdir="${systemdir}/logs" -scriptlogdir="${rootdir}/log/script" -consolelogdir="${rootdir}/log/console" +scriptlogdir="${logdir}/script" +consolelogdir="${logdir}/console" scriptlog="${scriptlogdir}/${servicename}-script.log" consolelog="${consolelogdir}/${servicename}-console.log" emaillog="${scriptlogdir}/${servicename}-email.log" diff --git a/lgsm/config-default/config-lgsm/sdtdserver/_default.cfg b/lgsm/config-default/config-lgsm/sdtdserver/_default.cfg index d537643cc..b8576295e 100644 --- a/lgsm/config-default/config-lgsm/sdtdserver/_default.cfg +++ b/lgsm/config-default/config-lgsm/sdtdserver/_default.cfg @@ -77,9 +77,9 @@ servercfgfullpath="${servercfgdir}/${servercfg}" backupdir="${rootdir}/backups" ## Logging Directories -gamelogdir="${rootdir}/log/server" -scriptlogdir="${rootdir}/log/script" -consolelogdir="${rootdir}/log/console" +gamelogdir="${logdir}/server" +scriptlogdir="${logdir}/script" +consolelogdir="${logdir}/console" gamelog="${gamelogdir}/${servicename}-game.log" scriptlog="${scriptlogdir}/${servicename}-script.log" consolelog="${consolelogdir}/${servicename}-console.log" diff --git a/lgsm/functions/check_steamcmd.sh b/lgsm/functions/check_steamcmd.sh index ddfcb82d4..2b8cb0f0b 100644 --- a/lgsm/functions/check_steamcmd.sh +++ b/lgsm/functions/check_steamcmd.sh @@ -39,7 +39,6 @@ fn_check_steamcmd_user(){ fn_check_steamcmd_sh(){ # Checks if SteamCMD exists when starting or updating a server. # Installs if missing. - steamcmddir="${rootdir}/steamcmd" if [ ! -f "${steamcmddir}/steamcmd.sh" ]; then if [ "${function_selfname}" == "command_install.sh" ]; then fn_install_steamcmd @@ -55,17 +54,5 @@ fn_check_steamcmd_sh(){ fi } -fn_check_steamcmd_guard(){ - if [ "${function_selfname}" == "command_update.sh" ]||[ "${function_selfname}" == "command_validate.sh" ]; then - # Checks that SteamCMD is working correctly and will prompt Steam Guard if required. - "${steamcmddir}"/steamcmd.sh +login "${steamuser}" "${steampass}" +quit - if [ $? -ne 0 ]; then - fn_print_failure_nl "Error running SteamCMD" - fi - fi -} - fn_check_steamcmd_user -fn_check_steamcmd_sh -# stdbuf has now replaced unbuffer. This should not longer be required. -#fn_check_steamcmd_guard +fn_check_steamcmd_sh \ No newline at end of file diff --git a/lgsm/functions/command_install_resources_mta.sh b/lgsm/functions/command_install_resources_mta.sh index 07c2e0ac0..07b6e4440 100644 --- a/lgsm/functions/command_install_resources_mta.sh +++ b/lgsm/functions/command_install_resources_mta.sh @@ -12,9 +12,8 @@ fn_install_resources(){ echo "" echo "Installing Default Resources" echo "=================================" - fileurl="http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip"; filedir="${tmpdir}"; filename="multitheftauto_resources.zip"; executecmd="noexecute" run="norun"; force="noforce"; md5="nomd5" - fn_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}" - fn_dl_extract "${filedir}" "${filename}" "${resourcesdir}" + fn_fetch_file "http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip" "${tmpdir}" "mtasa-resources-latest.zip" "noexecute" "norun" "noforce" "nomd5" + fn_dl_extract "${tmpdir}" "mtasa-resources-latest.zip" "${resourcesdir}" echo "Default Resources Installed." } diff --git a/lgsm/functions/command_start.sh b/lgsm/functions/command_start.sh index 1f411af48..87f9a05ed 100644 --- a/lgsm/functions/command_start.sh +++ b/lgsm/functions/command_start.sh @@ -46,7 +46,7 @@ fn_start_teamspeak3(){ if [ "${status}" == "0" ]; then fn_print_fail_nl "Unable to start ${servername}" fn_script_log_fatal "Unable to start ${servername}" - echo -e " Check log files: ${rootdir}/log" + echo -e " Check log files: ${logdir}" core_exit.sh else fn_print_ok_nl "${servername}" diff --git a/lgsm/functions/command_validate.sh b/lgsm/functions/command_validate.sh index f2fa5638b..72488d956 100644 --- a/lgsm/functions/command_validate.sh +++ b/lgsm/functions/command_validate.sh @@ -18,8 +18,7 @@ fn_validation(){ fn_script_log_info "Validating files: SteamCMD" sleep 1 - cd "${rootdir}/steamcmd" - + cd "${steamcmddir}" # Detects if unbuffer command is available for 32 bit distributions only. info_distro.sh if [ $(command -v stdbuf) ]&&[ "${arch}" != "x86_64" ]; then diff --git a/lgsm/functions/core_dl.sh b/lgsm/functions/core_dl.sh index 7d24f9436..665162859 100644 --- a/lgsm/functions/core_dl.sh +++ b/lgsm/functions/core_dl.sh @@ -55,7 +55,9 @@ fn_dl_extract(){ # extracts archives echo -ne "extracting ${local_filename}..." mime=$(file -b --mime-type "${local_filedir}/${local_filename}") - + if [ ! -d "${extractdir}" ]; then + mkdir "${extractdir}" + fi if [ "${mime}" == "application/gzip" ]||[ "${mime}" == "application/x-gzip" ]; then extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdir}") elif [ "${mime}" == "application/x-bzip2" ]; then diff --git a/lgsm/functions/fix_steamcmd.sh b/lgsm/functions/fix_steamcmd.sh index 52762e10a..693398739 100644 --- a/lgsm/functions/fix_steamcmd.sh +++ b/lgsm/functions/fix_steamcmd.sh @@ -13,7 +13,7 @@ if [ ! -f "${HOME}/.steam/sdk32/steamclient.so" ]; then fixname="steamclient.so general" fn_fix_msg_start mkdir -pv "${HOME}/.steam/sdk32" >> "${scriptlog}" - cp -v "${rootdir}/steamcmd/linux32/steamclient.so" "${HOME}/.steam/sdk32/steamclient.so" >> "${scriptlog}" + cp -v "${steamcmddir}/linux32/steamclient.so" "${HOME}/.steam/sdk32/steamclient.so" >> "${scriptlog}" fn_fix_msg_end fi @@ -31,13 +31,13 @@ elif [ "${gamename}" == "Hurtworld" ]; then if [ ! -f "${serverfiles}/Hurtworld_Data/Plugins/x86/steamclient.so" ]; then fixname="steamclient.so x86" fn_fix_msg_start - cp -v "${rootdir}/steamcmd/linux32/steamclient.so" "${serverfiles}/Hurtworld_Data/Plugins/x86/steamclient.so" >> "${scriptlog}" + cp -v "${steamcmddir}/linux32/steamclient.so" "${serverfiles}/Hurtworld_Data/Plugins/x86/steamclient.so" >> "${scriptlog}" fn_fix_msg_end fi if [ ! -f "${serverfiles}/Hurtworld_Data/Plugins/x86_64/steamclient.so" ]; then fixname="steamclient.so x86_64" fn_fix_msg_start - cp -v "${rootdir}/steamcmd/linux32/steamclient.so" "${serverfiles}/Hurtworld_Data/Plugins/x86_64/steamclient.so" >> "${scriptlog}" + cp -v "${steamcmddir}/linux32/steamclient.so" "${serverfiles}/Hurtworld_Data/Plugins/x86_64/steamclient.so" >> "${scriptlog}" fn_fix_msg_end fi elif [ "${gamename}" == "Tower Unite" ]; then diff --git a/lgsm/functions/install_logs.sh b/lgsm/functions/install_logs.sh index 3feb0feea..65a09ed18 100644 --- a/lgsm/functions/install_logs.sh +++ b/lgsm/functions/install_logs.sh @@ -15,7 +15,7 @@ if [ "${checklogs}" != "1" ]; then fi sleep 1 # Create script and console log directories -mkdir -v "${rootdir}/log" +mkdir -v "${logdir}" mkdir -v "${scriptlogdir}" touch "${scriptlog}" if [ -n "${consolelogdir}" ]; then @@ -30,15 +30,15 @@ fi # Symlink gamelogdir to lgsm logs if variable exists if [ -n "${gamelogdir}" ]; then - if [ ! -h "${rootdir}/log/server" ]; then - ln -nfsv "${gamelogdir}" "${rootdir}/log/server" + if [ ! -h "${logdir}/server" ]; then + ln -nfsv "${gamelogdir}" "${logdir}/server" fi fi # If server uses SteamCMD create a symbolic link to the Steam logs if [ -d "${rootdir}/Steam/logs" ]; then - if [ ! -h "${rootdir}/log/steamcmd" ]; then - ln -nfsv "${rootdir}/Steam/logs" "${rootdir}/log/steamcmd" + if [ ! -h "${logdir}/steamcmd" ]; then + ln -nfsv "${rootdir}/Steam/logs" "${logdir}/steamcmd" fi fi sleep 1 diff --git a/lgsm/functions/install_mta_resources.sh b/lgsm/functions/install_mta_resources.sh index 8156da9da..6abfc598a 100644 --- a/lgsm/functions/install_mta_resources.sh +++ b/lgsm/functions/install_mta_resources.sh @@ -14,20 +14,19 @@ fn_install_libmysqlclient16(){ echo "Checking if libmysqlclient16 is installed" echo "=================================" sleep 1 - if [ ! -f /usr/lib/libmysqlclient.so.16 ]; then + if [ ! -f "/usr/lib/libmysqlclient.so.16" ]; then fn_print_warn_nl "libmysqlclient16 not installed. Installing.." sleep 1 sudo -v > /dev/null 2>&1 if [ $? -eq 0 ]; then - fileurl="https://nightly.mtasa.com/files/modules/64/libmysqlclient.so.16"; filedir="${tmpdir}"; filename="libmysqlclient.so.16"; executecmd="executecmd" run="norun"; force="noforce"; md5="6c188e0f8fb5d7a29f4bc413b9fed6c2" - fn_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}" - sudo mv ${tmpdir}/${filename} /usr/lib/${filename} + fn_fetch_file "https://nightly.mtasa.com/files/modules/64/libmysqlclient.so.16" "${filedir}" "libmysqlclient.so.16" "executecmd" "norun" "noforce" "6c188e0f8fb5d7a29f4bc413b9fed6c2" + sudo mv "${tmpdir}/libmysqlclient.so.16" "/usr/lib/libmysqlclient.so.16" else fn_print_fail_nl "Failed to install libmysqlclient16, $(whoami) does not have sudo access. Download it manually and place it in /usr/lib" sleep 1 fi else - echo "libmysqlclient16 already installed." + echo "libmysqlclient16 already installed." fi } diff --git a/lgsm/functions/install_server_files.sh b/lgsm/functions/install_server_files.sh index ed8ad70ff..39c2934bc 100644 --- a/lgsm/functions/install_server_files.sh +++ b/lgsm/functions/install_server_files.sh @@ -48,7 +48,7 @@ fn_install_server_files_steamcmd(){ counter="0" while [ "${counter}" == "0" ]||[ "${exitcode}" != "0" ]; do counter=$((counter+1)) - cd "${rootdir}/steamcmd" + cd "${steamcmddir}" if [ "${counter}" -le "10" ]; then # Attempt 1-4: Standard attempt # Attempt 5-6: Validate attempt @@ -66,7 +66,7 @@ fn_install_server_files_steamcmd(){ find ${serverfiles} -type d -print0 | grep -Ez '[^/]{30}$' | xargs -0 rm -rf fi if [ "${counter}" -ge "9" ]; then - rm -rf "${rootdir}/steamcmd" + rm -rf "${steamcmddir}" check_steamcmd.sh fi diff --git a/lgsm/functions/logs.sh b/lgsm/functions/logs.sh index 44467d82f..2fd0fc626 100644 --- a/lgsm/functions/logs.sh +++ b/lgsm/functions/logs.sh @@ -37,7 +37,7 @@ if [ $(find "${scriptlogdir}"/ -type f -mtime +"${logdays}"|wc -l) -ne "0" ]; th sourcemodlogdir="${systemdir}/addons/sourcemod/logs" ulxlogdir="${systemdir}/data/ulx_logs" darkrplogdir="${systemdir}/data/darkrp_logs" - legacyserverlogdir="${rootdir}/log/server" + legacyserverlogdir="${logdir}/server" # Setting up counting variables scriptcount="0" ; consolecount="0" ; gamecount="0" ; srcdscount="0" ; smcount="0" ; ulxcount="0" ; darkrpcount="0" ; legacycount="0" sleep 1 diff --git a/lgsm/functions/monitor_gsquery.sh b/lgsm/functions/monitor_gsquery.sh index dc24aaee3..c874dc452 100644 --- a/lgsm/functions/monitor_gsquery.sh +++ b/lgsm/functions/monitor_gsquery.sh @@ -9,11 +9,6 @@ local commandname="MONITOR" local commandaction="Monitor" local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" -# Forces legacy servers to use gsquery -if [ -z "${gsquery}" ]; then - gsquery="yes" -fi - if [ "${gsquery}" == "yes" ]; then # Downloads gsquery.py if missing diff --git a/lgsm/functions/update_mta.sh b/lgsm/functions/update_mta.sh index 9383b73e3..72aaf65ec 100644 --- a/lgsm/functions/update_mta.sh +++ b/lgsm/functions/update_mta.sh @@ -10,11 +10,10 @@ local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" fn_update_mta_dl(){ fn_fetch_file "http://linux.mtasa.com/dl/${numversion}/multitheftauto_linux_x64-${fullversion}.tar.gz" "${tmpdir}" "multitheftauto_linux_x64-${fullversion}.tar.gz" - mkdir "${tmpdir}/multitheftauto_linux_x64-${fullversion}" - fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64-${fullversion}.tar.gz" "${tmpdir}/multitheftauto_linux_x64-${fullversion}" + fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64-${fullversion}.tar.gz" "${tmpdir}" echo -e "copying to ${serverfiles}...\c" fn_script_log "Copying to ${serverfiles}" - cp -R "${tmpdir}/multitheftauto_linux_x64-${fullversion}/multitheftauto_linux_x64-${fullversion}/"* "${serverfiles}" + cp -R "${tmpdir}/multitheftauto_linux_x64-${fullversion}/"* "${serverfiles}" local exitcode=$? if [ "${exitcode}" == "0" ]; then fn_print_ok_eol_nl diff --git a/lgsm/functions/update_steamcmd.sh b/lgsm/functions/update_steamcmd.sh index 26096291f..09f25b2d9 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 "${rootdir}/steamcmd" + cd "${steamcmddir}" # Detects if unbuffer command is available for 32 bit distributions only. info_distro.sh @@ -25,6 +25,7 @@ fn_update_steamcmd_dl(){ unbuffer="stdbuf -i0 -o0 -e0" fi + cd "${steamcmddir}" if [ "${engine}" == "goldsource" ]; then ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod ${appidmod} +app_update "${appid}" ${branch} +quit | tee -a "${scriptlog}" else @@ -146,7 +147,7 @@ fn_update_steamcmd_check(){ currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3) # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD - cd "${rootdir}/steamcmd" + if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then rm -f "${HOME}/Steam/appcache/appinfo.vdf" fi @@ -160,6 +161,7 @@ fn_update_steamcmd_check(){ fi # Gets availablebuild info + cd "${steamcmddir}" 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" diff --git a/linuxgsm.sh b/linuxgsm.sh index 9c26ac3c7..d2e71ca43 100644 --- a/linuxgsm.sh +++ b/linuxgsm.sh @@ -22,6 +22,7 @@ shortname="core" servername="core" gamename="core" lockselfname=".${servicename}.lock" +steamcmddir="${rootdir}/steamcmd" lgsmdir="${rootdir}/lgsm" functionsdir="${lgsmdir}/functions" libdir="${lgsmdir}/lib"