From 1150b497a0ee5e607ddf9de6a8f7f02d9a2b0558 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 30 Sep 2023 22:05:08 +0100 Subject: [PATCH] refactor: improve variable naming and remove unnecessary code duplication The commit refactors the code in `install_config.sh` to improve variable naming and remove unnecessary code duplication. Specifically, it renames the variables for better clarity and removes redundant lines of code. refactor: improve installation and configuration process - Refactored the fix_dst.sh script to keep the shard name in server.ini consistent with the LinuxGSM config. - Updated install_config.sh to provide clearer messages during the default config download and copy processes. refactor: update shard name in server.ini The code has been refactored to update the shard name in the server.ini file. This change ensures that the shard name in the LinuxGSM config matches the one in server.ini. --- lgsm/modules/fix_dst.sh | 12 ++++++++++++ lgsm/modules/info_game.sh | 1 - lgsm/modules/install_config.sh | 10 +++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lgsm/modules/fix_dst.sh b/lgsm/modules/fix_dst.sh index ff963d3426..a364357737 100644 --- a/lgsm/modules/fix_dst.sh +++ b/lgsm/modules/fix_dst.sh @@ -15,3 +15,15 @@ if [ -f "/etc/redhat-release" ] && [ ! -f "${serverfiles}/bin/lib32/libcurl-gnut ln -s "/usr/lib/libcurl.so.4" "${serverfiles}/bin/lib32/libcurl-gnutls.so.4" fn_fix_msg_end fi + +# Keeps shard name in server.ini the same as in the LinuxGSM config. +if [ -f "${servercfgfullpath}" ]; then + if [ "$(grep -Ec '^name[[:space:]]*=' "${servercfgfullpath}")" -eq 1 ]; then + if [ "$(grep -E '^name[[:space:]]*=' "${servercfgfullpath}" | cut -d '=' -f2 | tr -d '"' | tr -d ' ')" != "${shard}" ]; then + fixname="update server.ini shard name" + fn_fix_msg_start + sed -i -e "s/name[[:space:]]*=.*/name = \"${shard}\"/g" "${servercfgfullpath}" + fn_fix_msg_end + fi + fi +fi diff --git a/lgsm/modules/info_game.sh b/lgsm/modules/info_game.sh index 2853b8bc58..5536b9840a 100644 --- a/lgsm/modules/info_game.sh +++ b/lgsm/modules/info_game.sh @@ -435,7 +435,6 @@ fn_info_game_dodr() { fn_info_game_dst() { if [ -f "${servercfgfullpath}" ]; then fn_info_game_ini "port" "server_port" "${servercfgfullpath}" - fn_info_game_ini "shard" "name" "${servercfgfullpath}" fn_info_game_ini "steamauthport" "authentication_port" "${servercfgfullpath}" fn_info_game_ini "steamport" "master_server_port" "${servercfgfullpath}" fi diff --git a/lgsm/modules/install_config.sh b/lgsm/modules/install_config.sh index 003dc0b095..1624abea4e 100644 --- a/lgsm/modules/install_config.sh +++ b/lgsm/modules/install_config.sh @@ -33,7 +33,7 @@ fn_default_config_remote() { echo -e "" echo -e "${bold}${lightyellow}Downloading ${gamename} Configs${default}" echo -e "${bold}=================================${default}" - echo -e "Default configs are downloaded from:" + echo -e "Downloading default configs from:" echo -e "" echo -e "${italic}https://github.com/GameServerManagers/Game-Server-Configs${default}" echo -e "" @@ -48,8 +48,8 @@ fn_default_config_remote() { if [ "${shortname}" == "arma3" ] && [ "${config}" == "${networkcfgdefault}" ]; then echo -en "copying config file [ ${italic}${networkcfgfullpath}${default} ]" changes+=$(cp -nv "${lgsmdir}/config-default/config-game/${config}" "${networkcfgfullpath}") - elif [ "${shortname}" == "dst" ] && [ "${config}" == "${clustercfgdefault}" ]; then - echo -en "copying config file [ ${italic}${clustercfgdefault}${default} ]" + elif [ "${shortname}" == "dst" ] && [ "${config}" == "${clustercfgfullpath}" ]; then + echo -en "copying config file [ ${italic}${clustercfgfullpath}${default} ]" changes+=$(cp -nv "${lgsmdir}/config-default/config-game/${clustercfgdefault}" "${clustercfgfullpath}") else echo -en "copying config file [ ${italic}${servercfgdir}/${config}${default} ]" @@ -70,6 +70,10 @@ fn_default_config_remote() { # Copys local default config to server config location. fn_default_config_local() { + echo -e "" + echo -e "${bold}${lightyellow}Copying ${gamename} Configs${default}" + echo -e "${bold}=================================${default}" + echo -e "Copying default configs." fn_check_cfgdir echo -en "copying config file [ ${italic}${servercfgdefault}${default} ]" cp -n "${servercfgdir}/${servercfgdefault}" "${servercfgfullpath}"