command_mods_update.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # LGSM command_mods_update.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Updates installed mods along with mods_list.sh and mods_core.sh.
  7. local commandname="MODS"
  8. local commandaction="Mods Update"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. check.sh
  11. mods_core.sh
  12. mods_list.sh
  13. fn_mods_update_init(){
  14. fn_script_log "Entering mods & addons update"
  15. echo "================================="
  16. echo "${gamename} mods & addons update"
  17. echo ""
  18. # Installed mod dir is "${modslockfilefullpath}"
  19. # How many mods will be updated
  20. installedmodscount="$(cat "${modslockfilefullpath}" | wc -l)"
  21. # If no mods to be updated
  22. if [ ! -f "${modslockfilefullpath}" ]||[ $installedmodscount -eq 0 ]; then
  23. fn_print_information_nl "No mods or addons to be updated"
  24. echo " * Did you install any mod using LGSM?"
  25. fn_scrip_log_info "No mods or addons to be updated"
  26. core_exit.sh
  27. else
  28. fn_print_information_nl "${installedmodscount} mods or addons will be updated:"
  29. fn_script_log_info "${installedmodscount} mods or addons will be updated"
  30. # Loop showing mods to update
  31. installedmodsline=1
  32. while [ $installedmodsline -le $installedmodscount ]; do
  33. echo -e " * \e[36m$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")\e[0m"
  34. let installedmodsline=installedmodsline+1
  35. done
  36. sleep 2
  37. fi
  38. }
  39. # Recursively list all installed mods and apply update
  40. fn_mods_update_loop(){
  41. # Reset line value
  42. installedmodsline="1"
  43. while [ $installedmodsline -le $installedmodscount ]; do
  44. # Current line defines current mod command
  45. currentmod="$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")"
  46. if [ -n "${currentmod}" ]; then
  47. # Get mod info
  48. fn_mod_get_info_from_command
  49. fn_print_dots_nl "Updating ${modprettyname}"
  50. fn_script_log "Updating ${modprettyname}."
  51. # Check and create required directories
  52. fn_mods_dir
  53. # Clear lgsm/tmp/mods dir if exists then recreate it
  54. fn_clear_tmp_mods
  55. fn_mods_tmpdir
  56. # Download mod
  57. fn_mod_dl
  58. # Extract the mod
  59. fn_mod_extract
  60. # Remove files that should not be erased
  61. # fn_remove_cfg_files
  62. # Convert to lowercase if needed
  63. fn_mod_lowercase
  64. # Build a file list
  65. fn_mod_fileslist
  66. # Copying to destination
  67. fn_mod_copy_destination
  68. # Ending with installation routines
  69. fn_mod_add_list
  70. fn_clear_tmp_mods
  71. fn_print_ok_nl "${modprettyname} installed."
  72. fn_script_log "${modprettyname} installed."
  73. let installedmodsline=installedmodsline+1
  74. else
  75. fn_print_fail "No mod was selected."
  76. core_exit.sh
  77. fi
  78. done
  79. }
  80. fn_mods_update_init
  81. fn_mods_update_loop