command_mods_update.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. fn_mods_update_init(){
  13. fn_script_log "Entering mods & addons update"
  14. echo "================================="
  15. echo "${gamename} mods & addons update"
  16. echo ""
  17. # Installed mod dir is "${modslockfilefullpath}"
  18. # How many mods will be updated
  19. installedmodscount="$(cat "${modslockfilefullpath}" | wc -l)"
  20. # If no mods to be updated
  21. if [ ! -f "${modslockfilefullpath}" ]||[ $installedmodscount -eq 0 ]; then
  22. fn_print_information_nl "No mods or addons to be updated"
  23. echo " * Did you install any mod using LGSM?"
  24. fn_script_log_info "No mods or addons to be updated"
  25. core_exit.sh
  26. else
  27. fn_print_information_nl "${installedmodscount} mods or addons will be updated:"
  28. fn_script_log_info "${installedmodscount} mods or addons will be updated"
  29. # Loop showing mods to update
  30. installedmodsline=1
  31. while [ $installedmodsline -le $installedmodscount ]; do
  32. echo -e " * \e[36m$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")\e[0m"
  33. let installedmodsline=installedmodsline+1
  34. done
  35. sleep 2
  36. fi
  37. }
  38. # Recursively list all installed mods and apply update
  39. fn_mods_update_loop(){
  40. # Reset line value
  41. installedmodsline="1"
  42. while [ $installedmodsline -le $installedmodscount ]; do
  43. # Current line defines current mod command
  44. currentmod="$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")"
  45. if [ -n "${currentmod}" ]; then
  46. # Get mod info
  47. fn_mod_get_info_from_command
  48. # Don't update the mod if it's policy is to "NOUPDATE"
  49. if [ "${modkeepfiles}" == "NOUPDATE" ]; then
  50. fn_print_info_nl "${modprettyname} won't be updated to preserve custom files"
  51. fn_script_log "${modprettyname} won't be updated to preserve custom files."
  52. let installedmodsline=installedmodsline+1
  53. else
  54. echo ""
  55. fn_print_dots_nl "Updating ${modprettyname}"
  56. fn_script_log "Updating ${modprettyname}."
  57. # Check and create required files
  58. fn_mods_files
  59. # Clear lgsm/tmp/mods dir if exists then recreate it
  60. fn_clear_tmp_mods
  61. fn_mods_tmpdir
  62. # Download mod
  63. fn_mod_dl
  64. # Extract the mod
  65. fn_mod_extract
  66. # Convert to lowercase if needed
  67. fn_mod_lowercase
  68. # Remove files that should not be erased
  69. fn_remove_cfg_files
  70. # Build a file list
  71. fn_mod_fileslist
  72. # Copying to destination
  73. fn_mod_copy_destination
  74. # Ending with installation routines
  75. fn_mod_add_list
  76. # Post install fixes
  77. fn_postinstall_tasks
  78. # Cleaning
  79. fn_clear_tmp_mods
  80. fn_print_ok "${modprettyname} updated"
  81. fn_script_log "${modprettyname} updated."
  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. exitcode="1"
  88. core_exit.sh
  89. fi
  90. done
  91. echo ""
  92. fn_print_ok_nl "Mods update complete"
  93. fn_script_log "Mods update complete."
  94. }
  95. fn_mods_update_init
  96. fn_mods_update_loop
  97. core_exit.sh