command_mods_install.sh 3.7 KB

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