Jelajahi Sumber

refactor: improve code readability and fix typos

- Refactored the code to improve readability and organization.
- Fixed typos in the comments and echo statements.
- Changed some echo statements to use variables for better consistency.
- Updated URLs in the echo statements to be clickable links.

Co-authored-by: [co-author name]
Daniel Gibbs 2 tahun lalu
induk
melakukan
9f1448983d
2 mengubah file dengan 53 tambahan dan 42 penghapusan
  1. 5 5
      lgsm/modules/install_complete.sh
  2. 48 37
      lgsm/modules/install_config.sh

+ 5 - 5
lgsm/modules/install_complete.sh

@@ -11,21 +11,21 @@ echo -e ""
 echo -e "${bold}=================================${default}"
 echo -e "${bold}=================================${default}"
 
 
 if [ "${exitcode}" == "1" ]; then
 if [ "${exitcode}" == "1" ]; then
-	echo -e "Install Failed!"
+	echo -e "${red}Install Failed!${default}"
 	fn_script_log_fatal "Install Failed!"
 	fn_script_log_fatal "Install Failed!"
 elif [ "${exitcode}" == "2" ]; then
 elif [ "${exitcode}" == "2" ]; then
-	echo -e "Install Completed with Errors!"
+	echo -e "${red}Install Completed with Errors!${default}}"
 	fn_script_log_error "Install Completed with Errors!"
 	fn_script_log_error "Install Completed with Errors!"
 elif [ "${exitcode}" == "3" ]; then
 elif [ "${exitcode}" == "3" ]; then
-	echo -e "Install Completed with Warnings!"
+	echo -e "${lightyellow}Install Completed with Warnings!${default}}"
 	fn_script_log_warn "Install Completed with Warnings!"
 	fn_script_log_warn "Install Completed with Warnings!"
 elif [ -z "${exitcode}" ] || [ "${exitcode}" == "0" ]; then
 elif [ -z "${exitcode}" ] || [ "${exitcode}" == "0" ]; then
-	echo -e "Install Complete!"
+	echo -e "${green}Install Complete!${default}}"
 	fn_script_log_pass "Install Complete!"
 	fn_script_log_pass "Install Complete!"
 fi
 fi
 
 
 echo -e ""
 echo -e ""
 echo -e "To start the ${gamename} server type:"
 echo -e "To start the ${gamename} server type:"
-echo -e "./${selfname} start"
+echo -e "${italic}./${selfname} start${default}"
 echo -e ""
 echo -e ""
 core_exit.sh
 core_exit.sh

+ 48 - 37
lgsm/modules/install_config.sh

@@ -9,17 +9,24 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 # Checks if server cfg dir exists, creates it if it doesn't.
 # Checks if server cfg dir exists, creates it if it doesn't.
 fn_check_cfgdir() {
 fn_check_cfgdir() {
-	if [ ! -d "${servercfgdir}" ]; then
+
+	if [ "${shortname}" == "dst" ]; then
+		echo -en "creating ${clustercfgfullpath} config directory"
+		mkdir -p "${clustercfgfullpath}"
+	elif [ "${shortname}" == "arma3" ]; then
+		echo -en "creating ${networkcfgfullpath} config directory"
+		mkdir -p "${networkcfgfullpath}"
+	else
 		echo -en "creating ${servercfgdir} config directory"
 		echo -en "creating ${servercfgdir} config directory"
-		mkdir -pv "${servercfgdir}"
-		if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181
-			fn_print_fail_eol
-			fn_script_log_fatal "creating ${servercfgdir} config directory"
-			core_exit.sh
-		else
-			fn_print_ok_eol
-			fn_script_log_pass "creating ${servercfgdir} config directory"
-		fi
+		mkdir -p "${servercfgdir}"
+	fi
+	if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181
+		fn_print_fail_eol
+		fn_script_log_fatal "creating ${servercfgdir} config directory"
+		core_exit.sh
+	else
+		fn_print_ok_eol
+		fn_script_log_pass "creating ${servercfgdir} config directory"
 	fi
 	fi
 }
 }
 
 
