Skip to content

Commit e86848c

Browse files
authored
feat: update refactor (#4146)
* feat(ut99): add oldunreal update functionality * non-steam update refactor * chore: flipping exit code if statements Must have consistancy XD * rename variables * feat(ut99): now supports native x64 * extracts will now fail if files doesnt exist * localbuild fix * a * fix: exit code bug * improve progress bar * add extractsrc and extractdest to deal with specific dir extracts * update ts3 extract * update * paper REFACTOR * mta a * fix(mta): prevent default resources exit from installer * streamline mcserver * mcb * jk2 * fixes * correct directory extract for factorio * mcb remove non printable characters * codacy
1 parent c957b2a commit e86848c

27 files changed

+1030
-852
lines changed

lgsm/config-default/config-lgsm/ut99server/_default.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ glibc="2.1"
145145
# Edit with care
146146

147147
## Game Server Directories
148-
systemdir="${serverfiles}/System"
148+
systemdir="${serverfiles}/System64"
149149
executabledir="${systemdir}"
150150
executable="./ucc-bin"
151151
servercfgdir="${systemdir}"

lgsm/functions/alert.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn_alert_update() {
6060
alertemoji="🎮"
6161
alertsound="1"
6262
alerturl="not enabled"
63-
alertbody="${gamename} received update"
63+
alertbody="${gamename} received update: ${remotebuildversion}"
6464
}
6565

6666
fn_alert_check_update() {
@@ -69,7 +69,7 @@ fn_alert_check_update() {
6969
alertemoji="🎮"
7070
alertsound="1"
7171
alerturl="not enabled"
72-
alertbody="${gamename} update available"
72+
alertbody="${gamename} update available: ${remotebuildversion}"
7373
}
7474

7575
fn_alert_permissions() {

lgsm/functions/command_backup.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,17 @@ fn_backup_migrate_olddir() {
9999
fn_script_log_info "${rootdir}/backups > ${backupdir}"
100100
mv "${rootdir}/backups/"* "${backupdir}" 2> /dev/null
101101
exitcode=$?
102-
if [ "${exitcode}" -eq 0 ]; then
102+
if [ "${exitcode}" == 0 ]; then
103103
rmdir "${rootdir}/backups" 2> /dev/null
104104
exitcode=$?
105105
fi
106-
if [ "${exitcode}" -eq 0 ]; then
107-
fn_print_ok_nl "Backup directory is being migrated"
108-
fn_script_log_pass "Backup directory is being migrated"
109-
else
106+
if [ "${exitcode}" != 0 ]; then
110107
fn_print_error_nl "Backup directory is being migrated"
111108
fn_script_log_error "Backup directory is being migrated"
109+
else
110+
111+
fn_print_ok_nl "Backup directory is being migrated"
112+
fn_script_log_pass "Backup directory is being migrated"
112113
fi
113114
fi
114115
fi

lgsm/functions/command_check_update.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@ fn_print_dots ""
1414
check.sh
1515
core_logs.sh
1616

17-
if [ "${appid}" ]; then
18-
core_steamcmd.sh
19-
20-
check_steamcmd.sh
21-
22-
fn_update_steamcmd_localbuild
23-
fn_update_steamcmd_remotebuild
24-
fn_update_steamcmd_compare
25-
elif [ "${shortname}" == "ts3" ]; then
17+
if [ "${shortname}" == "ts3" ]; then
2618
update_ts3.sh
19+
elif [ "${shortname}" == "mc" ]; then
20+
update_minecraft.sh
21+
elif [ "${shortname}" == "mcb" ]; then
22+
update_minecraft_bedrock.sh
23+
elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then
24+
update_papermc.sh
25+
elif [ "${shortname}" == "fctr" ]; then
26+
update_factorio.sh
27+
elif [ "${shortname}" == "mta" ]; then
28+
update_mta.sh
29+
elif [ "${shortname}" == "jk2" ]; then
30+
update_jediknight2.sh
31+
elif [ "${shortname}" == "vints" ]; then
32+
update_vintagestory.sh
33+
elif [ "${shortname}" == "ut99" ]; then
34+
update_ut99.sh
35+
else
36+
update_steamcmd.sh
2737
fi
2838

2939
core_exit.sh

lgsm/functions/command_install_resources_mta.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn_firstcommand_set
1212

1313
fn_install_resources() {
1414
echo -e ""
15-
echo -e "Installing Default Resources"
15+
echo -e "${lightyellow}Installing Default Resources${default}"
1616
echo -e "================================="
1717
fn_fetch_file "http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip" "" "" "" "${tmpdir}" "mtasa-resources-latest.zip" "nochmodx" "norun" "noforce" "nohash"
1818
fn_dl_extract "${tmpdir}" "mtasa-resources-latest.zip" "${resourcesdir}"
@@ -30,5 +30,3 @@ else
3030
fn_print_warning_nl "Default resources are not installed when using ./${selfname} auto-install."
3131
fn_print_information_nl "To install default resources use ./${selfname} install"
3232
fi
33-
34-
core_exit.sh

lgsm/functions/command_mods_update.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ fn_remove_cfg_files() {
2727
filetopreserve=$(echo -e "${modkeepfiles}" | awk -F ';' -v x=${preservefilesindex} '{ print $x }')
2828
echo -e " * serverfiles/${filetopreserve}"
2929
# If it matches an existing file that have been extracted delete the file.
30-
if [ -f "${extractdir}/${filetopreserve}" ] || [ -d "${extractdir}/${filetopreserve}" ]; then
31-
rm -r "${extractdir:?}/${filetopreserve}"
30+
if [ -f "${extractdest}/${filetopreserve}" ] || [ -d "${extractdest}/${filetopreserve}" ]; then
31+
rm -r "${extractdest:?}/${filetopreserve}"
3232
# Write the file path in a tmp file, to rebuild a full file list as it is rebuilt upon update.
3333
if [ ! -f "${modsdir}/.removedfiles.tmp" ]; then
3434
touch "${modsdir}/.removedfiles.tmp"

lgsm/functions/command_update.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ elif [ "${shortname}" == "jk2" ]; then
3131
update_jediknight2.sh
3232
elif [ "${shortname}" == "vints" ]; then
3333
update_vintagestory.sh
34+
elif [ "${shortname}" == "ut99" ]; then
35+
update_ut99.sh
3436
else
3537
update_steamcmd.sh
3638
fi

lgsm/functions/core_dl.sh

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# hash: Optional, set an hash sum and will compare it against the file.
1515
#
1616
# Downloads can be defined in code like so:
17-
# fn_fetch_file "${remote_fileurl}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${hash}"
18-
# fn_fetch_file "http://example.com/file.tar.bz2" "/some/dir" "file.tar.bz2" "chmodx" "run" "forcedl" "10cd7353aa9d758a075c600a6dd193fd"
17+
# fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${hash}"
18+
# fn_fetch_file "http://example.com/file.tar.bz2" "http://example.com/file2.tar.bz2" "file.tar.bz2" "file2.tar.bz2" "/some/dir" "file.tar.bz2" "chmodx" "run" "forcedl" "10cd7353aa9d758a075c600a6dd193fd"
1919

2020
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
2121

@@ -124,7 +124,7 @@ fn_dl_steamcmd() {
124124
echo -en "Please provide content log to LinuxGSM developers https://linuxgsm.com/steamcmd-error"
125125
fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Unknown error occured"
126126
fi
127-
elif [ "${exitcode}" != "0" ]; then
127+
elif [ "${exitcode}" != 0 ]; then
128128
fn_print_error2_nl "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
129129
fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
130130
else
@@ -146,12 +146,12 @@ fn_clear_tmp() {
146146
if [ -d "${tmpdir}" ]; then
147147
rm -rf "${tmpdir:?}/"*
148148
local exitcode=$?
149-
if [ "${exitcode}" == 0 ]; then
150-
fn_print_ok_eol_nl
151-
fn_script_log_pass "clearing LinuxGSM tmp directory"
152-
else
149+
if [ "${exitcode}" != 0 ]; then
153150
fn_print_error_eol_nl
154151
fn_script_log_error "clearing LinuxGSM tmp directory"
152+
else
153+
fn_print_ok_eol_nl
154+
fn_script_log_pass "clearing LinuxGSM tmp directory"
155155
fi
156156
fi
157157
}
@@ -202,39 +202,64 @@ fn_dl_hash() {
202202

203203
# Extracts bzip2, gzip or zip files.
204204
# Extracts can be defined in code like so:
205-
# fn_dl_extract "${local_filedir}" "${local_filename}" "${extractdir}"
205+
# fn_dl_extract "${local_filedir}" "${local_filename}" "${extractdest}" "${extractsrc}"
206206
# fn_dl_extract "/home/gameserver/lgsm/tmp" "file.tar.bz2" "/home/gamserver/serverfiles"
207207
fn_dl_extract() {
208208
local_filedir="${1}"
209209
local_filename="${2}"
210-
extractdir="${3}"
210+
extractdest="${3}"
211+
extractsrc="${4}"
211212
# Extracts archives.
212213
echo -en "extracting ${local_filename}..."
213-
mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
214-
if [ ! -d "${extractdir}" ]; then
215-
mkdir "${extractdir}"
214+
215+
if [ ! -d "${extractdest}" ]; then
216+
mkdir "${extractdest}"
217+
fi
218+
if [ ! -f "${local_filedir}/${local_filename}" ]; then
219+
fn_print_fail_eol_nl
220+
echo -en "file ${local_filedir}/${local_filename} not found"
221+
fn_script_log_fatal "Extracting ${local_filename}"
222+
fn_script_log_fatal "File ${local_filedir}/${local_filename} not found"
223+
core_exit.sh
216224
fi
225+
mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
217226
if [ "${mime}" == "application/gzip" ] || [ "${mime}" == "application/x-gzip" ]; then
218-
extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdir}")
227+
if [ -n "${extractsrc}" ]; then
228+
extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
229+
else
230+
extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdest}")
231+
fi
219232
elif [ "${mime}" == "application/x-bzip2" ]; then
220-
extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdir}")
233+
if [ -n "${extractsrc}" ]; then
234+
extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
235+
else
236+
extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdest}")
237+
fi
221238
elif [ "${mime}" == "application/x-xz" ]; then
222-
extractcmd=$(tar -xf "${local_filedir}/${local_filename}" -C "${extractdir}")
239+
if [ -n "${extractsrc}" ]; then
240+
extractcmd=$(tar -Jxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
241+
else
242+
extractcmd=$(tar -Jxf "${local_filedir}/${local_filename}" -C "${extractdest}")
243+
fi
223244
elif [ "${mime}" == "application/zip" ]; then
224-
extractcmd=$(unzip -qo -d "${extractdir}" "${local_filedir}/${local_filename}")
245+
if [ -n "${extractsrc}" ]; then
246+
extractcmd=$(unzip -qoj -d "${extractdest}" "${local_filedir}/${local_filename}" "${extractsrc}"/*)
247+
else
248+
extractcmd=$(unzip -qo -d "${extractdest}" "${local_filedir}/${local_filename}")
249+
fi
225250
fi
226251
local exitcode=$?
227252
if [ "${exitcode}" != 0 ]; then
228253
fn_print_fail_eol_nl
229-
fn_script_log_fatal "Extracting download"
254+
fn_script_log_fatal "Extracting ${local_filename}"
230255
if [ -f "${lgsmlog}" ]; then
231256
echo -e "${extractcmd}" >> "${lgsmlog}"
232257
fi
233258
echo -e "${extractcmd}"
234259
core_exit.sh
235260
else
236261
fn_print_ok_eol_nl
237-
fn_script_log_pass "Extracting download"
262+
fn_script_log_pass "Extracting ${local_filename}"
238263
fi
239264
}
240265

@@ -360,21 +385,21 @@ fn_fetch_file() {
360385
trap fn_fetch_trap INT
361386
# Larger files show a progress bar.
362387
if [ "${local_filename##*.}" == "bz2" ] || [ "${local_filename##*.}" == "gz" ] || [ "${local_filename##*.}" == "zip" ] || [ "${local_filename##*.}" == "jar" ] || [ "${local_filename##*.}" == "xz" ]; then
363-
echo -en "downloading ${local_filename}..."
388+
echo -e "downloading ${local_filename}..."
364389
fn_sleep_time
365-
echo -en "\033[1K"
366390
curlcmd=$(curl --connect-timeout 10 --progress-bar --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
391+
local exitcode=$?
367392
echo -en "downloading ${local_filename}..."
368393
else
394+
curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
395+
local exitcode=$?
369396
echo -en "fetching ${fileurl_name} ${local_filename}...\c"
370-
curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}" 2>&1)
371397
fi
372-
local exitcode=$?
373398

374399
# Download will fail if downloads a html file.
375400
if [ -f "${local_filedir}/${local_filename}" ]; then
376-
if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
377-
rm -f "${local_filedir:?}/${local_filename:?}"
401+
if head -n 1 "${local_filedir}/${local_filename}" | grep -q "DOCTYPE"; then
402+
rm "${local_filedir:?}/${local_filename:?}"
378403
local exitcode=2
379404
fi
380405
fi
@@ -384,22 +409,21 @@ fn_fetch_file() {
384409
if [ ${counter} -ge 2 ]; then
385410
fn_print_fail_eol_nl
386411
if [ -f "${lgsmlog}" ]; then
387-
fn_script_log_fatal "Downloading ${local_filename}"
412+
fn_script_log_fatal "Downloading ${local_filename}..."
388413
fn_script_log_fatal "${fileurl}"
389414
fi
390415
core_exit.sh
391416
else
392417
fn_print_error_eol_nl
393418
if [ -f "${lgsmlog}" ]; then
394-
fn_script_log_error "Downloading ${local_filename}"
419+
fn_script_log_error "Downloading ${local_filename}..."
395420
fn_script_log_error "${fileurl}"
396421
fi
397422
fi
398423
else
399-
fn_print_ok_eol
400-
echo -en "\033[2K\\r"
424+
fn_print_ok_eol_nl
401425
if [ -f "${lgsmlog}" ]; then
402-
fn_script_log_pass "Downloading ${local_filename}"
426+
fn_script_log_pass "Downloading ${local_filename}..."
403427
fi
404428

405429
# Make file executable if chmodx is set.

lgsm/functions/core_exit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fi
2525

2626
if [ "${exitbypass}" ]; then
2727
unset exitbypass
28-
elif [ "${exitcode}" ] && [ "${exitcode}" != "0" ]; then
28+
elif [ "${exitcode}" != "0" ]; then
2929
# List LinuxGSM version in logs
3030
fn_script_log_info "LinuxGSM version: ${version}"
3131
if [ "${exitcode}" == "1" ]; then

lgsm/functions/core_functions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@ update_vintagestory.sh() {
680680
fn_fetch_function
681681
}
682682

683+
update_ut99.sh() {
684+
functionfile="${FUNCNAME[0]}"
685+
fn_fetch_function
686+
}
687+
683688
fn_update_functions.sh() {
684689
functionfile="${FUNCNAME[0]}"
685690
fn_fetch_function

0 commit comments

Comments
 (0)