Просмотр исходного кода

feat: add 24h caching to external ip gathering

this will prevent querying of external ip tool repeatedly
Also tidied up a few rm commands
Daniel Gibbs 3 лет назад
Родитель
Сommit
4898caa345

+ 1 - 1
lgsm/functions/command_dev_debug.sh

@@ -11,7 +11,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 fn_firstcommand_reset
 
 if [ -f "${rootdir}/.dev-debug" ]; then
-	rm "${rootdir:?}/.dev-debug"
+	rm -f "${rootdir:?}/.dev-debug"
 	fn_print_ok_nl "Disabled dev-debug"
 	fn_script_log_info "Disabled dev-debug"
 else

+ 2 - 2
lgsm/functions/command_fastdl.sh

@@ -68,7 +68,7 @@ fn_clear_old_fastdl() {
 	# Clearing old FastDL.
 	if [ -d "${fastdldir}" ]; then
 		echo -en "clearing existing FastDL directory ${fastdldir}..."
-		rm -fR "${fastdldir:?}"
+		rm -rf "${fastdldir:?}"
 		exitcode=$?
 		if [ "${exitcode}" != 0 ]; then
 			fn_print_fail_eol_nl
@@ -277,7 +277,7 @@ fn_fastdl_gmod() {
 		# Clear addons directory in fastdl.
 		echo -en "clearing addons dir from fastdl dir..."
 		fn_sleep_time
-		rm -fR "${fastdldir:?}/addons"
+		rm -rf "${fastdldir:?}/addons"
 		exitcode=$?
 		if [ "${exitcode}" != 0 ]; then
 			fn_print_fail_eol_nl

+ 1 - 1
lgsm/functions/command_start.sh

@@ -171,7 +171,7 @@ fn_start_tmux() {
 		fn_print_ok "${servername}"
 		fn_script_log_pass "Started ${servername}"
 	fi
-	rm "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp" 2> /dev/null
+	rm -f "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp" 2> /dev/null
 	echo -en "\n"
 }
 

+ 1 - 1
lgsm/functions/core_dl.sh

@@ -374,7 +374,7 @@ fn_fetch_file() {
 			# Download will fail if downloads a html file.
 			if [ -f "${local_filedir}/${local_filename}" ]; then
 				if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
-					rm "${local_filedir:?}/${local_filename:?}"
+					rm -f "${local_filedir:?}/${local_filename:?}"
 					local exitcode=2
 				fi
 			fi

+ 1 - 1
lgsm/functions/core_steamcmd.sh

@@ -73,7 +73,7 @@ fn_check_steamcmd_dir() {
 	# Symbolic links to Steam installation directory.
 	if [ ! -L "${HOME}/.steam/root" ]; then
 		if [ -d "${HOME}/.steam/root" ]; then
-			rm "${HOME}/.steam/root"
+			rm -f "${HOME:?}/.steam/root"
 		fi
 		ln -s "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" "${HOME}/.steam/root"
 	fi

+ 14 - 17
lgsm/functions/info_game.sh

@@ -2561,27 +2561,24 @@ elif [ "${engine}" == "unreal2" ]; then
 fi
 
 # External IP address
-if [ -z "${extip}" ]; then
+# Cache external IP address for 24 hours
+if [ -f "${tmpdir}/extip.txt" ]; then
+	if [ "$(find "${tmpdir}/extip.txt" -mmin +1440)" ]; then
+		rm -f "${tmpdir:?}/extip.txt"
+	fi
+fi
+
+if [ ! -f "${tmpdir}/extip.txt" ]; then
 	extip="$(curl --connect-timeout 10 -s https://api.ipify.org 2> /dev/null)"
 	exitcode=$?
-	# Should ifconfig.co return an error will use last known IP.
-	if [ ${exitcode} -eq 0 ]; then
-		if [[ "${extip}" != *"DOCTYPE"* ]]; then
-			echo -e "${extip}" > "${tmpdir}/extip.txt"
-		else
-			if [ -f "${tmpdir}/extip.txt" ]; then
-				extip="$(cat "${tmpdir}/extip.txt")"
-			else
-				fn_print_error_nl "Unable to get external IP"
-			fi
-		fi
+	# if curl passes add extip to externalip.txt
+	if [ "${exitcode}" == "0" ]; then
+		echo "${extip}" > "${tmpdir}/extip.txt"
 	else
-		if [ -f "${tmpdir}/extip.txt" ]; then
-			extip="$(cat "${tmpdir}/extip.txt")"
-		else
-			fn_print_error_nl "Unable to get external IP"
-		fi
+		echo "Unable to get external IP address"
 	fi
+else
+	extip="$(cat "${tmpdir}/extip.txt")"
 fi
 
 # Alert IP address

+ 1 - 1
lgsm/functions/info_stats.sh

@@ -12,7 +12,7 @@ info_distro.sh
 
 # remove uuid that was used in v20.2.0 and below
 if [ -f "${datadir}/uuid.txt" ]; then
-	rm "${datadir:?}/uuid.txt"
+	rm -f "${datadir:?}/uuid.txt"
 fi
 
 # generate uuid's

+ 2 - 2
lgsm/functions/mods_core.sh

@@ -440,7 +440,7 @@ fn_mods_create_tmp_dir() {
 fn_mods_clear_tmp_dir() {
 	if [ -d "${modstmpdir}" ]; then
 		echo -en "clearing mod download directory ${modstmpdir}..."
-		rm -fr "${modstmpdir:?}"
+		rm -rf "${modstmpdir:?}"
 		exitcode=$?
 		if [ "${exitcode}" != 0 ]; then
 			fn_print_fail_eol_nl
@@ -742,7 +742,7 @@ fn_mod_remove_amxmodx_file() {
 
 			# if file is empty, remove it.
 			if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
-				rm "${modinstalldir}/addons/metamod/plugins.ini"
+				rm -f "${modinstalldir}/addons/metamod/plugins.ini"
 				fn_script_log_pass "file removed ${modinstalldir}/addons/metamod/plugins.ini because it was empty"
 			fi
 		fi

+ 1 - 1
linuxgsm.sh

@@ -113,7 +113,7 @@ fn_bootstrap_fetch_file() {
 			# Download will fail if downloads a html file.
 			if [ -f "${local_filedir}/${local_filename}" ]; then
 				if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
-					rm "${local_filedir:?}/${local_filename:?}"
+					rm -f "${local_filedir:?}/${local_filename:?}"
 					local exitcode=2
 				fi
 			fi

+ 1 - 1
tests/tests_fctrserver.sh

@@ -112,7 +112,7 @@ fn_bootstrap_fetch_file() {
 			# Download will fail if downloads a html file.
 			if [ -f "${local_filedir}/${local_filename}" ]; then
 				if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
-					rm "${local_filedir:?}/${local_filename:?}"
+					rm -f "${local_filedir:?}/${local_filename:?}"
 					local exitcode=2
 				fi
 			fi

+ 1 - 1
tests/tests_jc2server.sh

@@ -113,7 +113,7 @@ fn_bootstrap_fetch_file() {
 			# Download will fail if downloads a html file.
 			if [ -f "${local_filedir}/${local_filename}" ]; then
 				if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
-					rm "${local_filedir:?}/${local_filename:?}"
+					rm -f "${local_filedir:?}/${local_filename:?}"
 					local exitcode=2
 				fi
 			fi

+ 1 - 1
tests/tests_mcserver.sh

@@ -113,7 +113,7 @@ fn_bootstrap_fetch_file() {
 			# Download will fail if downloads a html file.
 			if [ -f "${local_filedir}/${local_filename}" ]; then
 				if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
-					rm "${local_filedir:?}/${local_filename:?}"
+					rm -f "${local_filedir:?}/${local_filename:?}"
 					local exitcode=2
 				fi
 			fi

+ 1 - 1
tests/tests_ts3server.sh

@@ -113,7 +113,7 @@ fn_bootstrap_fetch_file() {
 			# Download will fail if downloads a html file.
 			if [ -f "${local_filedir}/${local_filename}" ]; then
 				if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
-					rm "${local_filedir:?}/${local_filename:?}"
+					rm -f "${local_filedir:?}/${local_filename:?}"
 					local exitcode=2
 				fi
 			fi