Skip to content

Commit bdfc6e5

Browse files
committed
Refactor remote build version handling across multiple modules
- Updated variable names from 'remotebuildversion' to 'remotebuild' for consistency. - Adjusted logic to check for remote build availability using the new variable name. - Modified output messages to reflect the change in variable naming. - Ensured all modules (update_mc.sh, update_mcb.sh, update_mta.sh, update_pmc.sh, update_ts3.sh, update_ut99.sh, update_vints.sh, update_xnt.sh) are aligned with the new naming convention for better readability and maintainability.
1 parent cfa873c commit bdfc6e5

File tree

12 files changed

+203
-155
lines changed

12 files changed

+203
-155
lines changed

lgsm/modules/alert.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,37 @@ fn_alert_monitor_query() {
9797

9898
# Update alerts
9999
fn_alert_update() {
100-
fn_script_log_info "Sending alert: ${selfname} has received a game server update: ${localbuild}"
100+
# If previousbuild is set show transition, else fallback to single version.
101+
if [ -n "${previousbuild:-}" ] && [ -n "${localbuild:-}" ]; then
102+
fn_script_log_info "Sending alert: ${selfname} updated ${previousbuild} -> ${localbuild}"
103+
alertmessage="${selfname} has been updated: ${previousbuild} -> ${localbuild}."
104+
else
105+
fn_script_log_info "Sending alert: ${selfname} has received a game server update: ${localbuild}"
106+
alertmessage="${selfname} has received a game server update: ${localbuild}."
107+
fi
101108
alertaction="Updated"
102109
alertemoji="🎉"
103110
alertsound="1"
104-
alertmessage="${selfname} has received a game server update: ${localbuild}."
105111
# Green
106112
alertcolourhex="#00cd00"
107113
alertcolourdec="52480"
108114
}
109115

116+
# Update failure alert
117+
fn_alert_update_failed() {
118+
# Expect updatefailureexpected (target version) and updatefailuregot (actual localbuild) if set
119+
local expected="${updatefailureexpected:-${remotebuild:-unknown}}"
120+
local got="${updatefailuregot:-${localbuild:-unknown}}"
121+
fn_script_log_error "Sending alert: ${selfname} update failed expected ${expected} got ${got}"
122+
alertaction="Update Failed"
123+
alertemoji=""
124+
alertsound="2"
125+
alertmessage="${selfname} update failed. Expected ${expected} but is still ${got}. Manual intervention required."
126+
# Red
127+
alertcolourhex="#cd0000"
128+
alertcolourdec="13434880"
129+
}
130+
110131
fn_alert_update_request() {
111132
fn_script_log_info "Sending alert: ${selfname} has requested an update and needs to be restarted."
112133
alertaction="Updating"
@@ -119,11 +140,11 @@ fn_alert_update_request() {
119140
}
120141

121142
fn_alert_check_update() {
122-
fn_script_log_info "Sending alert: ${gamename} update available: ${remotebuildversion}"
143+
fn_script_log_info "Sending alert: ${gamename} update available: ${localbuild} -> ${remotebuild}"
123144
alertaction="Update available"
124145
alertemoji="🎉"
125146
alertsound="1"
126-
alertmessage="${gamename} update available: ${remotebuildversion}"
147+
alertmessage="${gamename} update available: ${localbuild} -> ${remotebuild}"
127148
# Blue
128149
alertcolourhex="#1e90ff"
129150
alertcolourdec="2003199"
@@ -210,6 +231,8 @@ elif [ "${alert}" == "test" ]; then
210231
fn_alert_test
211232
elif [ "${alert}" == "update" ]; then
212233
fn_alert_update
234+
elif [ "${alert}" == "update-failed" ]; then
235+
fn_alert_update_failed
213236
elif [ "${alert}" == "update-request" ]; then
214237
fn_alert_update_request
215238
elif [ "${alert}" == "check-update" ]; then

lgsm/modules/core_steamcmd.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ fn_update_steamcmd_remotebuild() {
185185
fi
186186

187187
# password for branch not needed to check the buildid
188-
remotebuildversion=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_request "${appid}" +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed -e '/"branches"/,/^}/!d' | sed -n "/\"${branch}\"/,/}/p" | grep -m 1 buildid | tr -cd '[:digit:]')
188+
remotebuild=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_request "${appid}" +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed -e '/"branches"/,/^}/!d' | sed -n "/\"${branch}\"/,/}/p" | grep -m 1 buildid | tr -cd '[:digit:]')
189189

190190
if [ "${firstcommandname}" != "INSTALL" ]; then
191191
fn_print_dots "Checking remote build: ${remotelocation}"
192-
# Checks if remotebuildversion variable has been set.
193-
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
192+
# Checks if remotebuild variable has been set.
193+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
194194
fn_print_fail "Checking remote build: ${remotelocation}"
195195
fn_script_log_fail "Checking remote build"
196196
core_exit.sh
@@ -200,7 +200,7 @@ fn_update_steamcmd_remotebuild() {
200200
fi
201201
else
202202
# Checks if remotebuild variable has been set.
203-
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
203+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
204204
fn_print_failure "Unable to get remote build"
205205
fn_script_log_fail "Unable to get remote build"
206206
core_exit.sh
@@ -211,14 +211,14 @@ fn_update_steamcmd_remotebuild() {
211211
fn_update_steamcmd_compare() {
212212
fn_print_dots "Checking for update: ${remotelocation}"
213213
# Update has been found or force update.
214-
if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
214+
if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
215215
# Create update lockfile.
216216
date '+%s' > "${lockdir:?}/update.lock"
217217
fn_print_ok_nl "Checking for update: ${remotelocation}"
218218
fn_print "\n"
219219
fn_print_nl "${bold}${underline}Update${default} available"
220220
fn_print_nl "* Local build: ${red}${localbuild}${default}"
221-
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
221+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
222222
if [ -n "${branch}" ]; then
223223
fn_print_nl "* Branch: ${branch}"
224224
fi
@@ -229,14 +229,14 @@ fn_update_steamcmd_compare() {
229229
fn_print "\n"
230230
fn_script_log_info "Update available"
231231
fn_script_log_info "Local build: ${localbuild}"
232-
fn_script_log_info "Remote build: ${remotebuildversion}"
232+
fn_script_log_info "Remote build: ${remotebuild}"
233233
if [ -n "${branch}" ]; then
234234
fn_script_log_info "Branch: ${branch}"
235235
fi
236236
if [ -n "${betapassword}" ]; then
237237
fn_script_log_info "Branch password: ${betapassword}"
238238
fi
239-
fn_script_log_info "${localbuild} > ${remotebuildversion}"
239+
fn_script_log_info "${localbuild} > ${remotebuild}"
240240

241241
if [ "${commandname}" == "UPDATE" ]; then
242242
date +%s > "${lockdir:?}/last-updated.lock"
@@ -268,7 +268,7 @@ fn_update_steamcmd_compare() {
268268
fn_print "\n"
269269
fn_print_nl "${bold}${underline}No update${default} available"
270270
fn_print_nl "* Local build: ${green}${localbuild}${default}"
271-
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
271+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
272272
if [ -n "${branch}" ]; then
273273
fn_print_nl "* Branch: ${branch}"
274274
fi
@@ -279,7 +279,7 @@ fn_update_steamcmd_compare() {
279279
fn_print "\n"
280280
fn_script_log_info "No update available"
281281
fn_script_log_info "Local build: ${localbuild}"
282-
fn_script_log_info "Remote build: ${remotebuildversion}"
282+
fn_script_log_info "Remote build: ${remotebuild}"
283283
if [ -n "${branch}" ]; then
284284
fn_script_log_info "Branch: ${branch}"
285285
fi

lgsm/modules/update_fctr.sh

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,32 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1010
fn_update_dl() {
1111
# Download and extract files to serverfiles.
1212
fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
13-
fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${remotebuildversion}.tar.xz" "${serverfiles}" "factorio"
13+
fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${remotebuild}.tar.xz" "${serverfiles}" "factorio"
1414
fn_clear_tmp
1515
}
1616

1717
fn_update_localbuild() {
18-
# Gets local build info.
19-
fn_print_dots "Checking local build: ${remotelocation}"
18+
# Optional arg1: 'silent' to suppress user-facing output
19+
local mode="${1:-}"
20+
if [ "${mode}" != "silent" ]; then
21+
fn_print_dots "Checking local build: ${remotelocation}"
22+
fi
2023
# Uses executable to get local build.
2124
if [ -d "${executabledir}" ]; then
2225
cd "${executabledir}" || exit
2326
localbuild=$(${executable} --version | grep -m 1 "Version:" | awk '{print $2}')
2427
fi
2528
if [ -z "${localbuild}" ]; then
26-
fn_print_error "Checking local build: ${remotelocation}: missing local build info"
29+
if [ "${mode}" != "silent" ]; then
30+
fn_print_error "Checking local build: ${remotelocation}: missing local build info"
31+
fi
2732
fn_script_log_error "Missing local build info"
2833
fn_script_log_error "Set localbuild to 0"
2934
localbuild="0"
3035
else
31-
fn_print_ok "Checking local build: ${remotelocation}"
36+
if [ "${mode}" != "silent" ]; then
37+
fn_print_ok "Checking local build: ${remotelocation}"
38+
fi
3239
fn_script_log_pass "Checking local build"
3340
fi
3441
}
@@ -37,14 +44,14 @@ fn_update_remotebuild() {
3744
# Gets remote build info.
3845
apiurl="https://factorio.com/get-download/${branch}/headless/${factorioarch}"
3946
remotebuildresponse=$(curl -s "${apiurl}")
40-
remotebuildversion=$(echo "${remotebuildresponse}" | grep -o '[0-9]\.[0-9]\{1,\}\.[0-9]\{1,\}' | head -1)
47+
remotebuild=$(echo "${remotebuildresponse}" | grep -o '[0-9]\.[0-9]\{1,\}\.[0-9]\{1,\}' | head -1)
4148
remotebuildurl="https://factorio.com/get-download/${branch}/headless/${factorioarch}"
42-
remotebuildfilename="factorio_headless_${factorioarch}-${remotebuildversion}.tar.xz"
49+
remotebuildfilename="factorio_headless_${factorioarch}-${remotebuild}.tar.xz"
4350

4451
if [ "${firstcommandname}" != "INSTALL" ]; then
4552
fn_print_dots "Checking remote build: ${remotelocation}"
46-
# Checks if remotebuildversion variable has been set.
47-
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
53+
# Checks if remotebuild variable has been set.
54+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
4855
fn_print_fail "Checking remote build: ${remotelocation}"
4956
fn_script_log_fail "Checking remote build"
5057
core_exit.sh
@@ -54,7 +61,7 @@ fn_update_remotebuild() {
5461
fi
5562
else
5663
# Checks if remotebuild variable has been set.
57-
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
64+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
5865
fn_print_failure "Unable to get remote build"
5966
fn_script_log_fail "Unable to get remote build"
6067
core_exit.sh
@@ -65,14 +72,14 @@ fn_update_remotebuild() {
6572
fn_update_compare() {
6673
fn_print_dots "Checking for update: ${remotelocation}"
6774
# Update has been found or force update.
68-
if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
75+
if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
6976
# Create update lockfile.
7077
date '+%s' > "${lockdir:?}/update.lock"
7178
fn_print_ok_nl "Checking for update: ${remotelocation}"
7279
fn_print "\n"
7380
fn_print_nl "${bold}${underline}Update${default} available"
7481
fn_print_nl "* Local build: ${red}${localbuild}${default}"
75-
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
82+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
7683
if [ -n "${branch}" ]; then
7784
fn_print_nl "* Branch: ${branch}"
7885
fi
@@ -81,18 +88,20 @@ fn_update_compare() {
8188
fn_print_nl "* apiurl: ${apiurl}"
8289
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
8390
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
84-
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
91+
fn_print_nl "* remotebuild: ${remotebuild}"
8592
fi
8693
fn_print "\n"
8794
fn_script_log_info "Update available"
8895
fn_script_log_info "Local build: ${localbuild} ${factorioarch}"
89-
fn_script_log_info "Remote build: ${remotebuildversion} ${factorioarch}"
96+
fn_script_log_info "Remote build: ${remotebuild} ${factorioarch}"
9097
if [ -n "${branch}" ]; then
9198
fn_script_log_info "Branch: ${branch}"
9299
fi
93-
fn_script_log_info "${localbuild} > ${remotebuildversion}"
100+
fn_script_log_info "${localbuild} > ${remotebuild}"
94101

95102
if [ "${commandname}" == "UPDATE" ]; then
103+
# Keep track of the build before updating for alert purposes.
104+
previousbuild="${localbuild}"
96105
date +%s > "${lockdir:?}/last-updated.lock"
97106
unset updateonstart
98107
check_status.sh
@@ -120,6 +129,23 @@ fn_update_compare() {
120129
command_start.sh
121130
fn_firstcommand_reset
122131
fi
132+
# Refresh local build value after update (silent) so alerts show new version.
133+
fn_update_localbuild silent
134+
# Verify the update applied correctly unless forced update to same version.
135+
if [ "${localbuild}" != "${remotebuild}" ]; then
136+
# If forced update and version unchanged treat as acceptable; otherwise failure.
137+
if [ "${forceupdate}" != "1" ] || [ "${previousbuild}" = "${localbuild}" ]; then
138+
fn_script_log_error "Update verification failed: expected ${remotebuild}, got ${localbuild}"
139+
fn_print_fail_nl "Update verification failed: expected ${remotebuild}, got ${localbuild}"
140+
updatefailureexpected="${remotebuild}"
141+
updatefailuregot="${localbuild}"
142+
alert="update-failed"
143+
alert.sh
144+
core_exit.sh
145+
fi
146+
else
147+
fn_script_log_pass "Update verification success: ${previousbuild} -> ${localbuild}"
148+
fi
123149
unset exitbypass
124150
alert="update"
125151
elif [ "${commandname}" == "CHECK-UPDATE" ]; then
@@ -131,14 +157,14 @@ fn_update_compare() {
131157
fn_print "\n"
132158
fn_print_nl "${bold}${underline}No update${default} available"
133159
fn_print_nl "* Local build: ${green}${localbuild}${default}"
134-
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
160+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
135161
if [ -n "${branch}" ]; then
136162
fn_print_nl "* Branch: ${branch}"
137163
fi
138164
fn_print "\n"
139165
fn_script_log_info "No update available"
140166
fn_script_log_info "Local build: ${localbuild} ${factorioarch}"
141-
fn_script_log_info "Remote build: ${remotebuildversion} ${factorioarch}"
167+
fn_script_log_info "Remote build: ${remotebuild} ${factorioarch}"
142168
if [ -n "${branch}" ]; then
143169
fn_script_log_info "Branch: ${branch}"
144170
fi
@@ -147,7 +173,7 @@ fn_update_compare() {
147173
fn_print_nl "* apiurl: ${apiurl}"
148174
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
149175
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
150-
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
176+
fn_print_nl "* remotebuild: ${remotebuild}"
151177
fi
152178
fi
153179
}

lgsm/modules/update_jk2.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ fn_update_remotebuild() {
3636
remotebuildresponse=$(curl -s "${apiurl}")
3737
remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("dedicated.zip")) | .name')
3838
remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("dedicated.zip")) | .browser_download_url')
39-
remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
39+
remotebuild=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
4040

4141
if [ "${firstcommandname}" != "INSTALL" ]; then
4242
fn_print_dots "Checking remote build: ${remotelocation}"
43-
# Checks if remotebuildversion variable has been set.
44-
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
43+
# Checks if remotebuild variable has been set.
44+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
4545
fn_print_fail "Checking remote build: ${remotelocation}"
4646
fn_script_log_fail "Checking remote build"
4747
core_exit.sh
@@ -51,7 +51,7 @@ fn_update_remotebuild() {
5151
fi
5252
else
5353
# Checks if remotebuild variable has been set.
54-
if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
54+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
5555
fn_print_failure "Unable to get remote build"
5656
fn_script_log_fail "Unable to get remote build"
5757
core_exit.sh
@@ -62,14 +62,14 @@ fn_update_remotebuild() {
6262
fn_update_compare() {
6363
fn_print_dots "Checking for update: ${remotelocation}"
6464
# Update has been found or force update.
65-
if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
65+
if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
6666
# Create update lockfile.
6767
date '+%s' > "${lockdir:?}/update.lock"
6868
fn_print_ok_nl "Checking for update: ${remotelocation}"
6969
fn_print "\n"
7070
fn_print_nl "${bold}${underline}Update${default} available"
7171
fn_print_nl "* Local build: ${red}${localbuild}${default}"
72-
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
72+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
7373
if [ -n "${branch}" ]; then
7474
fn_print_nl "* Branch: ${branch}"
7575
fi
@@ -78,16 +78,16 @@ fn_update_compare() {
7878
fn_print_nl "* apiurl: ${apiurl}"
7979
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
8080
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
81-
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
81+
fn_print_nl "* remotebuild: ${remotebuild}"
8282
fi
8383
fn_print "\n"
8484
fn_script_log_info "Update available"
8585
fn_script_log_info "Local build: ${localbuild}"
86-
fn_script_log_info "Remote build: ${remotebuildversion}"
86+
fn_script_log_info "Remote build: ${remotebuild}"
8787
if [ -n "${branch}" ]; then
8888
fn_script_log_info "Branch: ${branch}"
8989
fi
90-
fn_script_log_info "${localbuild} > ${remotebuildversion}"
90+
fn_script_log_info "${localbuild} > ${remotebuild}"
9191

9292
if [ "${commandname}" == "UPDATE" ]; then
9393
date +%s > "${lockdir:?}/last-updated.lock"
@@ -128,14 +128,14 @@ fn_update_compare() {
128128
fn_print "\n"
129129
fn_print_nl "${bold}${underline}No update${default} available"
130130
fn_print_nl "* Local build: ${green}${localbuild}${default}"
131-
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
131+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
132132
if [ -n "${branch}" ]; then
133133
fn_print_nl "* Branch: ${branch}"
134134
fi
135135
fn_print "\n"
136136
fn_script_log_info "No update available"
137137
fn_script_log_info "Local build: ${localbuild}"
138-
fn_script_log_info "Remote build: ${remotebuildversion}"
138+
fn_script_log_info "Remote build: ${remotebuild}"
139139
if [ -n "${branch}" ]; then
140140
fn_script_log_info "Branch: ${branch}"
141141
fi
@@ -144,7 +144,7 @@ fn_update_compare() {
144144
fn_print_nl "* apiurl: ${apiurl}"
145145
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
146146
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
147-
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
147+
fn_print_nl "* remotebuild: ${remotebuild}"
148148
fi
149149
fi
150150
}

0 commit comments

Comments
 (0)