@@ -10,25 +10,32 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1010fn_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
1717fn_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() {
6572fn_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}
0 commit comments