command_mods_install.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. if ! read -r usermodselect && [ -z "${usermodselect}" ]; then
  60. echo -e ""
  61. fn_print_error_nl "Unable to read an addon/mod: no input available"
  62. fn_script_log_error "Unable to read an addon/mod: no input available"
  63. exitcode=2
  64. core_exit.sh
  65. fi
  66. # Exit if user says exit or abort.
  67. if [ "${usermodselect}" == "exit" ] || [ "${usermodselect}" == "abort" ]; then
  68. core_exit.sh
  69. fi
  70. validselection=0
  71. for availablemodcommand in "${availablemodscommands[@]}"; do
  72. if [ "${availablemodcommand}" == "${usermodselect}" ]; then
  73. validselection=1
  74. break
  75. fi
  76. done
  77. if [ "${validselection}" -eq 1 ]; then
  78. break
  79. fi
  80. # Supplementary output upon invalid user input.
  81. fn_print_error2_nl "${usermodselect} is not a valid addon/mod."
  82. done
  83. # Get mod info.
  84. currentmod="${usermodselect}"
  85. fn_mod_get_info
  86. echo -e ""
  87. echo -e "Installing ${modprettyname}"
  88. fn_messages_separator
  89. fn_script_log_info "${modprettyname} selected for install"
  90. # Check if the mod is already installed and warn the user.
  91. if [ -f "${modsinstalledlistfullpath}" ]; then
  92. if [ "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
  93. fn_print_warning_nl "${modprettyname} is already installed"
  94. fn_script_log_warn "${modprettyname} is already installed"
  95. echo -e " * Any configs may be overwritten."
  96. if ! fn_prompt_yn "Continue?" Y; then
  97. exitcode=0
  98. core_exit.sh
  99. fi
  100. fn_script_log_info "User selected to continue"
  101. fi
  102. fi
  103. ## Installation.
  104. # CounterStrikeSharp requires Metamod:Source 2.0.
  105. if [ "${modcommand}" == "counterstrikesharp" ]; then
  106. fn_mod_exist "metamodsource2"
  107. fi
  108. # If amxmodx check if metamod exists first
  109. if [ "${modcommand}" == "amxmodx" ]; then
  110. fn_mod_exist "metamod"
  111. fi
  112. if [ "${modcommand}" == "amxmodxcs" ] \
  113. || [ "${modcommand}" == "amxmodxdod" ] \
  114. || [ "${modcommand}" == "amxmodxtfc" ] \
  115. || [ "${modcommand}" == "amxmodxns" ] \
  116. || [ "${modcommand}" == "amxmodxts" ]; then
  117. fn_mod_exist "amxmodx"
  118. fi
  119. # If nolobbyreservation check if sourcemod exists first as it is compiled using the SourceMod compiler
  120. if [ "${modcommand}" == "nolobbyreservation" ]; then
  121. fn_mod_exist "sourcemod"
  122. fi
  123. fn_create_mods_dir
  124. fn_mods_clear_tmp_dir
  125. fn_mods_create_tmp_dir
  126. fn_mod_install_files
  127. fn_mod_lowercase
  128. # NoLobbyReservation is only distributed as source
  129. if [ "${modcommand}" == "nolobbyreservation" ]; then
  130. fn_mod_compile_sourcemod_plugin "nolobbyreservation"
  131. fi
  132. fn_mod_create_filelist
  133. fn_mod_copy_destination
  134. fn_mod_add_list
  135. fn_mod_tidy_files_list
  136. fn_mods_clear_tmp_dir
  137. # Install the Metamod:Source search path for CS2.
  138. if [ "${modcommand}" == "metamodsource2" ]; then
  139. fn_mod_install_gameinfo_gi_file
  140. fi
  141. # Create/modify existing liblist.gam file for Metamod
  142. if [ "${modcommand}" == "metamod" ]; then
  143. fn_mod_install_liblist_gam_file
  144. fi
  145. # Create/modify plugins.ini file for Metamod
  146. if [ "${modcommand}" == "amxmodx" ]; then
  147. fn_mod_install_amxmodx_file
  148. fi
  149. echo -e "${modprettyname} installed"
  150. fn_script_log_pass "${modprettyname} installed."
  151. core_exit.sh