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="addons/mods"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. check.sh
  11. mods_core.sh
  12. fn_mods_install_init(){
  13. fn_print_header
  14. # Display installed mods
  15. fn_installed_mods_light_list
  16. echo "Available addons/mods"
  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 an ${cyan}addon/mod${default} to ${green}install${default} (or exit to abort): "
  24. read -r usermodselect
  25. # Exit if user says exit or abort
  26. if [ "${usermodselect}" == "exit" ]||[ "${usermodselect}" == "abort" ]; then
  27. core_exit.sh
  28. # Supplementary output upon invalid user input
  29. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  30. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  31. fi
  32. done
  33. # Gives a pretty name to the user and get all mod info
  34. currentmod="${usermodselect}"
  35. fn_mod_get_info_from_command
  36. fn_print_dots_nl "Installing ${modprettyname}"
  37. sleep 1
  38. fn_script_log "Installing ${modprettyname}."
  39. }
  40. # Run all required operation
  41. fn_mod_installation(){
  42. # If a mod was selected
  43. if [ -n "${currentmod}" ]; then
  44. # Get mod info
  45. fn_mod_get_info_from_command
  46. # Check if mod is already installed
  47. fn_mod_already_installed
  48. # Check and create required files
  49. fn_mods_files
  50. # Clear lgsm/tmp/mods dir if exists then recreate it
  51. fn_clear_tmp_mods
  52. fn_mods_tmpdir
  53. # Download mod
  54. fn_mod_dl
  55. # Extract the mod
  56. fn_mod_extract
  57. # Convert to lowercase if needed
  58. fn_mod_lowercase
  59. # Build a file list
  60. fn_mod_fileslist
  61. # Copying to destination
  62. fn_mod_copy_destination
  63. # Ending with installation routines
  64. fn_mod_add_list
  65. # Post install fixes
  66. fn_postinstall_tasks
  67. # Cleaning
  68. fn_clear_tmp_mods
  69. fn_print_ok_nl "${modprettyname} installed"
  70. fn_script_log "${modprettyname} installed."
  71. else
  72. fn_print_fail "No addon/mod was selected"
  73. exitcode="1"
  74. core_exit.sh
  75. fi
  76. }
  77. fn_mods_install_init
  78. fn_mod_installation
  79. core_exit.sh