command_mods_install.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. # LinuxGSM command_mods_install.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.com
  6. # Description: List and installs available mods along with mods_list.sh and mods_core.sh.
  7. local commandname="MODS"
  8. local commandaction="addons/mods"
  9. local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
  10. check.sh
  11. mods_core.sh
  12. fn_print_header
  13. # Displays a list of installed mods.
  14. fn_mods_installed_list
  15. if [ "${installedmodscount}" -gt "0" ]; then
  16. echo -e "Installed addons/mods"
  17. echo -e "================================="
  18. # Go through all available commands, get details and display them to the user.
  19. for ((llindex=0; llindex < ${#installedmodslist[@]}; llindex++)); do
  20. # Current mod is the "llindex" value of the array we're going through.
  21. currentmod="${installedmodslist[llindex]}"
  22. fn_mod_get_info
  23. # Display mod info to the user.
  24. echo -e " * ${green}${modcommand}${default}${default}"
  25. done
  26. echo -e ""
  27. fi
  28. echo -e "Available addons/mods"
  29. echo -e "================================="
  30. # Display available mods from mods_list.sh.
  31. # Set and reset vars
  32. compatiblemodslistindex=0
  33. # As long as we're within index values.
  34. while [ "${compatiblemodslistindex}" -lt "${#compatiblemodslist[@]}" ]; do
  35. # Set values for convenience.
  36. displayedmodname="${compatiblemodslist[compatiblemodslistindex]}"
  37. displayedmodcommand="${compatiblemodslist[compatiblemodslistindex+1]}"
  38. displayedmodsite="${compatiblemodslist[compatiblemodslistindex+2]}"
  39. displayedmoddescription="${compatiblemodslist[compatiblemodslistindex+3]}"
  40. # Output mods to the user.
  41. echo -e "${displayedmodname} - ${displayedmoddescription} - ${displayedmodsite}"
  42. echo -e " * ${cyan}${displayedmodcommand}${default}"
  43. # Increment index from the amount of values we just displayed.
  44. let "compatiblemodslistindex+=4"
  45. ((totalmodsavailable++))
  46. done
  47. # If no mods are available for a specific game.
  48. if [ -z "${compatiblemodslist}" ]; then
  49. fn_print_fail_nl "No mods are currently available for ${gamename}."
  50. fn_script_log_info "No mods are currently available for ${gamename}."
  51. core_exit.sh
  52. fi
  53. fn_script_log_info "${totalmodsavailable} addons/mods are available for install"
  54. ## User selects a mod.
  55. echo -e ""
  56. while [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; do
  57. echo -en "Enter an ${cyan}addon/mod${default} to ${green}install${default} (or exit to abort): "
  58. read -r usermodselect
  59. # Exit if user says exit or abort.
  60. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  61. core_exit.sh
  62. # Supplementary output upon invalid user input.
  63. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  64. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  65. fi
  66. done
  67. # Get mod info.
  68. currentmod="${usermodselect}"
  69. fn_mod_get_info
  70. echo -e ""
  71. echo -e "Installing ${modprettyname}"
  72. echo -e "================================="
  73. fn_script_log_info "${modprettyname} selected for install"
  74. # Check if the mod is already installed and warn the user.
  75. if [ -f "${modsinstalledlistfullpath}" ]; then
  76. if [ -n "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
  77. fn_print_warning_nl "${modprettyname} is already installed"
  78. fn_script_log_warn "${modprettyname} is already installed"
  79. echo -e " * Any configs may be overwritten."
  80. if ! fn_prompt_yn "Continue?" Y; then
  81. core_exit.sh
  82. fi
  83. fn_script_log_info "User selected to continue"
  84. fi
  85. fi
  86. ## Installation.
  87. fn_create_mods_dir
  88. fn_mods_clear_tmp_dir
  89. fn_mods_create_tmp_dir
  90. fn_mod_install_files
  91. fn_mod_lowercase
  92. fn_mod_create_filelist
  93. fn_mod_copy_destination
  94. fn_mod_add_list
  95. fn_mod_tidy_files_list
  96. fn_mods_clear_tmp_dir
  97. echo -e "${modprettyname} installed"
  98. fn_script_log_pass "${modprettyname} installed."
  99. core_exit.sh