command_mods_install.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. # 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 " * \e[1m${green}${modcommand}${default}${default}"
  25. ((totalmodsinstalled++))
  26. done
  27. echo ""
  28. fi
  29. echo "Available addons/mods"
  30. echo "================================="
  31. # Display available mods from mods_list.sh
  32. # Set and reset vars
  33. compatiblemodslistindex=0
  34. # As long as we're within index values
  35. while [ "${compatiblemodslistindex}" -lt "${#compatiblemodslist[@]}" ]; do
  36. # Set values for convenience
  37. displayedmodname="${compatiblemodslist[compatiblemodslistindex]}"
  38. displayedmodcommand="${compatiblemodslist[compatiblemodslistindex+1]}"
  39. displayedmodsite="${compatiblemodslist[compatiblemodslistindex+2]}"
  40. displayedmoddescription="${compatiblemodslist[compatiblemodslistindex+3]}"
  41. # Output mods to the user
  42. echo -e "\e[1m${displayedmodname}${default} - ${displayedmoddescription} - ${displayedmodsite}"
  43. echo -e " * ${cyan}${displayedmodcommand}${default}"
  44. # Increment index from the amount of values we just displayed
  45. let "compatiblemodslistindex+=4"
  46. ((totalmods++))
  47. done
  48. # If no mods are available for a specific game
  49. if [ -z "${compatiblemodslist}" ]; then
  50. fn_print_fail "No mods are currently available for ${gamename}."
  51. fn_script_log_info "No mods are currently available for ${gamename}."
  52. core_exit.sh
  53. fi
  54. fn_script_log_info "${totalmods} addons/mods are available for install"
  55. ## User selects a mod
  56. echo ""
  57. while [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; do
  58. echo -en "Enter an ${cyan}addon/mod${default} to ${green}install${default} (or exit to abort): "
  59. read -r usermodselect
  60. # Exit if user says exit or abort
  61. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  62. core_exit.sh
  63. # Supplementary output upon invalid user input
  64. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  65. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  66. fi
  67. done
  68. # Get mod info
  69. currentmod="${usermodselect}"
  70. fn_mod_get_info
  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_create_mods_dir
  95. fn_mods_clear_tmp_dir
  96. fn_mods_create_tmp_dir
  97. fn_mod_install_files
  98. fn_mod_lowercase
  99. fn_mod_create_filelist
  100. fn_mod_copy_destination
  101. fn_mod_add_list
  102. fn_mod_tidy_files_list
  103. fn_mods_clear_tmp_dir
  104. echo "${modprettyname} installed"
  105. fn_script_log_pass "${modprettyname} installed."
  106. core_exit.sh