Skip to content

Commit

Permalink
refactor: simplify config directory creation and copying
Browse files Browse the repository at this point in the history
The code changes simplify the logic for creating config directories and copying config files. The function `fn_check_cfgdir` now only creates the server config directory if it exists, removing unnecessary checks for other directories. Additionally, the function `fn_default_config_remote` no longer duplicates the call to `fn_check_cfgdir`.
  • Loading branch information
dgibbs64 committed Sep 30, 2023
1 parent e499c1c commit d9658ae
Showing 1 changed file with 5 additions and 36 deletions.
41 changes: 5 additions & 36 deletions lgsm/modules/install_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,8 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

# Checks if server cfg dir exists, creates it if it doesn't.
fn_check_cfgdir() {
changes=""
if [ -n "${clustercfgdir}" ]; then
echo -en "creating config directory [ ${italic}${clustercfgdir}${default} ]"
changes+=$(mkdir -pv "${clustercfgdir}")
if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181
fn_print_fail_eol_nl
fn_script_log_fatal "creating ${servercfgdir} config directory"
core_exit.sh
elif [ "${changes}" != "" ]; then
fn_print_ok_eol_nl
fn_script_log_pass "creating ${servercfgdir} config directory"
else
fn_print_skip_eol_nl
fi
elif [ -n "${networkcfgdir}" ]; then
echo -en "creating config directory [ ${italic}${networkcfgdir}${default} ]"
changes+=$(mkdir -pv "${networkcfgdir}")
if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181
fn_print_fail_eol_nl
fn_script_log_fatal "creating ${servercfgdir} config directory"
core_exit.sh
elif [ "${changes}" != "" ]; then
fn_print_ok_eol_nl
fn_script_log_pass "creating ${servercfgdir} config directory"
else
fn_print_skip_eol_nl
fi
else
if [ -n "${servercfgdir}" ]; then
changes=""
echo -en "creating config directory [ ${italic}${servercfgdir}${default} ]"
changes+=$(mkdir -pv "${servercfgdir}")
if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181
Expand All @@ -49,9 +23,8 @@ fn_check_cfgdir() {
else
fn_print_skip_eol_nl
fi
unset changes
fi

unset changes
}

# Copys default configs from Game-Server-Configs repo to server config location.
Expand All @@ -65,18 +38,14 @@ fn_default_config_remote() {
echo -e "${italic}https://github.com/GameServerManagers/Game-Server-Configs${default}"
echo -e ""
fn_sleep_time
fn_check_cfgdir
githuburl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/main"
for config in "${array_configs[@]}"; do
if [ ! -f "${lgsmdir}/config-default/config-game/${config}" ]; then
fn_fetch_file "${githuburl}/${shortname}/${config}" "${remote_fileurl_backup}" "GitHub" "Bitbucket" "${lgsmdir}/config-default/config-game" "${config}" "nochmodx" "norun" "forcedl" "nohash"
fi
fn_check_cfgdir

changes=""
if [ "${config}" == "${servercfgdefault}" ]; then
echo -en "copying config file [ ${italic}${servercfgfullpath}${default} ]"
changes+=$(cp -nv "${lgsmdir}/config-default/config-game/${config}" "${servercfgfullpath}")
elif [ "${shortname}" == "arma3" ] && [ "${config}" == "${networkcfgdefault}" ]; then
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
Expand Down

0 comments on commit d9658ae

Please sign in to comment.