Skip to content

Commit 4714851

Browse files
dgibbs64Copilot
andauthored
feat(unreal): consolidate map compression scripts (#4805)
* fix(compress_unreal2_maps): streamline file removal and compression process * lint * feat(unreal): consolidate map compression scripts * Removed `compress_ut99_maps.sh` and integrated its functionality into `compress_unreal_maps.sh`. * Updated `core_getopt.sh` to reference the new unified compression script. * Cleaned up `core_modules.sh` by removing the obsolete function for `compress_ut99_maps.sh`. * Added `core_exit.sh` call to `install_ut2k4_key.sh` for consistent exit handling. * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * fix(compress_unreal_maps): correct array usage in file compression loop * Updated the loop to iterate over the `exts` array correctly using `"${exts[@]}"` instead of `${exts}`. * This change ensures proper handling of file extensions during the compression process. --------- Co-authored-by: Copilot <[email protected]>
1 parent 7cc48be commit 4714851

File tree

7 files changed

+86
-80
lines changed

7 files changed

+86
-80
lines changed

.shellcheckrc

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

lgsm/modules/compress_unreal2_maps.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# LinuxGSM compress_unreal_maps.sh module
3+
# Author: Daniel Gibbs
4+
# Contributors: https://linuxgsm.com/contrib
5+
# Website: https://linuxgsm.com
6+
# Description: Compresses unreal and unreal2 resources.
7+
8+
commandname="MAP-COMPRESSOR"
9+
commandaction="Compressing Maps"
10+
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
11+
fn_firstcommand_set
12+
13+
check.sh
14+
fn_print_header
15+
echo -e "Will compress all maps in:"
16+
echo -e ""
17+
pwd
18+
echo -e ""
19+
echo -e "Compressed maps saved to:"
20+
echo -e ""
21+
echo -e "${compressedmapsdir}"
22+
echo -e ""
23+
totalseconds=3
24+
for seconds in {3..1}; do
25+
fn_print_warn "map compression starting in: ${totalseconds}"
26+
totalseconds=$((totalseconds - 1))
27+
fn_sleep_time_1
28+
if [ "${seconds}" == "0" ]; then
29+
break
30+
fi
31+
done
32+
fn_print_nl
33+
mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
34+
35+
# List of extensions to compress
36+
exts=(ut2 kfm rom u ucl upl int utx uax ukx usx unr umx umod uzx)
37+
38+
# Remove old compressed files using find
39+
for ext in "${exts[@]}"; do
40+
mapfile -t oldfiles < <(find "${serverfiles}" -name "*.${ext}.uz2" -type f)
41+
if [ ${#oldfiles[@]} -gt 0 ]; then
42+
echo -e "found ${#oldfiles[@]} old compressed file(s) to remove for extension: ${ext}"
43+
fi
44+
for file in "${oldfiles[@]}"; do
45+
if rm -f "$file"; then
46+
echo -en "removing file [ ${italic}$(basename "$file")${default} ]\c"
47+
fn_print_ok_eol_nl
48+
else
49+
echo -en "removing file [ ${italic}$(basename "$file")${default} ]\c"
50+
fn_print_fail_eol_nl
51+
fi
52+
done
53+
done
54+
55+
cd "${systemdir}" || exit
56+
57+
# Find and compress files, then move .uz2 to compressedmapsdir
58+
for ext in "${exts[@]}"; do
59+
# Collect all files with the current extension into an array
60+
mapfile -t files < <(find "${serverfiles}" -name "*.${ext}" -type f)
61+
for file in "${files[@]}"; do
62+
echo -en "compressing file [ ${italic}$(basename "$file") -> $(basename "$file").uz2${default} ]\c"
63+
if ! ./ucc-bin compress "${file}" --nohomedir > /dev/null 2>&1; then
64+
fn_print_fail_eol_nl
65+
core_exit.sh
66+
else
67+
fn_print_ok_eol_nl
68+
fi
69+
70+
if ! mv -f "${file}.uz2" "${compressedmapsdir}" > /dev/null 2>&1; then
71+
echo -en "moving compressed file [ ${italic}$(basename "$file").uz2 -> ${compressedmapsdir}/$(basename "$file").uz2${default} ]\c"
72+
fn_print_fail_eol_nl
73+
core_exit.sh
74+
fi
75+
done
76+
done
77+
78+
fn_print_ok_nl "Compression complete: All compressed files moved to: ${compressedmapsdir}"
79+
80+
core_exit.sh

lgsm/modules/compress_ut99_maps.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

lgsm/modules/core_getopt.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ cmd_change_password=("pw;change-password" "command_ts3_server_pass.sh" "Change T
4242
cmd_install_default_resources=("ir;install-default-resources" "command_install_resources_mta.sh" "Install the MTA default resources.")
4343
cmd_fullwipe=("fw;full-wipe;wa;wipeall" "serverwipe=1; command_wipe.sh" "Reset the map and remove blueprint data.")
4444
cmd_mapwipe=("mw;map-wipe;w;wipe;wi" "mapwipe=1; command_wipe.sh" "Reset the map and keep blueprint data.")
45-
cmd_map_compressor_u99=("mc;map-compressor" "compress_ut99_maps.sh" "Compresses all ${gamename} server maps.")
46-
cmd_map_compressor_u2=("mc;map-compressor" "compress_unreal2_maps.sh" "Compresses all ${gamename} server maps.")
45+
cmd_map_compressor_unreal=("mc;map-compressor" "compress_unreal_maps.sh" "Compresses all ${gamename} server maps.")
4746
cmd_install_cdkey=("cd;server-cd-key" "install_ut2k4_key.sh" "Add your server cd key.")
4847
cmd_install_dst_token=("ct;cluster-token" "install_dst_token.sh" "Configure cluster token.")
4948
cmd_install_squad_license=("li;license" "install_squad_license.sh" "Add your Squad server license.")
@@ -113,13 +112,13 @@ fi
113112
# Unreal exclusive.
114113
if [ "${engine}" == "unreal2" ]; then
115114
if [ "${shortname}" == "ut2k4" ]; then
116-
currentopt+=("${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}")
115+
currentopt+=("${cmd_install_cdkey[@]}" "${cmd_map_compressor_unreal[@]}")
117116
else
118-
currentopt+=("${cmd_map_compressor_u2[@]}")
117+
currentopt+=("${cmd_map_compressor_unreal[@]}")
119118
fi
120119
fi
121120
if [ "${engine}" == "unreal" ]; then
122-
currentopt+=("${cmd_map_compressor_u99[@]}")
121+
currentopt+=("${cmd_map_compressor_unreal[@]}")
123122
fi
124123

125124
# DST exclusive.

lgsm/modules/core_modules.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,6 @@ compress_unreal2_maps.sh() {
275275
fn_fetch_module
276276
}
277277

278-
compress_ut99_maps.sh() {
279-
modulefile="${FUNCNAME[0]}"
280-
fn_fetch_module
281-
}
282-
283278
# Mods
284279

285280
mods_list.sh() {

lgsm/modules/install_ut2k4_key.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ else
2727
echo -e "./${selfname} server-cd-key"
2828
fi
2929
echo -e ""
30+
core_exit.sh

0 commit comments

Comments
 (0)