Skip to content

Commit cfa873c

Browse files
committed
feat: refactor update comparison output for consistency and clarity
- Replaced direct echo statements with fn_print functions for uniformity in output formatting across multiple update scripts. - Ensured lockfile creation uses the correct syntax for variable expansion. - Moved lock file to the same location to ensure monitor doesnt reboot at the wrong time - Updated remote build information display to enhance readability and maintain consistency in logging. - Removed unnecessary echo commands to streamline the output process.
1 parent e2397f1 commit cfa873c

File tree

13 files changed

+236
-288
lines changed

13 files changed

+236
-288
lines changed

.shellcheckrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
disable=SC2154
1+
disable=SC2154,SC2034

lgsm/modules/check_last_update.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
1111
if [ -f "${lockdir}/${selfname}-last-started.lock" ]; then
1212
laststart=$(cat "${lockdir}/${selfname}-last-started.lock")
1313
fi
14+
1415
if [ -f "${lockdir}/last-updated.lock" ]; then
1516
lastupdate=$(cat "${lockdir}/last-updated.lock")
1617
fi

lgsm/modules/core_steamcmd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ fn_update_steamcmd_compare() {
239239
fn_script_log_info "${localbuild} > ${remotebuildversion}"
240240

241241
if [ "${commandname}" == "UPDATE" ]; then
242+
date +%s > "${lockdir:?}/last-updated.lock"
242243
unset updateonstart
243244
check_status.sh
244245
# If server stopped.
@@ -257,7 +258,6 @@ fn_update_steamcmd_compare() {
257258
fn_firstcommand_reset
258259
fi
259260
unset exitbypass
260-
date +%s > "${lockdir:?}/last-updated.lock"
261261
alert="update"
262262
elif [ "${commandname}" == "CHECK-UPDATE" ]; then
263263
alert="check-update"

lgsm/modules/update_fctr.sh

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ fn_update_compare() {
6969
# Create update lockfile.
7070
date '+%s' > "${lockdir:?}/update.lock"
7171
fn_print_ok_nl "Checking for update: ${remotelocation}"
72-
echo -en "\n"
73-
echo -e "Update available"
74-
echo -e "* Local build: ${red}${localbuild} ${factorioarch}${default}"
75-
echo -e "* Remote build: ${green}${remotebuildversion} ${factorioarch}${default}"
72+
fn_print "\n"
73+
fn_print_nl "${bold}${underline}Update${default} available"
74+
fn_print_nl "* Local build: ${red}${localbuild}${default}"
75+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
7676
if [ -n "${branch}" ]; then
77-
echo -e "* Branch: ${branch}"
77+
fn_print_nl "* Branch: ${branch}"
7878
fi
7979
if [ -f "${rootdir}/.dev-debug" ]; then
80-
echo -e "Remote build info"
81-
echo -e "* apiurl: ${apiurl}"
82-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
83-
echo -e "* remotebuildurl: ${remotebuildurl}"
84-
echo -e "* remotebuildversion: ${remotebuildversion}"
80+
fn_print_nl "Remote build info"
81+
fn_print_nl "* apiurl: ${apiurl}"
82+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
83+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
84+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
8585
fi
86-
echo -en "\n"
86+
fn_print "\n"
8787
fn_script_log_info "Update available"
8888
fn_script_log_info "Local build: ${localbuild} ${factorioarch}"
8989
fn_script_log_info "Remote build: ${remotebuildversion} ${factorioarch}"
@@ -93,7 +93,7 @@ fn_update_compare() {
9393
fn_script_log_info "${localbuild} > ${remotebuildversion}"
9494

9595
if [ "${commandname}" == "UPDATE" ]; then
96-
date +%s > "${lockdir}/last-updated.lock"
96+
date +%s > "${lockdir:?}/last-updated.lock"
9797
unset updateonstart
9898
check_status.sh
9999
# If server stopped.
@@ -128,26 +128,26 @@ fn_update_compare() {
128128
alert.sh
129129
else
130130
fn_print_ok_nl "Checking for update: ${remotelocation}"
131-
echo -en "\n"
132-
echo -e "No update available"
133-
echo -e "* Local build: ${green}${localbuild} ${factorioarch}${default}"
134-
echo -e "* Remote build: ${green}${remotebuildversion} ${factorioarch}${default}"
131+
fn_print "\n"
132+
fn_print_nl "${bold}${underline}No update${default} available"
133+
fn_print_nl "* Local build: ${green}${localbuild}${default}"
134+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
135135
if [ -n "${branch}" ]; then
136-
echo -e "* Branch: ${branch}"
136+
fn_print_nl "* Branch: ${branch}"
137137
fi
138-
echo -en "\n"
138+
fn_print "\n"
139139
fn_script_log_info "No update available"
140140
fn_script_log_info "Local build: ${localbuild} ${factorioarch}"
141141
fn_script_log_info "Remote build: ${remotebuildversion} ${factorioarch}"
142142
if [ -n "${branch}" ]; then
143143
fn_script_log_info "Branch: ${branch}"
144144
fi
145145
if [ -f "${rootdir}/.dev-debug" ]; then
146-
echo -e "Remote build info"
147-
echo -e "* apiurl: ${apiurl}"
148-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
149-
echo -e "* remotebuildurl: ${remotebuildurl}"
150-
echo -e "* remotebuildversion: ${remotebuildversion}"
146+
fn_print_nl "Remote build info"
147+
fn_print_nl "* apiurl: ${apiurl}"
148+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
149+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
150+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
151151
fi
152152
fi
153153
}

lgsm/modules/update_jk2.sh

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@ fn_update_compare() {
6666
# Create update lockfile.
6767
date '+%s' > "${lockdir:?}/update.lock"
6868
fn_print_ok_nl "Checking for update: ${remotelocation}"
69-
echo -en "\n"
70-
echo -e "Update available"
71-
echo -e "* Local build: ${red}${localbuild}${default}"
72-
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
69+
fn_print "\n"
70+
fn_print_nl "${bold}${underline}Update${default} available"
71+
fn_print_nl "* Local build: ${red}${localbuild}${default}"
72+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
7373
if [ -n "${branch}" ]; then
74-
echo -e "* Branch: ${branch}"
74+
fn_print_nl "* Branch: ${branch}"
7575
fi
7676
if [ -f "${rootdir}/.dev-debug" ]; then
77-
echo -e "Remote build info"
78-
echo -e "* apiurl: ${apiurl}"
79-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
80-
echo -e "* remotebuildurl: ${remotebuildurl}"
81-
echo -e "* remotebuildversion: ${remotebuildversion}"
77+
fn_print_nl "Remote build info"
78+
fn_print_nl "* apiurl: ${apiurl}"
79+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
80+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
81+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
8282
fi
83-
echo -en "\n"
83+
fn_print "\n"
8484
fn_script_log_info "Update available"
8585
fn_script_log_info "Local build: ${localbuild}"
8686
fn_script_log_info "Remote build: ${remotebuildversion}"
@@ -90,6 +90,7 @@ fn_update_compare() {
9090
fn_script_log_info "${localbuild} > ${remotebuildversion}"
9191

9292
if [ "${commandname}" == "UPDATE" ]; then
93+
date +%s > "${lockdir:?}/last-updated.lock"
9394
unset updateonstart
9495
check_status.sh
9596
# If server stopped.
@@ -117,46 +118,39 @@ fn_update_compare() {
117118
fn_firstcommand_reset
118119
fi
119120
unset exitbypass
120-
date +%s > "${lockdir}/last-updated.lock"
121121
alert="update"
122122
elif [ "${commandname}" == "CHECK-UPDATE" ]; then
123123
alert="check-update"
124124
fi
125125
alert.sh
126126
else
127127
fn_print_ok_nl "Checking for update: ${remotelocation}"
128-
echo -en "\n"
129-
echo -e "No update available"
130-
echo -e "* Local build: ${green}${localbuild}${default}"
131-
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
128+
fn_print "\n"
129+
fn_print_nl "${bold}${underline}No update${default} available"
130+
fn_print_nl "* Local build: ${green}${localbuild}${default}"
131+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
132132
if [ -n "${branch}" ]; then
133-
echo -e "* Branch: ${branch}"
133+
fn_print_nl "* Branch: ${branch}"
134134
fi
135-
echo -en "\n"
135+
fn_print "\n"
136136
fn_script_log_info "No update available"
137137
fn_script_log_info "Local build: ${localbuild}"
138138
fn_script_log_info "Remote build: ${remotebuildversion}"
139139
if [ -n "${branch}" ]; then
140140
fn_script_log_info "Branch: ${branch}"
141141
fi
142142
if [ -f "${rootdir}/.dev-debug" ]; then
143-
echo -e "Remote build info"
144-
echo -e "* apiurl: ${apiurl}"
145-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
146-
echo -e "* remotebuildurl: ${remotebuildurl}"
147-
echo -e "* remotebuildversion: ${remotebuildversion}"
143+
fn_print_nl "Remote build info"
144+
fn_print_nl "* apiurl: ${apiurl}"
145+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
146+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
147+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
148148
fi
149149
fi
150150
}
151151

152152
# The location where the builds are checked and downloaded.
153-
remotelocation="github.com"
154-
155-
if [ ! "$(command -v jq 2> /dev/null)" ]; then
156-
fn_print_fail_nl "jq is not installed"
157-
fn_script_log_fail "jq is not installed"
158-
core_exit.sh
159-
fi
153+
remotelocation="factorio.com"
160154

161155
if [ "${firstcommandname}" == "INSTALL" ]; then
162156
fn_update_remotebuild

lgsm/modules/update_mc.sh

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ fn_update_compare() {
8181
# Create update lockfile.
8282
date '+%s' > "${lockdir:?}/update.lock"
8383
fn_print_ok_nl "Checking for update: ${remotelocation}"
84-
echo -en "\n"
85-
echo -e "Update available"
86-
echo -e "* Local build: ${red}${localbuild}${default}"
87-
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
84+
fn_print "\n"
85+
fn_print_nl "${bold}${underline}Update${default} available"
86+
fn_print_nl "* Local build: ${red}${localbuild}${default}"
87+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
8888
if [ -n "${branch}" ]; then
89-
echo -e "* Branch: ${branch}"
89+
fn_print_nl "* Branch: ${branch}"
9090
fi
9191
if [ -f "${rootdir}/.dev-debug" ]; then
92-
echo -e "Remote build info"
93-
echo -e "* apiurl: ${apiurl}"
94-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
95-
echo -e "* remotebuildurl: ${remotebuildurl}"
96-
echo -e "* remotebuildversion: ${remotebuildversion}"
92+
fn_print_nl "Remote build info"
93+
fn_print_nl "* apiurl: ${apiurl}"
94+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
95+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
96+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
9797
fi
98-
echo -en "\n"
98+
fn_print "\n"
9999
fn_script_log_info "Update available"
100100
fn_script_log_info "Local build: ${localbuild}"
101101
fn_script_log_info "Remote build: ${remotebuildversion}"
@@ -105,7 +105,7 @@ fn_update_compare() {
105105
fn_script_log_info "${localbuild} > ${remotebuildversion}"
106106

107107
if [ "${commandname}" == "UPDATE" ]; then
108-
date +%s > "${lockdir}/last-updated.lock"
108+
date +%s > "${lockdir:?}/last-updated.lock"
109109
unset updateonstart
110110
check_status.sh
111111
# If server stopped.
@@ -140,39 +140,33 @@ fn_update_compare() {
140140
alert.sh
141141
else
142142
fn_print_ok_nl "Checking for update: ${remotelocation}"
143-
echo -en "\n"
144-
echo -e "No update available"
145-
echo -e "* Local build: ${green}${localbuild}${default}"
146-
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
143+
fn_print "\n"
144+
fn_print_nl "${bold}${underline}No update${default} available"
145+
fn_print_nl "* Local build: ${green}${localbuild}${default}"
146+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
147147
if [ -n "${branch}" ]; then
148-
echo -e "* Branch: ${branch}"
148+
fn_print_nl "* Branch: ${branch}"
149149
fi
150-
echo -en "\n"
150+
fn_print "\n"
151151
fn_script_log_info "No update available"
152152
fn_script_log_info "Local build: ${localbuild}"
153153
fn_script_log_info "Remote build: ${remotebuildversion}"
154154
if [ -n "${branch}" ]; then
155155
fn_script_log_info "Branch: ${branch}"
156156
fi
157157
if [ -f "${rootdir}/.dev-debug" ]; then
158-
echo -e "Remote build info"
159-
echo -e "* apiurl: ${apiurl}"
160-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
161-
echo -e "* remotebuildurl: ${remotebuildurl}"
162-
echo -e "* remotebuildversion: ${remotebuildversion}"
158+
fn_print_nl "Remote build info"
159+
fn_print_nl "* apiurl: ${apiurl}"
160+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
161+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
162+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
163163
fi
164164
fi
165165
}
166166

167167
# The location where the builds are checked and downloaded.
168168
remotelocation="mojang.com"
169169

170-
if [ ! "$(command -v jq 2> /dev/null)" ]; then
171-
fn_print_fail_nl "jq is not installed"
172-
fn_script_log_fail "jq is not installed"
173-
core_exit.sh
174-
fi
175-
176170
if [ "${firstcommandname}" == "INSTALL" ]; then
177171
fn_update_remotebuild
178172
fn_update_dl

lgsm/modules/update_mcb.sh

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ fn_update_compare() {
9292
# Create update lockfile.
9393
date '+%s' > "${lockdir:?}/update.lock"
9494
fn_print_ok_nl "Checking for update: ${remotelocation}"
95-
echo -en "\n"
96-
echo -e "Update available"
97-
echo -e "* Local build: ${red}${localbuild}${default}"
98-
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
95+
fn_print "\n"
96+
fn_print_nl "${bold}${underline}Update${default} available"
97+
fn_print_nl "* Local build: ${red}${localbuild}${default}"
98+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
9999
if [ -n "${branch}" ]; then
100-
echo -e "* Branch: ${branch}"
100+
fn_print_nl "* Branch: ${branch}"
101101
fi
102102
if [ -f "${rootdir}/.dev-debug" ]; then
103-
echo -e "Remote build info"
104-
echo -e "* apiurl: ${apiurl}"
105-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
106-
echo -e "* remotebuildurl: ${remotebuildurl}"
107-
echo -e "* remotebuildversion: ${remotebuildversion}"
103+
fn_print_nl "Remote build info"
104+
fn_print_nl "* apiurl: ${apiurl}"
105+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
106+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
107+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
108108
fi
109-
echo -en "\n"
109+
fn_print "\n"
110110
fn_script_log_info "Update available"
111111
fn_script_log_info "Local build: ${localbuild}"
112112
fn_script_log_info "Remote build: ${remotebuildversion}"
@@ -116,7 +116,7 @@ fn_update_compare() {
116116
fn_script_log_info "${localbuild} > ${remotebuildversion}"
117117

118118
if [ "${commandname}" == "UPDATE" ]; then
119-
date +%s > "${lockdir}/last-updated.lock"
119+
date +%s > "${lockdir:?}/last-updated.lock"
120120
unset updateonstart
121121
check_status.sh
122122
# If server stopped.
@@ -151,39 +151,33 @@ fn_update_compare() {
151151
alert.sh
152152
else
153153
fn_print_ok_nl "Checking for update: ${remotelocation}"
154-
echo -en "\n"
155-
echo -e "No update available"
156-
echo -e "* Local build: ${green}${localbuild}${default}"
157-
echo -e "* Remote build: ${green}${remotebuildversion}${default}"
154+
fn_print "\n"
155+
fn_print_nl "${bold}${underline}No update${default} available"
156+
fn_print_nl "* Local build: ${green}${localbuild}${default}"
157+
fn_print_nl "* Remote build: ${green}${remotebuildversion}${default}"
158158
if [ -n "${branch}" ]; then
159-
echo -e "* Branch: ${branch}"
159+
fn_print_nl "* Branch: ${branch}"
160160
fi
161-
echo -en "\n"
161+
fn_print "\n"
162162
fn_script_log_info "No update available"
163163
fn_script_log_info "Local build: ${localbuild}"
164164
fn_script_log_info "Remote build: ${remotebuildversion}"
165165
if [ -n "${branch}" ]; then
166166
fn_script_log_info "Branch: ${branch}"
167167
fi
168168
if [ -f "${rootdir}/.dev-debug" ]; then
169-
echo -e "Remote build info"
170-
echo -e "* apiurl: ${apiurl}"
171-
echo -e "* remotebuildfilename: ${remotebuildfilename}"
172-
echo -e "* remotebuildurl: ${remotebuildurl}"
173-
echo -e "* remotebuildversion: ${remotebuildversion}"
169+
fn_print_nl "Remote build info"
170+
fn_print_nl "* apiurl: ${apiurl}"
171+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
172+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
173+
fn_print_nl "* remotebuildversion: ${remotebuildversion}"
174174
fi
175175
fi
176176
}
177177

178178
# The location where the builds are checked and downloaded.
179179
remotelocation="minecraft.net"
180180

181-
if [ ! "$(command -v jq 2> /dev/null)" ]; then
182-
fn_print_fail_nl "jq is not installed"
183-
fn_script_log_fail "jq is not installed"
184-
core_exit.sh
185-
fi
186-
187181
if [ "${firstcommandname}" == "INSTALL" ]; then
188182
fn_update_remotebuild
189183
fn_update_dl

0 commit comments

Comments
 (0)