command_mods_install.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. # LinuxGSM command_mods_install.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.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 "Installed addons/mods"
  17. echo "================================="
  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 ""
  27. fi
  28. echo "Available addons/mods"
  29. echo "================================="
  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 ""
  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 ""
  71. echo "Installing ${modprettyname}"
  72. echo "================================="
  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. sleep 1
  80. echo " * Any configs may be overwritten."
  81. while true; do
  82. read -e -i "y" -p "Continue? [Y/n]" yn
  83. case $yn in
  84. [Yy]* ) break;;
  85. [Nn]* ) echo Exiting; core_exit.sh;;
  86. * ) echo "Please answer yes or no.";;
  87. esac
  88. done
  89. fn_script_log_info "User selected to continue"
  90. fi
  91. fi
  92. ## Installation
  93. fn_create_mods_dir
  94. fn_mods_clear_tmp_dir
  95. fn_mods_create_tmp_dir
  96. fn_mod_install_files
  97. fn_mod_lowercase
  98. fn_mod_create_filelist
  99. fn_mod_copy_destination
  100. fn_mod_add_list
  101. fn_mod_tidy_files_list
  102. fn_mods_clear_tmp_dir
  103. echo "${modprettyname} installed"
  104. fn_script_log_pass "${modprettyname} installed."
  105. core_exit.sh