command_mods_update.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # LinuxGSM command_mods_update.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.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. echo -e "the following files/directories will be preserved:"
  17. sleep 0.5
  18. # Count how many files there are to remove
  19. filestopreserve="$(echo "${modkeepfiles}" | awk -F ';' '{ print NF }')"
  20. # Test all subvalues of "modkeepfiles" using the ";" separator
  21. for ((preservefilesindex=1; preservefilesindex < ${filestopreserve}; preservefilesindex++)); do
  22. # Put the current file we are looking for into a variable
  23. filetopreserve="$(echo "${modkeepfiles}" | awk -F ';' -v x=${preservefilesindex} '{ print $x }' )"
  24. echo -e " * serverfiles/${filetopreserve}"
  25. # If it matches an existing file that have been extracted delete the file
  26. if [ -f "${extractdir}/${filetopreserve}" ]||[ -d "${extractdir}/${filetopreserve}" ]; then
  27. rm -r "${extractdir}/${filetopreserve}"
  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 "${filetopreserve}" >> "${modsdir}/.removedfiles.tmp"
  33. fi
  34. done
  35. fi
  36. }
  37. fn_print_dots "Update addons/mods"
  38. sleep 0.5
  39. fn_mods_check_installed
  40. fn_print_info_nl "Update addons/mods: ${installedmodscount} addons/mods will be updated"
  41. fn_script_log_info "${installedmodscount} mods or addons will be updated"
  42. fn_mods_installed_list
  43. # Go through all available commands, get details and display them to the user
  44. for ((ulindex=0; ulindex < ${#installedmodslist[@]}; ulindex++)); do
  45. # Current mod is the "ulindex" value of the array we're going through
  46. currentmod="${installedmodslist[ulindex]}"
  47. fn_mod_get_info
  48. # Display installed mods and the update policy
  49. if [ -z "${modkeepfiles}" ]; then
  50. # If modkeepfiles is not set for some reason, that's a problem
  51. fn_script_log_error "Could not find update policy for ${modprettyname}"
  52. fn_print_error_nl "Could not find update policy for ${modprettyname}"
  53. exitcode="1"
  54. core_exit.sh
  55. # If the mod won't get updated
  56. elif [ "${modkeepfiles}" == "NOUPDATE" ]; then
  57. echo -e " * ${red}{modprettyname}${default} (won't be updated)"
  58. # If the mode is just overwritten
  59. elif [ "${modkeepfiles}" == "OVERWRITE" ]; then
  60. echo -e " * ${modprettyname} (overwrite)"
  61. else
  62. echo -e " * ${yellow}${modprettyname}${default} (retain common custom files)"
  63. fi
  64. done
  65. sleep 1
  66. ## Update
  67. # List all installed mods and apply update
  68. # Reset line value
  69. installedmodsline="1"
  70. while [ ${installedmodsline} -le ${installedmodscount} ]; do
  71. currentmod="$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")"
  72. if [ -n "${currentmod}" ]; then
  73. fn_mod_get_info
  74. # Don not update mod if the policy is set to "NOUPDATE"
  75. if [ "${modkeepfiles}" == "NOUPDATE" ]; then
  76. fn_print_info "${modprettyname} will not be updated to preserve custom files"
  77. fn_script_log_info "${modprettyname} will not be updated to preserve custom files"
  78. else
  79. echo ""
  80. echo "==> Updating ${modprettyname}"
  81. fn_create_mods_dir
  82. fn_mods_clear_tmp_dir
  83. fn_mods_create_tmp_dir
  84. fn_mod_install_files
  85. fn_mod_lowercase
  86. fn_remove_cfg_files
  87. fn_mod_create_filelist
  88. fn_mod_copy_destination
  89. fn_mod_add_list
  90. fn_mod_tidy_files_list
  91. fn_mods_clear_tmp_dir
  92. fi
  93. ((installedmodsline++))
  94. else
  95. fn_print_fail "No mod was selected"
  96. fn_script_log_fatal "No mod was selected"
  97. exitcode="1"
  98. core_exit.sh
  99. fi
  100. done
  101. echo ""
  102. fn_print_ok_nl "Mods update complete"
  103. fn_script_log_info "Mods update complete"
  104. core_exit.sh