Skip to content

Commit 4898caa

Browse files
committed
feat: add 24h caching to external ip gathering
this will prevent querying of external ip tool repeatedly Also tidied up a few rm commands
1 parent ba339d9 commit 4898caa

13 files changed

+28
-31
lines changed

lgsm/functions/command_dev_debug.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1111
fn_firstcommand_reset
1212

1313
if [ -f "${rootdir}/.dev-debug" ]; then
14-
rm "${rootdir:?}/.dev-debug"
14+
rm -f "${rootdir:?}/.dev-debug"
1515
fn_print_ok_nl "Disabled dev-debug"
1616
fn_script_log_info "Disabled dev-debug"
1717
else

lgsm/functions/command_fastdl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn_clear_old_fastdl() {
6868
# Clearing old FastDL.
6969
if [ -d "${fastdldir}" ]; then
7070
echo -en "clearing existing FastDL directory ${fastdldir}..."
71-
rm -fR "${fastdldir:?}"
71+
rm -rf "${fastdldir:?}"
7272
exitcode=$?
7373
if [ "${exitcode}" != 0 ]; then
7474
fn_print_fail_eol_nl
@@ -277,7 +277,7 @@ fn_fastdl_gmod() {
277277
# Clear addons directory in fastdl.
278278
echo -en "clearing addons dir from fastdl dir..."
279279
fn_sleep_time
280-
rm -fR "${fastdldir:?}/addons"
280+
rm -rf "${fastdldir:?}/addons"
281281
exitcode=$?
282282
if [ "${exitcode}" != 0 ]; then
283283
fn_print_fail_eol_nl

lgsm/functions/command_start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn_start_tmux() {
171171
fn_print_ok "${servername}"
172172
fn_script_log_pass "Started ${servername}"
173173
fi
174-
rm "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp" 2> /dev/null
174+
rm -f "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp" 2> /dev/null
175175
echo -en "\n"
176176
}
177177

lgsm/functions/core_dl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ fn_fetch_file() {
374374
# Download will fail if downloads a html file.
375375
if [ -f "${local_filedir}/${local_filename}" ]; then
376376
if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
377-
rm "${local_filedir:?}/${local_filename:?}"
377+
rm -f "${local_filedir:?}/${local_filename:?}"
378378
local exitcode=2
379379
fi
380380
fi

lgsm/functions/core_steamcmd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn_check_steamcmd_dir() {
7373
# Symbolic links to Steam installation directory.
7474
if [ ! -L "${HOME}/.steam/root" ]; then
7575
if [ -d "${HOME}/.steam/root" ]; then
76-
rm "${HOME}/.steam/root"
76+
rm -f "${HOME:?}/.steam/root"
7777
fi
7878
ln -s "${XDG_DATA_HOME:="${HOME}/.local/share"}/Steam" "${HOME}/.steam/root"
7979
fi

lgsm/functions/info_game.sh

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,27 +2561,24 @@ elif [ "${engine}" == "unreal2" ]; then
25612561
fi
25622562

25632563
# External IP address
2564-
if [ -z "${extip}" ]; then
2564+
# Cache external IP address for 24 hours
2565+
if [ -f "${tmpdir}/extip.txt" ]; then
2566+
if [ "$(find "${tmpdir}/extip.txt" -mmin +1440)" ]; then
2567+
rm -f "${tmpdir:?}/extip.txt"
2568+
fi
2569+
fi
2570+
2571+
if [ ! -f "${tmpdir}/extip.txt" ]; then
25652572
extip="$(curl --connect-timeout 10 -s https://api.ipify.org 2> /dev/null)"
25662573
exitcode=$?
2567-
# Should ifconfig.co return an error will use last known IP.
2568-
if [ ${exitcode} -eq 0 ]; then
2569-
if [[ "${extip}" != *"DOCTYPE"* ]]; then
2570-
echo -e "${extip}" > "${tmpdir}/extip.txt"
2571-
else
2572-
if [ -f "${tmpdir}/extip.txt" ]; then
2573-
extip="$(cat "${tmpdir}/extip.txt")"
2574-
else
2575-
fn_print_error_nl "Unable to get external IP"
2576-
fi
2577-
fi
2574+
# if curl passes add extip to externalip.txt
2575+
if [ "${exitcode}" == "0" ]; then
2576+
echo "${extip}" > "${tmpdir}/extip.txt"
25782577
else
2579-
if [ -f "${tmpdir}/extip.txt" ]; then
2580-
extip="$(cat "${tmpdir}/extip.txt")"
2581-
else
2582-
fn_print_error_nl "Unable to get external IP"
2583-
fi
2578+
echo "Unable to get external IP address"
25842579
fi
2580+
else
2581+
extip="$(cat "${tmpdir}/extip.txt")"
25852582
fi
25862583

25872584
# Alert IP address

lgsm/functions/info_stats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ info_distro.sh
1212

1313
# remove uuid that was used in v20.2.0 and below
1414
if [ -f "${datadir}/uuid.txt" ]; then
15-
rm "${datadir:?}/uuid.txt"
15+
rm -f "${datadir:?}/uuid.txt"
1616
fi
1717

1818
# generate uuid's

lgsm/functions/mods_core.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ fn_mods_create_tmp_dir() {
440440
fn_mods_clear_tmp_dir() {
441441
if [ -d "${modstmpdir}" ]; then
442442
echo -en "clearing mod download directory ${modstmpdir}..."
443-
rm -fr "${modstmpdir:?}"
443+
rm -rf "${modstmpdir:?}"
444444
exitcode=$?
445445
if [ "${exitcode}" != 0 ]; then
446446
fn_print_fail_eol_nl
@@ -742,7 +742,7 @@ fn_mod_remove_amxmodx_file() {
742742

743743
# if file is empty, remove it.
744744
if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
745-
rm "${modinstalldir}/addons/metamod/plugins.ini"
745+
rm -f "${modinstalldir}/addons/metamod/plugins.ini"
746746
fn_script_log_pass "file removed ${modinstalldir}/addons/metamod/plugins.ini because it was empty"
747747
fi
748748
fi

linuxgsm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn_bootstrap_fetch_file() {
113113
# Download will fail if downloads a html file.
114114
if [ -f "${local_filedir}/${local_filename}" ]; then
115115
if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
116-
rm "${local_filedir:?}/${local_filename:?}"
116+
rm -f "${local_filedir:?}/${local_filename:?}"
117117
local exitcode=2
118118
fi
119119
fi

tests/tests_fctrserver.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn_bootstrap_fetch_file() {
112112
# Download will fail if downloads a html file.
113113
if [ -f "${local_filedir}/${local_filename}" ]; then
114114
if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
115-
rm "${local_filedir:?}/${local_filename:?}"
115+
rm -f "${local_filedir:?}/${local_filename:?}"
116116
local exitcode=2
117117
fi
118118
fi

0 commit comments

Comments
 (0)