4
0

compress_unreal_maps.sh 2.3 KB

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