command_mods_update.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. # Don't update the mod if it's policy is to "NOUPDATE"
  50. if [ "${modkeepfiles}" == "NOUPDATE" ]; then
  51. fn_print_warning "${modprettyname} update has been disabled by LGSM."
  52. echo " * Usual reason is to prevent erasing custom files."
  53. echo " * If you still wish to update this mod:"
  54. echo " * 1) Backup your critical mod files"
  55. echo " * 2) Uninstall the mod with ./${selfname} mods-uninstall (optionnal)"
  56. echo " * 3) Re-install the mod with ./${selfname} mods-install"
  57. else
  58. fn_print_dots_nl "Updating ${modprettyname}"
  59. fn_script_log "Updating ${modprettyname}."
  60. # Check and create required directories
  61. fn_mods_dir
  62. # Clear lgsm/tmp/mods dir if exists then recreate it
  63. fn_clear_tmp_mods
  64. fn_mods_tmpdir
  65. # Download mod
  66. fn_mod_dl
  67. # Extract the mod
  68. fn_mod_extract
  69. # Remove files that should not be erased
  70. # fn_remove_cfg_files
  71. # Convert to lowercase if needed
  72. fn_mod_lowercase
  73. # Build a file list
  74. fn_mod_fileslist
  75. # Copying to destination
  76. fn_mod_copy_destination
  77. # Ending with installation routines
  78. fn_mod_add_list
  79. fn_clear_tmp_mods
  80. fn_print_ok_nl "${modprettyname} installed."
  81. fn_script_log "${modprettyname} installed."
  82. let installedmodsline=installedmodsline+1
  83. fi
  84. else
  85. fn_print_fail "No mod was selected."
  86. fn_script_log_fail "No mod was selected."
  87. core_exit.sh
  88. fi
  89. done
  90. }
  91. fn_mods_update_init
  92. fn_mods_update_loop