command_mods_update.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_print_header
  13. # Prevents specific files being overwritten upon update (set by ${modkeepfiles})
  14. # For that matter, remove cfg files after extraction before copying them to destination
  15. fn_remove_cfg_files(){
  16. if [ "${modkeepfiles}" != "OVERWRITE" ]&&[ "${modkeepfiles}" != "NOUPDATE" ]; then
  17. fn_print_dots "Preventing overwriting of ${modprettyname} config files"
  18. fn_script_log "Preventing overwriting of ${modprettyname} config files"
  19. sleep 0.5
  20. # Count how many files there are to remove
  21. removefilesamount="$(echo "${modkeepfiles}" | awk -F ';' '{ print NF }')"
  22. # Test all subvalues of "modkeepfiles" using the ";" separator
  23. for ((removefilesindex=1; removefilesindex < ${removefilesamount}; removefilesindex++)); do
  24. # Put the current file we are looking for into a variable
  25. filetoremove="$( echo "${modkeepfiles}" | awk -F ';' -v x=${removefilesindex} '{ print $x }' )"
  26. # If it matches an existing file that have been extracted delete the file
  27. if [ -f "${extractdir}/${filetoremove}" ]||[ -d "${extractdir}/${filetoremove}" ]; then
  28. rm -r "${extractdir}/${filetoremove}"
  29. # Write the file path in a tmp file, to rebuild a full file list as it is rebuilt upon update
  30. if [ ! -f "${modsdir}/.removedfiles.tmp" ]; then
  31. touch "${modsdir}/.removedfiles.tmp"
  32. fi
  33. echo "${filetoremove}" >> "${modsdir}/.removedfiles.tmp"
  34. fi
  35. done
  36. fn_print_ok "Preventing overwriting of ${modprettyname} config files"
  37. sleep 0.5
  38. fi
  39. }
  40. echo "Update addons/mods"
  41. echo "================================="
  42. fn_mods_check_installed
  43. fn_print_information_nl "${installedmodscount} addons/mods will be updated"
  44. fn_script_log_info "${installedmodscount} mods or addons will be updated"
  45. fn_mods_installed_list
  46. echo ""
  47. echo "Installed addons/mods"
  48. echo "================================="
  49. # Go through all available commands, get details and display them to the user
  50. for ((ulindex=0; ulindex < ${#installedmodslist[@]}; ulindex++)); do
  51. # Current mod is the "ulindex" value of the array we're going through
  52. currentmod="${installedmodslist[ulindex]}"
  53. fn_mod_get_info
  54. # Display installed mods and the update policy
  55. if [ -z "${modkeepfiles}" ]; then
  56. # If modkeepfiles is not set for some reason, that's a problem
  57. fn_script_log_error "Couldn't find update policy for ${modprettyname}"
  58. fn_print_error_nl "Couldn't find update policy for ${modprettyname}"
  59. exitcode="1"
  60. core_exit.sh
  61. # If the mod won't get updated
  62. elif [ "${modkeepfiles}" == "NOUPDATE" ]; then
  63. echo -e " * \e[31m${modprettyname}${default} (won't be updated)"
  64. # If the mode is just overwritten
  65. elif [ "${modkeepfiles}" == "OVERWRITE" ]; then
  66. echo -e " * \e[1m${modprettyname}${default} (overwrite)"
  67. else
  68. echo -e " * ${yellow}${modprettyname}${default} (common custom files remain untouched)"
  69. fi
  70. done
  71. ## Update
  72. # List all installed mods and apply update
  73. # Reset line value
  74. installedmodsline="1"
  75. while [ ${installedmodsline} -le ${installedmodscount} ]; do
  76. currentmod="$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")"
  77. if [ -n "${currentmod}" ]; then
  78. fn_mod_get_info
  79. # Don not update mod if the policy is set to "NOUPDATE"
  80. if [ "${modkeepfiles}" == "NOUPDATE" ]; then
  81. fn_print_info "${modprettyname} will not be updated to preserve custom files"
  82. fn_script_log_info "${modprettyname} will not be updated to preserve custom files"
  83. else
  84. echo ""
  85. fn_create_mods_dir
  86. fn_mods_clear_tmp_dir
  87. fn_mods_create_tmp_dir
  88. fn_mod_install_files
  89. fn_mod_lowercase
  90. fn_remove_cfg_files
  91. fn_mod_create_filelist
  92. fn_mod_copy_destination
  93. fn_mod_add_list
  94. fn_mod_tidy_files_list
  95. fn_mods_clear_tmp_dir
  96. fi
  97. ((installedmodsline++))
  98. else
  99. fn_print_fail "No mod was selected"
  100. fn_script_log_fatal "No mod was selected"
  101. exitcode="1"
  102. core_exit.sh
  103. fi
  104. done
  105. echo ""
  106. fn_print_ok_nl "Mods update complete"
  107. fn_script_log "Mods update complete"
  108. core_exit.sh