From 471485117c7dcb5178920af57350cd1efb3c17a5 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 9 Aug 2025 01:36:24 +0100 Subject: [PATCH] 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 <175728472+Copilot@users.noreply.github.com> * 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 <175728472+Copilot@users.noreply.github.com> --- .shellcheckrc | 1 + lgsm/modules/compress_unreal2_maps.sh | 35 ------------ lgsm/modules/compress_unreal_maps.sh | 80 +++++++++++++++++++++++++++ lgsm/modules/compress_ut99_maps.sh | 35 ------------ lgsm/modules/core_getopt.sh | 9 ++- lgsm/modules/core_modules.sh | 5 -- lgsm/modules/install_ut2k4_key.sh | 1 + 7 files changed, 86 insertions(+), 80 deletions(-) create mode 100644 .shellcheckrc delete mode 100644 lgsm/modules/compress_unreal2_maps.sh create mode 100644 lgsm/modules/compress_unreal_maps.sh delete mode 100644 lgsm/modules/compress_ut99_maps.sh diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 000000000..026ee646c --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1 @@ +disable=SC2154 diff --git a/lgsm/modules/compress_unreal2_maps.sh b/lgsm/modules/compress_unreal2_maps.sh deleted file mode 100644 index 58824cbc7..000000000 --- a/lgsm/modules/compress_unreal2_maps.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# LinuxGSM compress_unreal2_maps.sh module -# Author: Daniel Gibbs -# Contributors: https://linuxgsm.com/contrib -# Website: https://linuxgsm.com -# Description: Compresses unreal maps. - -commandname="MAP-COMPRESSOR" -commandaction="Compressing Maps" -moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -fn_firstcommand_set - -check.sh -fn_print_header -echo -e "Will compress all maps in:" -echo -e "" -pwd -echo -e "" -echo -e "Compressed maps saved to:" -echo -e "" -echo -e "${compressedmapsdir}" -echo -e "" -if ! fn_prompt_yn "Start compression?" Y; then - exitcode=0 - core_exit.sh -fi -mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1 -rm -rfv "${serverfiles:?}/Maps/"*.ut2.uz2 -cd "${systemdir}" || exit -for map in "${serverfiles}/Maps/"*; do - ./ucc-bin compress "${map}" --nohomedir -done -mv -fv "${serverfiles}/Maps/"*.ut2.uz2 "${compressedmapsdir}" - -core_exit.sh diff --git a/lgsm/modules/compress_unreal_maps.sh b/lgsm/modules/compress_unreal_maps.sh new file mode 100644 index 000000000..6b97e03d9 --- /dev/null +++ b/lgsm/modules/compress_unreal_maps.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# LinuxGSM compress_unreal_maps.sh module +# Author: Daniel Gibbs +# Contributors: https://linuxgsm.com/contrib +# Website: https://linuxgsm.com +# Description: Compresses unreal and unreal2 resources. + +commandname="MAP-COMPRESSOR" +commandaction="Compressing Maps" +moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" +fn_firstcommand_set + +check.sh +fn_print_header +echo -e "Will compress all maps in:" +echo -e "" +pwd +echo -e "" +echo -e "Compressed maps saved to:" +echo -e "" +echo -e "${compressedmapsdir}" +echo -e "" +totalseconds=3 +for seconds in {3..1}; do + fn_print_warn "map compression starting in: ${totalseconds}" + totalseconds=$((totalseconds - 1)) + fn_sleep_time_1 + if [ "${seconds}" == "0" ]; then + break + fi +done +fn_print_nl +mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1 + +# List of extensions to compress +exts=(ut2 kfm rom u ucl upl int utx uax ukx usx unr umx umod uzx) + +# Remove old compressed files using find +for ext in "${exts[@]}"; do + mapfile -t oldfiles < <(find "${serverfiles}" -name "*.${ext}.uz2" -type f) + if [ ${#oldfiles[@]} -gt 0 ]; then + echo -e "found ${#oldfiles[@]} old compressed file(s) to remove for extension: ${ext}" + fi + for file in "${oldfiles[@]}"; do + if rm -f "$file"; then + echo -en "removing file [ ${italic}$(basename "$file")${default} ]\c" + fn_print_ok_eol_nl + else + echo -en "removing file [ ${italic}$(basename "$file")${default} ]\c" + fn_print_fail_eol_nl + fi + done +done + +cd "${systemdir}" || exit + +# Find and compress files, then move .uz2 to compressedmapsdir +for ext in "${exts[@]}"; do + # Collect all files with the current extension into an array + mapfile -t files < <(find "${serverfiles}" -name "*.${ext}" -type f) + for file in "${files[@]}"; do + echo -en "compressing file [ ${italic}$(basename "$file") -> $(basename "$file").uz2${default} ]\c" + if ! ./ucc-bin compress "${file}" --nohomedir > /dev/null 2>&1; then + fn_print_fail_eol_nl + core_exit.sh + else + fn_print_ok_eol_nl + fi + + if ! mv -f "${file}.uz2" "${compressedmapsdir}" > /dev/null 2>&1; then + echo -en "moving compressed file [ ${italic}$(basename "$file").uz2 -> ${compressedmapsdir}/$(basename "$file").uz2${default} ]\c" + fn_print_fail_eol_nl + core_exit.sh + fi + done +done + +fn_print_ok_nl "Compression complete: All compressed files moved to: ${compressedmapsdir}" + +core_exit.sh diff --git a/lgsm/modules/compress_ut99_maps.sh b/lgsm/modules/compress_ut99_maps.sh deleted file mode 100644 index 885c32d9a..000000000 --- a/lgsm/modules/compress_ut99_maps.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# LinuxGSM compress_ut99_maps.sh module -# Author: Daniel Gibbs -# Contributors: https://linuxgsm.com/contrib -# Website: https://linuxgsm.com -# Description: Compresses unreal maps. - -commandname="MAP-COMPRESSOR" -commandaction="Compressing Maps" -moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -fn_firstcommand_set - -check.sh -fn_print_header -echo -e "Will compress all maps in:" -echo -e "" -pwd -echo -e "" -echo -e "Compressed maps saved to:" -echo -e "" -echo -e "${compressedmapsdir}" -echo -e "" -if ! fn_prompt_yn "Start compression?" Y; then - exitcode=0 - core_exit.sh -fi -mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1 -rm -rfv "${serverfiles:?}/Maps/"*.unr.uz -cd "${systemdir}" || exit -for map in "${serverfiles}/Maps/"*; do - ./ucc-bin compress "${map}" --nohomedir -done -mv -fv "${serverfiles}/Maps/"*.unr.uz "${compressedmapsdir}" - -core_exit.sh diff --git a/lgsm/modules/core_getopt.sh b/lgsm/modules/core_getopt.sh index 8997ff3a0..295f9900b 100644 --- a/lgsm/modules/core_getopt.sh +++ b/lgsm/modules/core_getopt.sh @@ -42,8 +42,7 @@ cmd_change_password=("pw;change-password" "command_ts3_server_pass.sh" "Change T cmd_install_default_resources=("ir;install-default-resources" "command_install_resources_mta.sh" "Install the MTA default resources.") cmd_fullwipe=("fw;full-wipe;wa;wipeall" "serverwipe=1; command_wipe.sh" "Reset the map and remove blueprint data.") cmd_mapwipe=("mw;map-wipe;w;wipe;wi" "mapwipe=1; command_wipe.sh" "Reset the map and keep blueprint data.") -cmd_map_compressor_u99=("mc;map-compressor" "compress_ut99_maps.sh" "Compresses all ${gamename} server maps.") -cmd_map_compressor_u2=("mc;map-compressor" "compress_unreal2_maps.sh" "Compresses all ${gamename} server maps.") +cmd_map_compressor_unreal=("mc;map-compressor" "compress_unreal_maps.sh" "Compresses all ${gamename} server maps.") cmd_install_cdkey=("cd;server-cd-key" "install_ut2k4_key.sh" "Add your server cd key.") cmd_install_dst_token=("ct;cluster-token" "install_dst_token.sh" "Configure cluster token.") cmd_install_squad_license=("li;license" "install_squad_license.sh" "Add your Squad server license.") @@ -113,13 +112,13 @@ fi # Unreal exclusive. if [ "${engine}" == "unreal2" ]; then if [ "${shortname}" == "ut2k4" ]; then - currentopt+=("${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}") + currentopt+=("${cmd_install_cdkey[@]}" "${cmd_map_compressor_unreal[@]}") else - currentopt+=("${cmd_map_compressor_u2[@]}") + currentopt+=("${cmd_map_compressor_unreal[@]}") fi fi if [ "${engine}" == "unreal" ]; then - currentopt+=("${cmd_map_compressor_u99[@]}") + currentopt+=("${cmd_map_compressor_unreal[@]}") fi # DST exclusive. diff --git a/lgsm/modules/core_modules.sh b/lgsm/modules/core_modules.sh index e5e6d1e5d..2116e5366 100644 --- a/lgsm/modules/core_modules.sh +++ b/lgsm/modules/core_modules.sh @@ -275,11 +275,6 @@ compress_unreal2_maps.sh() { fn_fetch_module } -compress_ut99_maps.sh() { - modulefile="${FUNCNAME[0]}" - fn_fetch_module -} - # Mods mods_list.sh() { diff --git a/lgsm/modules/install_ut2k4_key.sh b/lgsm/modules/install_ut2k4_key.sh index 2829da8d6..963a52f10 100644 --- a/lgsm/modules/install_ut2k4_key.sh +++ b/lgsm/modules/install_ut2k4_key.sh @@ -27,3 +27,4 @@ else echo -e "./${selfname} server-cd-key" fi echo -e "" +core_exit.sh