command_mods_update.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. fn_sleep_time
  18. # Count how many files there are to remove.
  19. filestopreserve=$(echo -e "${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 -e "${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 -e "${filetopreserve}" >> "${modsdir}/.removedfiles.tmp"
  33. fi
  34. done
  35. fi
  36. }
  37. fn_print_dots "Update addons/mods"
  38. fn_mods_check_installed
  39. fn_print_info_nl "Update addons/mods: ${installedmodscount} addons/mods will be updated"
  40. fn_script_log_info "${installedmodscount} mods or addons will be updated"
  41. fn_mods_installed_list
  42. # Go through all available commands, get details and display them to the user.
  43. for ((ulindex=0; ulindex < ${#installedmodslist[@]}; ulindex++)); do
  44. # Current mod is the "ulindex" value of the array we're going through.
  45. currentmod="${installedmodslist[ulindex]}"
  46. fn_mod_get_info
  47. # Display installed mods and the update policy.
  48. if [ -z "${modkeepfiles}" ]; then
  49. # If modkeepfiles is not set for some reason, that's a problem.
  50. fn_script_log_error "Could not find update policy for ${modprettyname}"
  51. fn_print_error_nl "Could not find update policy for ${modprettyname}"
  52. exitcode="1"
  53. core_exit.sh
  54. # If the mod won't get updated.
  55. elif [ "${modkeepfiles}" == "NOUPDATE" ]; then
  56. echo -e " * ${red}{modprettyname}${default} (won't be updated)"
  57. # If the mode is just overwritten.
  58. elif [ "${modkeepfiles}" == "OVERWRITE" ]; then
  59. echo -e " * ${modprettyname} (overwrite)"
  60. else
  61. echo -e " * ${yellow}${modprettyname}${default} (retain common custom files)"
  62. fi
  63. done
  64. ## Update
  65. # List all installed mods and apply update.
  66. # Reset line value.
  67. installedmodsline="1"
  68. while [ "${installedmodsline}" -le "${installedmodscount}" ]; do
  69. currentmod=$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")
  70. if [ -n "${currentmod}" ]; then
  71. fn_mod_get_info
  72. # Don not update mod if the policy is set to "NOUPDATE".
  73. if [ "${modkeepfiles}" == "NOUPDATE" ]; then
  74. fn_print_info "${modprettyname} will not be updated to preserve custom files"
  75. fn_script_log_info "${modprettyname} will not be updated to preserve custom files"
  76. else
  77. echo -e ""
  78. echo -e "==> Updating ${modprettyname}"
  79. fn_create_mods_dir
  80. fn_mods_clear_tmp_dir
  81. fn_mods_create_tmp_dir
  82. fn_mod_install_files
  83. fn_mod_lowercase
  84. fn_remove_cfg_files
  85. fn_mod_create_filelist
  86. fn_mod_copy_destination
  87. fn_mod_add_list
  88. fn_mod_tidy_files_list
  89. fn_mods_clear_tmp_dir
  90. fi
  91. ((installedmodsline++))
  92. else
  93. fn_print_fail "No mod was selected"
  94. fn_script_log_fatal "No mod was selected"
  95. exitcode="1"
  96. core_exit.sh
  97. fi
  98. done
  99. echo -e ""
  100. fn_print_ok_nl "Mods update complete"
  101. fn_script_log_info "Mods update complete"
  102. core_exit.sh