command_mods_install.sh 2.5 KB

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