4
0

command_mods_install.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. ((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 :; 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. fi
  64. validselection=0
  65. for availablemodcommand in "${availablemodscommands[@]}"; do
  66. if [ "${availablemodcommand}" == "${usermodselect}" ]; then
  67. validselection=1
  68. break
  69. fi
  70. done
  71. if [ "${validselection}" -eq 1 ]; then
  72. break
  73. fi
  74. # Supplementary output upon invalid user input.
  75. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  76. done
  77. # Get mod info.
  78. currentmod="${usermodselect}"
  79. fn_mod_get_info
  80. echo -e ""
  81. echo -e "Installing ${modprettyname}"
  82. fn_messages_separator
  83. fn_script_log_info "${modprettyname} selected for install"
  84. # Check if the mod is already installed and warn the user.
  85. if [ -f "${modsinstalledlistfullpath}" ]; then
  86. if [ "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
  87. fn_print_warning_nl "${modprettyname} is already installed"
  88. fn_script_log_warn "${modprettyname} is already installed"
  89. echo -e " * Any configs may be overwritten."
  90. if ! fn_prompt_yn "Continue?" Y; then
  91. exitcode=0
  92. core_exit.sh
  93. fi
  94. fn_script_log_info "User selected to continue"
  95. fi
  96. fi
  97. ## Installation.
  98. # If amxmodx check if metamod exists first
  99. if [ "${modcommand}" == "amxmodx" ]; then
  100. fn_mod_exist "metamod"
  101. fi
  102. if [ "${modcommand}" == "amxmodxcs" ] \
  103. || [ "${modcommand}" == "amxmodxdod" ] \
  104. || [ "${modcommand}" == "amxmodxtfc" ] \
  105. || [ "${modcommand}" == "amxmodxns" ] \
  106. || [ "${modcommand}" == "amxmodxts" ]; then
  107. fn_mod_exist "amxmodx"
  108. fi
  109. fn_create_mods_dir
  110. fn_mods_clear_tmp_dir
  111. fn_mods_create_tmp_dir
  112. fn_mod_install_files
  113. fn_mod_lowercase
  114. fn_mod_create_filelist
  115. fn_mod_copy_destination
  116. fn_mod_add_list
  117. fn_mod_tidy_files_list
  118. fn_mods_clear_tmp_dir
  119. # Create/modify existing liblist.gam file for Metamod
  120. if [ "${modcommand}" == "metamod" ]; then
  121. fn_mod_install_liblist_gam_file
  122. fi
  123. # Create/modify plugins.ini file for Metamod
  124. if [ "${modcommand}" == "amxmodx" ]; then
  125. fn_mod_install_amxmodx_file
  126. fi
  127. echo -e "${modprettyname} installed"
  128. fn_script_log_pass "${modprettyname} installed."
  129. core_exit.sh