command_mods_install.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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="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. # Convert to lowercase if needed
  61. fn_mod_lowercase
  62. # Build a file list
  63. fn_mod_fileslist
  64. # Copying to destination
  65. fn_mod_copy_destination
  66. # Ending with installation routines
  67. fn_mod_add_list
  68. # Post install fixes
  69. fn_postinstall_tasks
  70. # Cleaning
  71. fn_clear_tmp_mods
  72. fn_print_ok_nl "${modprettyname} installed"
  73. fn_script_log "${modprettyname} installed."
  74. else
  75. fn_print_fail "No mod was selected"
  76. core_exit.sh
  77. fi
  78. }
  79. fn_mods_install_init
  80. fn_mod_installation