command_mods_update.sh 4.1 KB

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