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