command_mods_install.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.
  7. local commandname="MODS"
  8. local commandaction="Mod Installation"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. check.sh
  11. mods_core.sh
  12. mods_list.sh
  13. fn_mods_install_init(){
  14. fn_script_log "Entering mods & addons installation"
  15. echo "================================="
  16. echo "${gamename} mods & addons installation"
  17. echo ""
  18. # Display available mods from mods_list.sh
  19. fn_mods_show_available
  20. echo ""
  21. # Keep prompting as long as the user input doesn't correspond to an available mod
  22. while [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; do
  23. echo -en "Enter a \e[36mmod\e[0m to install (or exit to abort): "
  24. read -r usermodselect
  25. # Exit if user says exit or abort
  26. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  27. fn_script_log "User aborted."
  28. echo "Aborted."
  29. core_exit.sh
  30. # Supplementary output upon invalid user input
  31. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  32. fn_print_error2_nl "${usermodselect} is not a valid mod."
  33. echo " * Enter a valid mod or input exit to abort."
  34. fi
  35. done
  36. # Gives a pretty name to the user and get all mod info
  37. currentmod="${usermodselect}"
  38. fn_mod_get_info_from_command
  39. fn_print_dots_nl "Installing ${modprettyname}"
  40. sleep 1
  41. fn_script_log "Installing ${modprettyname}."
  42. }
  43. # Run all required operation
  44. fn_mod_installation(){
  45. # If a mod was selected
  46. if [ -n "${currentmod}" ]; then
  47. # Get mod info
  48. fn_mod_get_info_from_command
  49. # Check if mod is already installed
  50. fn_mod_already_installed
  51. # Check and create required directories
  52. fn_mods_dir
  53. # Clear lgsm/tmp/mods dir if exists then recreate it
  54. fn_clear_tmp_mods
  55. fn_mods_tmpdir
  56. # Download mod
  57. fn_mod_dl
  58. # Extract the mod
  59. fn_mod_extract
  60. # Build a file list
  61. fn_mod_fileslist
  62. # Copying to destination
  63. fn_mod_copy_destination
  64. # Ending with installation routines
  65. fn_mod_add_list
  66. fn_clear_tmp_mods
  67. fn_print_ok_nl "${modprettyname} installed."
  68. fn_script_log "${modprettyname} installed."
  69. else
  70. fn_print_fail "No mod was selected."
  71. core_exit.sh
  72. fi
  73. }
  74. fn_mods_install_init
  75. fn_mod_installation