command_mods_update.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if [ -f "${modslockfilefullpath}" ]; then
  21. installedmodscount="$(cat "${modslockfilefullpath}" | wc -l)"
  22. if
  23. echo "${installedmodscount} addons will be updated:"
  24. # Loop showing mods to update
  25. installedmodsline=1
  26. while [ $installedmodsline -le $installedmodscount ]; do
  27. echo -e " * \e[36m$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")\e[0m"
  28. let installedmodsline=installedmodsline+1
  29. done
  30. sleep 2
  31. else
  32. fn_print_info_nl "No mods to be updated!"
  33. echo " * Did you install any mod using LGSM?"
  34. fn_print_log "No mods to be updated"
  35. core_exit.sh
  36. fi
  37. }
  38. fn_mods_update_loop(){
  39. installedmodline="1"
  40. while [ $installedmodsline -le $installedmodscount ]; do
  41. currentmod="$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")"
  42. fn_mod_get_info_from_command
  43. if [ -n "${currentmod}" ]; then
  44. fn_print_dots_nl "Updating ${modprettyname}"
  45. sleep 0.5
  46. fn_script_log "Updating ${modprettyname}."
  47. # Get mod info
  48. fn_mod_get_info_from_command
  49. # Check if mod is already installed
  50. fn_mod_already_installed
  51. # Check and create required directories
  52. fn_mods_dir
  53. # Clear lgsm/tmp/mods dir if exists then recreate it
  54. fn_clear_tmp_mods
  55. fn_mods_tmpdir
  56. # Download mod
  57. fn_mod_dl
  58. # Extract the mod
  59. fn_mod_extract
  60. # Build a file list
  61. fn_mod_fileslist
  62. # Copying to destination
  63. fn_mod_copy_destination
  64. # Ending with installation routines
  65. fn_mod_add_list
  66. fn_clear_tmp_mods
  67. fn_print_ok_nl "${modprettyname} installed."
  68. fn_script_log "${modprettyname} installed."
  69. let installedmodsline=installedmodsline+1
  70. else
  71. fn_print_fail "No mod was selected."
  72. core_exit.sh
  73. fi
  74. done
  75. }
  76. fn_mods_update_init
  77. fn_mods_update_loop