command_mods_update.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. fn_mods_update_init(){
  11. fn_script_log "Entering mods & addons update"
  12. echo "================================="
  13. echo "${gamename} mods & addons update"
  14. # A simple function to exit if no mods were installed
  15. # Also returns ${installedmodscount} if mods were found
  16. fn_mods_exit_if_not_installed
  17. echo ""
  18. fn_print_information_nl "${installedmodscount} mods or addons will be updated:"
  19. fn_script_log_info "${installedmodscount} mods or addons will be updated"
  20. # Display a list of installed addons
  21. fn_installed_mods_update_list
  22. }
  23. # Recursively list all installed mods and apply update
  24. fn_mods_update_loop(){
  25. # Reset line value
  26. installedmodsline="1"
  27. while [ $installedmodsline -le $installedmodscount ]; do
  28. # Current line defines current mod command
  29. currentmod="$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")"
  30. if [ -n "${currentmod}" ]; then
  31. # Get mod info
  32. fn_mod_get_info_from_command
  33. # Don't update the mod if it's policy is to "NOUPDATE"
  34. if [ "${modkeepfiles}" == "NOUPDATE" ]; then
  35. fn_print_info "${modprettyname} won't be updated to preserve custom files"
  36. fn_script_log "${modprettyname} won't be updated to preserve custom files."
  37. let installedmodsline=installedmodsline+1
  38. else
  39. echo ""
  40. fn_print_dots_nl "Updating ${modprettyname}"
  41. fn_script_log "Updating ${modprettyname}."
  42. # Check and create required files
  43. fn_mods_files
  44. # Clear lgsm/tmp/mods dir if exists then recreate it
  45. fn_clear_tmp_mods
  46. fn_mods_tmpdir
  47. # Download mod
  48. fn_mod_dl
  49. # Extract the mod
  50. fn_mod_extract
  51. # Convert to lowercase if needed
  52. fn_mod_lowercase
  53. # Remove files that should not be erased
  54. fn_remove_cfg_files
  55. # Build a file list
  56. fn_mod_fileslist
  57. # Copying to destination
  58. fn_mod_copy_destination
  59. # Ending with installation routines
  60. fn_mod_add_list
  61. # Post install fixes
  62. fn_postinstall_tasks
  63. # Cleaning
  64. fn_clear_tmp_mods
  65. fn_print_ok "${modprettyname} updated"
  66. fn_script_log "${modprettyname} updated."
  67. let installedmodsline=installedmodsline+1
  68. fi
  69. else
  70. fn_print_fail "No mod was selected"
  71. fn_script_log_fail "No mod was selected."
  72. exitcode="1"
  73. core_exit.sh
  74. fi
  75. done
  76. echo ""
  77. fn_print_ok_nl "Mods update complete"
  78. fn_script_log "Mods update complete."
  79. }
  80. check.sh
  81. mods_core.sh
  82. fn_mods_update_init
  83. fn_mods_update_loop
  84. core_exit.sh