command_mods_install.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. # LinuxGSM command_mods_install.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: List and installs available mods along with mods_list.sh and mods_core.sh.
  7. commandname="MODS-INSTALL"
  8. commandaction="Installing Mods"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. check.sh
  12. mods_core.sh
  13. fn_print_header
  14. # Displays a list of installed mods.
  15. fn_mods_installed_list
  16. if [ "${installedmodscount}" -gt "0" ]; then
  17. echo -e "Installed addons/mods"
  18. fn_messages_separator
  19. # Go through all available commands, get details and display them to the user.
  20. for ((llindex = 0; llindex < ${#installedmodslist[@]}; llindex++)); do
  21. # Current mod is the "llindex" value of the array we're going through.
  22. currentmod="${installedmodslist[llindex]}"
  23. fn_mod_get_info
  24. # Display mod info to the user.
  25. echo -e " * ${green}${modcommand}${default}${default}"
  26. done
  27. echo -e ""
  28. fi
  29. echo -e "Available addons/mods"
  30. fn_messages_separator
  31. # Display available mods from mods_list.sh.
  32. # Set and reset vars
  33. compatiblemodslistindex=0
  34. # As long as we're within index values.
  35. while [ "${compatiblemodslistindex}" -lt "${#compatiblemodslist[@]}" ]; do
  36. # Set values for convenience.
  37. displayedmodname="${compatiblemodslist[compatiblemodslistindex]}"
  38. displayedmodcommand="${compatiblemodslist[compatiblemodslistindex + 1]}"
  39. displayedmodsite="${compatiblemodslist[compatiblemodslistindex + 2]}"
  40. displayedmoddescription="${compatiblemodslist[compatiblemodslistindex + 3]}"
  41. # Output mods to the user.
  42. echo -e "${displayedmodname} - ${displayedmoddescription} - ${displayedmodsite}"
  43. echo -e " * ${cyan}${displayedmodcommand}${default}"
  44. # Increment index from the amount of values we just displayed.
  45. let "compatiblemodslistindex+=4"
  46. ((totalmodsavailable++))
  47. done
  48. # If no mods are available for a specific game.
  49. if [ -z "${compatiblemodslist}" ]; then
  50. fn_print_fail_nl "No mods are currently available for ${gamename}."
  51. fn_script_log_info "No mods are currently available for ${gamename}."
  52. core_exit.sh
  53. fi
  54. fn_script_log_info "${totalmodsavailable} addons/mods are available for install"
  55. ## User selects a mod.
  56. echo -e ""
  57. while [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; do
  58. echo -en "Enter an ${cyan}addon/mod${default} to ${green}install${default} (or exit to abort): "
  59. read -r usermodselect
  60. # Exit if user says exit or abort.
  61. if [ "${usermodselect}" == "exit" ] || [ "${usermodselect}" == "abort" ]; then
  62. core_exit.sh
  63. # Supplementary output upon invalid user input.
  64. elif [[ ! " ${availablemodscommands[@]} " =~ " ${usermodselect} " ]]; then
  65. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  66. fi
  67. done
  68. # Get mod info.
  69. currentmod="${usermodselect}"
  70. fn_mod_get_info
  71. echo -e ""
  72. echo -e "Installing ${modprettyname}"
  73. fn_messages_separator
  74. fn_script_log_info "${modprettyname} selected for install"
  75. # Check if the mod is already installed and warn the user.
  76. if [ -f "${modsinstalledlistfullpath}" ]; then
  77. if [ "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
  78. fn_print_warning_nl "${modprettyname} is already installed"
  79. fn_script_log_warn "${modprettyname} is already installed"
  80. echo -e " * Any configs may be overwritten."
  81. if ! fn_prompt_yn "Continue?" Y; then
  82. core_exit.sh
  83. fi
  84. fn_script_log_info "User selected to continue"
  85. fi
  86. fi
  87. ## Installation.
  88. # If amxmodx check if metamod exists first
  89. if [ "${modcommand}" == "amxmodx" ]; then
  90. fn_mod_exist "metamod"
  91. fi
  92. if [ "${modcommand}" == "amxmodxcs" ] \
  93. || [ "${modcommand}" == "amxmodxdod" ] \
  94. || [ "${modcommand}" == "amxmodxtfc" ] \
  95. || [ "${modcommand}" == "amxmodxns" ] \
  96. || [ "${modcommand}" == "amxmodxts" ]; then
  97. fn_mod_exist "amxmodx"
  98. fi
  99. fn_create_mods_dir
  100. fn_mods_clear_tmp_dir
  101. fn_mods_create_tmp_dir
  102. fn_mod_install_files
  103. fn_mod_lowercase
  104. fn_mod_create_filelist
  105. fn_mod_copy_destination
  106. fn_mod_add_list
  107. fn_mod_tidy_files_list
  108. fn_mods_clear_tmp_dir
  109. # Create/modify existing liblist.gam file for Metamod
  110. if [ "${modcommand}" == "metamod" ]; then
  111. fn_mod_install_liblist_gam_file
  112. fi
  113. # Create/modify plugins.ini file for Metamod
  114. if [ "${modcommand}" == "amxmodx" ]; then
  115. fn_mod_install_amxmodx_file
  116. fi
  117. echo -e "${modprettyname} installed"
  118. fn_script_log_pass "${modprettyname} installed."
  119. core_exit.sh