@@ -36,31 +43,35 @@ fn_default_config_remote() {
 	fn_sleep_time
 	fn_sleep_time
 	githuburl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/main"
 	githuburl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/main"
 	for config in "${array_configs[@]}"; do
 	for config in "${array_configs[@]}"; do
-		fn_fetch_file "${githuburl}/${shortname}/${config}" "${remote_fileurl_backup}" "GitHub" "Bitbucket" "${lgsmdir}/config-default/config-game" "${config}" "nochmodx" "norun" "forcedl" "nohash"
-	done
-	fn_check_cfgdir
-	for config in "${array_configs[@]}"; do
-		# every config is copied
-		echo -en "copying config file [ ${italic}${servercfgfullpath}${default} ]"
-		if [ "${config}" == "${servercfgdefault}" ]; then
-			mkdir -p "${servercfgdir}"
-			cp -nv "${lgsmdir}/config-default/config-game/${config}" "${servercfgfullpath}"
-		elif [ "${shortname}" == "arma3" ] && [ "${config}" == "${networkcfgdefault}" ]; then
-			mkdir -p "${servercfgdir}"
-			cp -nv "${lgsmdir}/config-default/config-game/${config}" "${networkcfgfullpath}"
-		elif [ "${shortname}" == "dst" ] && [ "${config}" == "${clustercfgdefault}" ]; then
-			mkdir -p "${clustercfgfullpath}"
-			cp -nv "${lgsmdir}/config-default/config-game/${clustercfgdefault}" "${clustercfgfullpath}"
-		else
-			mkdir -p "${servercfgdir}"
-			cp -nv "${lgsmdir}/config-default/config-game/${config}" "${servercfgdir}/${config}"
-		fi
-		if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181
-			fn_print_failure_eol_nl
-			fn_script_log_fatal "copying config file ${servercfgfullpath}"
-		else
-			fn_print_ok_eol_nl
-			fn_script_log_pass "copying config file ${servercfgfullpath}"
+		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"
+
+			fn_check_cfgdir
+
+			changes=""
+			if [ "${config}" == "${servercfgdefault}" ]; then
+				echo -en "copying config file [ ${italic}${servercfgfullpath}${default} ]"
+				changes+=$(cp -n "${lgsmdir}/config-default/config-game/${config}" "${servercfgfullpath}")
+			elif [ "${shortname}" == "arma3" ] && [ "${config}" == "${networkcfgdefault}" ]; then
+				echo -en "copying config file [ ${italic}${networkcfgfullpath}${default} ]"
+				changes+=$(cp -n "${lgsmdir}/config-default/config-game/${config}" "${networkcfgfullpath}")
+			elif [ "${shortname}" == "dst" ] && [ "${config}" == "${clustercfgdefault}" ]; then
+				echo -en "copying config file [ ${italic}${clustercfgdefault}${default} ]"
+				changes+=$(cp -n "${lgsmdir}/config-default/config-game/${clustercfgdefault}" "${clustercfgfullpath}")
+			else
+				echo -en "copying config file [ ${italic}${servercfgdir}/${config}${default} ]"
+				changes+=$(cp -n "${lgsmdir}/config-default/config-game/${config}" "${servercfgdir}/${config}")
+			fi
+			if [ "$?" -ne 0 ]; then # shellcheck disable=SC2181
+				fn_print_failure_eol_nl
+				fn_script_log_fatal "copying config file ${servercfgfullpath}"
+			elif [ "${changes}" != "" ]; then
+				fn_print_ok_eol_nl
+				fn_script_log_pass "copying config file ${servercfgfullpath}"
+			else
+				fn_print_skip_eol_nl
+			fi
+
 		fi
 		fi
 	done
 	done
 }
 }
@@ -69,7 +80,7 @@ fn_default_config_remote() {
 fn_default_config_local() {
 fn_default_config_local() {
 	fn_check_cfgdir
 	fn_check_cfgdir
 	echo -en "copying config file [ ${italic}${servercfgdefault}${default} ]"
 	echo -en "copying config file [ ${italic}${servercfgdefault}${default} ]"
-	cp -nv "${servercfgdir}/${servercfgdefault}" "${servercfgfullpath}"
+	cp -n "${servercfgdir}/${servercfgdefault}" "${servercfgfullpath}"
 	if [ "${exitcode}" != 0 ]; then
 	if [ "${exitcode}" != 0 ]; then
 		fn_print_fail_eol
 		fn_print_fail_eol
 		fn_script_log_fatal "copying config file [ ${servercfgdefault} ]"
 		fn_script_log_fatal "copying config file [ ${servercfgdefault} ]"
@@ -176,7 +187,7 @@ fn_list_config_locations() {
 		fi
 		fi
 	fi
 	fi
 	echo -e "LinuxGSM config: ${italic}${lgsmdir}/config-lgsm/${gameservername}${default}"
 	echo -e "LinuxGSM config: ${italic}${lgsmdir}/config-lgsm/${gameservername}${default}"
-	echo -e "Config documentation: ${italic}https://docs.linuxgsm.com/configuration{default}"
+	echo -e "Config documentation: ${italic}https://docs.linuxgsm.com/configuration${default}"
 }
 }
 
 
 if [ "${shortname}" == "sdtd" ]; then
 if [ "${shortname}" == "sdtd" ]; then