command_mods_install.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. # LGSM 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. # exits if no mods installed
  14. fn_mods_check_installed
  15. # Displays a list of installed mods
  16. fn_mods_installed_list
  17. if [ ${installedmodscount} -gt 0 ]; then
  18. echo "Installed addons/mods"
  19. echo "================================="
  20. # Go through all available commands, get details and display them to the user
  21. for ((llindex=0; llindex < ${#installedmodslist[@]}; llindex++)); do
  22. # Current mod is the "llindex" value of the array we're going through
  23. currentmod="${installedmodslist[llindex]}"
  24. fn_mod_get_info
  25. # Display mod info to the user
  26. echo -e " * \e[1m${green}${modcommand}${default}${default}"
  27. ((totalmodsinstalled++))
  28. done
  29. echo ""
  30. fi
  31. echo "Available addons/mods"
  32. echo "================================="
  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 "\e[1m${displayedmodname}${default} - ${displayedmoddescription} - ${displayedmodsite}"
  45. echo -e " * ${cyan}${displayedmodcommand}${default}"
  46. # Increment index from the amount of values we just displayed
  47. let "compatiblemodslistindex+=4"
  48. ((totalmods++))
  49. done
  50. # If no mods are available for a specific game
  51. if [ -z "${compatiblemodslist}" ]; then
  52. fn_print_fail "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 "${totalmods} addons/mods are available for install"
  57. ## User selects a mod
  58. echo ""
  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. currentmod="${usermodselect}"
  71. echo ""
  72. echo "Installing ${modprettyname}"
  73. echo "================================="
  74. fn_script_log_info "${modprettyname} selected for install"
  75. # Check if the mod is already installed and warn the user
  76. if [ -f "${modsinstalledlistfullpath}" ]; then
  77. if [ -n "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
  78. fn_print_warning_nl "${modprettyname} is already installed"
  79. fn_script_log_warn "${modprettyname} is already installed"
  80. sleep 1
  81. echo " * Any configs may be overwritten."
  82. while true; do
  83. read -e -i "y" -p "Continue? [Y/n]" yn
  84. case $yn in
  85. [Yy]* ) break;;
  86. [Nn]* ) echo Exiting; core_exit.sh;;
  87. * ) echo "Please answer yes or no.";;
  88. esac
  89. done
  90. fi
  91. fn_script_log_info "User selected to continue"
  92. fi
  93. ## Installation
  94. fn_mod_get_info
  95. fn_mod_already_installed
  96. fn_create_mods_dir
  97. fn_mods_clear_tmp_dir
  98. fn_mods_create_tmp_dir
  99. fn_mod_install_files
  100. fn_mod_lowercase
  101. fn_mod_create_filelist
  102. fn_mod_copy_destination
  103. fn_mod_add_list
  104. fn_mod_tidy_files_list
  105. fn_mods_clear_tmp_dir
  106. echo "${modprettyname} installed"
  107. fn_script_log_pass "${modprettyname} installed."
  108. core_exit.sh