command_mods_install.sh 2.5 KB

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