4
0

command_mods_update.sh 3.2 KB

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