mods_list.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #!/bin/bash
  2. # LGSM mods_list.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Lists and defines available mods for LGSM supported servers.
  7. # Usage: To add a mod, you just need to add an array variable into fn_mods_info following the guide to set proper values.
  8. # Usage: Then add this array to the mods_global_array.
  9. # Usage: If needed, you can scrape to define the download URL inside the fn_mods_scrape_urls function.
  10. local commandname="MODS"
  11. local commandaction="List Mods"
  12. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  13. check.sh
  14. ## Useful variables
  15. # Separator name
  16. modseparator="MOD"
  17. # Define mods information (required)
  18. fn_mods_info(){
  19. # REQUIRED: mod_info_name=( MOD "modcommand" "Pretty Name" "URL" "filename" "modsubfolders" "LowercaseOn/Off" "/files/to/keep;" "/install/path" "ENGINES" "GAMES" "NOTGAMES" "AUTHOR_URL" "Short Description" )
  20. # Example 1) Well made mod: mod_info_name=( MOD "awesomemod" "This is an Awesome Mod" "https://awesomemod.com/latest.zip" "awesomemod.zip" "0" "LowercaseOff" "OVERWRITE" "${systemdir}/addons" "source;unity3d;" "GAMES" "NOTGAMES" "https://awesomemod.com/" "This mod knows that 42 is the answer" )
  21. # Example 2) Poorly made mod: mod_info_name=( MOD "stupidmod" "This is a stupid mod" "${crappymodurl}" "StupidMod.zip" "2" "LowercaseOn" "cfg;data/crappymod;" "${systemdir}" "source;" "GAMES" "Garry's mod;Counter-Strike: Source;" "This mod is dumber than dumb" )
  22. # None of those values can be empty
  23. # [index] | Usage
  24. # [0] | MOD: separator, all mods must begin with it
  25. # [1] | "modcommand": the LGSM name and command to install the mod (must be unique and lowercase)
  26. # [2] | "Pretty Name": the common name people use to call the mod that will be displayed to the user
  27. # [3] | "URL": link to the file; can be a variable defined in fn_mods_nasty_urls (make sure curl can download it)
  28. # [4] | "filename": the output filename
  29. # [5] | "modsubfolders": in how many subfolders is the mod (none is 1)
  30. # [6] | "LowercaseOn/Off": LowercaseOff or LowercaseOn: enable/disable converting extracted files and directories to lowercase (some games require it)
  31. # [7] | "modinstalldir": the directory in which to install the mode ( use LGSM dir variables such as ${systemdir})
  32. # [8] | "/files/to/keep;", files & directories that should not be overwritten upon update, separated and ended with a semicolon; you can also use "OVERWRITE" to ignore the value or "NOUPDATE" to disallow updating
  33. # [9] | "Supported Engines;": list them according to LGSM ${engine} variables, separated and ended with a semicolon, or use ENGINES to ignore the value
  34. # [10] | "Supported Games;": list them according to LGSM ${gamename} variables, separated and ended with a semicolon, or use GAMES to ignore the value
  35. # [11] | "Unsupported Games;": list them according to LGSM ${gamename} variables, separated and ended with a semicolon, or use NOTGAMES to ignore the value (useful to exclude a game when using Supported Engines)
  36. # [12] | "AUTHOR_URL" is the author's website, displayed to the user when chosing mods to install
  37. # [13] | "Short Description" a description showed to the user upon installation
  38. # Source mods
  39. mod_info_metamod=( MOD "metamod" "MetaMod" "${metamodurl}" "${metamodlatestfile}" "0" "LowercaseOff" "${systemdir}" "OVERWRITE" "source;" "GAMES" "Garry's Mod;" "https://www.sourcemm.net" "Plugins Framework" )
  40. mod_info_sourcemod=( MOD "sourcemod" "SourceMod" "${sourcemodurl}" "${sourcemodlatestfile}" "0" "LowercaseOff" "${systemdir}" "cfg;" "source;" "GAMES" "Garry's Mod;" "http://www.sourcemod.net" "Admin Features (requires MetaMod)" )
  41. # Garry's Mod Addons
  42. mod_info_ulib=( MOD "ulib" "ULib" "https://codeload.github.com/TeamUlysses/ulib/zip/master" "ulib-master.zip" "0" "LowercaseOff" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "http://ulyssesmod.net" "Complete Framework" )
  43. mod_info_ulx=( MOD "ulx" "ULX" "https://codeload.github.com/TeamUlysses/ulx/zip/master" "ulx-master.zip" "0" "LowercaseOff" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "http://ulyssesmod.net" "Admin Panel (requires ULib)" )
  44. mod_info_utime=( MOD "utime" "UTime" "https://github.com/TeamUlysses/utime/archive/master.zip" "utime-master.zip" "0" "LowercaseOff" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "http://ulyssesmod.net" "Keep track of players play time" )
  45. mod_info_uclip=( MOD "uclip" "UClip" "https://github.com/TeamUlysses/uclip/archive/master.zip" "uclip-master.zip" "0" "LowercaseOff" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "http://ulyssesmod.net" "An alternative to noclip" )
  46. mod_info_acf=( MOD "acf" "Armoured Combat Framework" "https://github.com/nrlulz/ACF/archive/master.zip" "acf-master.zip" "0" "LowercaseOn" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "https://github.com/nrlulz/ACF" "Realistic Wepons & Engines" )
  47. mod_info_acf_missiles=( MOD "acfmissiles" "ACF Missiles" "https://github.com/Bubbus/ACF-Missiles/archive/master.zip" "acf-missiles-master.zip" "0" "LowercaseOn" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "https://github.com/Bubbus/ACF-Missiles" "More missiles for ACF" )
  48. mod_info_acf_advdupe2=( MOD "advdupe2" "Advanced Duplicator 2" "https://github.com/wiremod/advdupe2/archive/master.zip" "advdupe2-master.zip" "0" "LowercaseOn" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "http://www.wiremod.com" "Save your constructions" )
  49. mod_info_darkrp=( MOD "darkrp" "DarkRP" "https://github.com/FPtje/DarkRP/archive/master.zip" "darkrp-master.zip" "0" "LowercaseOn" "${systemdir}/addons" "OVERWRITE" "ENGINES" "Garry's Mod;" "NOTGAMES" "http://darkrp.com" "Most popular gamemode" )
  50. mod_info_darkrpmodification=( MOD "darkrpmodification" "DarkRP Modification" "https://github.com/FPtje/darkrpmodification/archive/master.zip" "darkrpmodification-master.zip" "0" "LowercaseOff" "${systemdir}/addons" "NOUPDATE" "ENGINES" "Garry's Mod;" "NOTGAMES" "http://darkrp.com" "Customize DarkRP settings" )
  51. # Oxidemod
  52. mod_info_rustoxide=( MOD "rustoxide" "Oxide for Rust" "https://raw.githubusercontent.com/OxideMod/Snapshots/master/Oxide-Rust.zip" "Oxide-Rust_Linux.zip" "0" "LowercaseOff" "${systemdir}" "OVERWRITE" "ENGINES" "Rust;" "NOTGAMES" "http://oxidemod.org/downloads/oxide-for-rust.1659" "Allows for the use of plugins" )
  53. mod_info_hwoxide=( MOD "hwoxide" "Oxide for Hurtworld" "https://raw.githubusercontent.com/OxideMod/Snapshots/master/Oxide-Hurtworld.zip" "Oxide-Hurtworld_Linux.zip" "0" "LowercaseOff" "${systemdir}" "OVERWRITE" "ENGINES" "Hurtworld;" "NOTGAMES" "http://oxidemod.org/downloads/oxide-for-hurtworld.1332" "Allows for the use of plugins" )
  54. mod_info_sdtdoxide=( MOD "sdtdoxide" "Oxide for 7 Days To Die" "https://raw.githubusercontent.com/OxideMod/Snapshots/master/Oxide-7DaysToDie.zip" "Oxide-7DaysToDie_Linux.zip" "0" "LowercaseOff" "${systemdir}" "OVERWRITE" "ENGINES" "7 Days To Die;" "NOTGAMES" "http://oxidemod.org/downloads/oxide-for-7-days-to-die.813" "Allows for the use of plugins" )
  55. # REQUIRED: Set all mods info into one array for convenience
  56. mods_global_array=( "${mod_info_metamod[@]}" "${mod_info_sourcemod[@]}" "${mod_info_ulib[@]}" "${mod_info_ulx[@]}" "${mod_info_utime[@]}" "${mod_info_uclip[@]}" "${mod_info_acf[@]}" "${mod_info_acf_missiles[@]}" "${mod_info_acf_sweps[@]}" "${mod_info_advdupe2[@]}" "${mod_info_darkrp[@]}" "${mod_info_darkrpmodification[@]}" "${mod_info_rustoxide[@]}" "${mod_info_hwoxide[@]}" "${mod_info_sdtdoxide[@]}" )
  57. }
  58. # Get a proper URL for mods that don't provide a good one (optional)
  59. fn_mods_scrape_urls(){
  60. # Metamod
  61. metamodscrapeurl="http://www.gsptalk.com/mirror/sourcemod"
  62. metamodlatestfile="$(wget "${metamodscrapeurl}/?MD" -q -O -| grep "mmsource" | grep "\-linux" | head -n1 | awk -F '>' '{ print $3 }' | awk -F '<' '{ print $1}')"
  63. metamodfasterurl="http://cdn.probablyaserver.com/sourcemod/"
  64. metamodurl="${metamodfasterurl}/${metamodlatestfile}"
  65. # Sourcemod
  66. sourcemodmversion="1.8"
  67. sourcemodscrapeurl="http://www.gsptalk.com/mirror/sourcemod"
  68. sourcemodlatestfile="$(wget "${sourcemodscrapeurl}/?MD" -q -O -| grep "sourcemod-" | grep "\-linux" | head -n1 | awk -F '>' '{ print $3 }' | awk -F '<' '{ print $1}')"
  69. sourcemodfasterurl="http://cdn.probablyaserver.com/sourcemod/"
  70. sourcemodurl="${sourcemodfasterurl}/${sourcemodlatestfile}"
  71. }
  72. # Sets some gsm requirements
  73. fn_gsm_requirements(){
  74. # If tmpdir variable doesn't exist, LGSM is too old
  75. if [ -z "${tmpdir}" ]||[ -z "${lgsmdir}" ]; then
  76. fn_print_fail "Your LGSM version is too old."
  77. echo " * Please do a full update, including ${selfname} script."
  78. core_exit.sh
  79. fi
  80. }
  81. # Define all variables from a mod at once when index is set to a separator
  82. fn_mod_info(){
  83. # If for some reason no index is set, none of this can work
  84. if [ -z "$index" ]; then
  85. fn_print_error "index variable not set. Please report an issue to LGSM Team."
  86. echo "* https://github.com/GameServerManagers/LinuxGSM/issues"
  87. core_exit.sh
  88. fi
  89. modcommand="${mods_global_array[index+1]}"
  90. modprettyname="${mods_global_array[index+2]}"
  91. modurl="${mods_global_array[index+3]}"
  92. modfilename="${mods_global_array[index+4]}"
  93. modsubfolders="${mods_global_array[index+5]}"
  94. modlowercase="${mods_global_array[index+6]}"
  95. modinstalldir="${mods_global_array[index+7]}"
  96. modkeepfiles="${mods_global_array[index+8]}"
  97. modengines="${mods_global_array[index+9]}"
  98. modgames="${mods_global_array[index+10]}"
  99. modexcludegames="${mods_global_array[index+11]}"
  100. modsite="${mods_global_array[index+12]}"
  101. moddescription="${mods_global_array[index+13]}"
  102. }
  103. # Find out if a game is compatible with a mod from a modgames (list of games supported by a mod) variable
  104. fn_compatible_mod_games(){
  105. # Reset test value
  106. modcompatiblegame="0"
  107. # If value is set to GAMES (ignore)
  108. if [ "${modgames}" != "GAMES" ]; then
  109. # How many games we need to test
  110. gamesamount="$(echo "${modgames}" | awk -F ';' '{ print NF }')"
  111. # Test all subvalue of "modgames" using the ";" separator
  112. for ((gamevarindex=1; gamevarindex < ${gamesamount}; gamevarindex++)); do
  113. # Put current game name into modtest variable
  114. gamemodtest="$( echo "${modgames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
  115. # If game name matches
  116. if [ "${gamemodtest}" == "${gamename}" ]; then
  117. # Mod is compatible !
  118. modcompatiblegame="1"
  119. fi
  120. done
  121. fi
  122. }
  123. # Find out if an engine is compatible with a mod from a modengines (list of engines supported by a mod) variable
  124. fn_compatible_mod_engines(){
  125. # Reset test value
  126. modcompatibleengine="0"
  127. # If value is set to ENGINES (ignore)
  128. if [ "${modengines}" != "ENGINES" ]; then
  129. # How many engines we need to test
  130. enginesamount="$(echo "${modengines}" | awk -F ';' '{ print NF }')"
  131. # Test all subvalue of "modengines" using the ";" separator
  132. for ((gamevarindex=1; gamevarindex < ${enginesamount}; gamevarindex++)); do
  133. # Put current engine name into modtest variable
  134. enginemodtest="$( echo "${modengines}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
  135. # If engine name matches
  136. if [ "${enginemodtest}" == "${engine}" ]; then
  137. # Mod is compatible !
  138. modcompatibleengine="1"
  139. fi
  140. done
  141. fi
  142. }
  143. # Find out if a game is not compatible with a mod from a modnotgames (list of games not supported by a mod) variable
  144. fn_not_compatible_mod_games(){
  145. # Reset test value
  146. modeincompatiblegame="0"
  147. # If value is set to NOTGAMES (ignore)
  148. if [ "${modexcludegames}" != "NOTGAMES" ]; then
  149. # How many engines we need to test
  150. excludegamesamount="$(echo "${modexcludegames}" | awk -F ';' '{ print NF }')"
  151. # Test all subvalue of "modexcludegames" using the ";" separator
  152. for ((gamevarindex=1; gamevarindex < ${excludegamesamount}; gamevarindex++)); do
  153. # Put current engine name into modtest variable
  154. excludegamemodtest="$( echo "${modexcludegames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
  155. # If engine name matches
  156. if [ "${excludegamemodtest}" == "${gamename}" ]; then
  157. # Mod is compatible !
  158. modeincompatiblegame="1"
  159. fi
  160. done
  161. fi
  162. }
  163. # Sums up if a mod is compatible or not with modcompatibility=0/1
  164. fn_mod_compatible_test(){
  165. # Test game and engine compatibility
  166. fn_compatible_mod_games
  167. fn_compatible_mod_engines
  168. fn_not_compatible_mod_games
  169. if [ "${modeincompatiblegame}" == "1" ]; then
  170. modcompatibility="0"
  171. elif [ "${modcompatibleengine}" == "1" ]||[ "${modcompatiblegame}" == "1" ]; then
  172. modcompatibility="1"
  173. else
  174. modcompatibility="0"
  175. fi
  176. }
  177. # Checks if a mod is compatibile for installation
  178. # Provides available mods for installation
  179. # Provides commands for mods installation
  180. fn_mods_available(){
  181. # First, reset variables
  182. compatiblemodslist=()
  183. availablemodscommands=()
  184. modprettynamemaxlength="0"
  185. modsitemaxlength="0"
  186. moddescriptionmaxlength="0"
  187. modcommandmaxlength="0"
  188. # Find compatible games
  189. # Find separators through the global array
  190. for ((index="0"; index <= ${#mods_global_array[@]}; index++)); do
  191. # If current value is a separator; then
  192. if [ "${mods_global_array[index]}" == "${modseparator}" ]; then
  193. # Set mod variables
  194. fn_mod_info
  195. # Test if game is compatible
  196. fn_mod_compatible_test
  197. # If game is compatible
  198. if [ "${modcompatibility}" == "1" ]; then
  199. # Put it into the list to display to the user
  200. compatiblemodslist+=( "${modprettyname}" "${modcommand}" "${modsite}" "${moddescription}" )
  201. # Keep available commands in an array
  202. availablemodscommands+=( "${modcommand}" )
  203. fi
  204. fi
  205. done
  206. }
  207. # Output available mods in a nice way to the user
  208. fn_mods_show_available(){
  209. # Set and reset vars
  210. compatiblemodslistindex=0
  211. spaces=" "
  212. # As long as we're within index values
  213. while [ "${compatiblemodslistindex}" -lt "${#compatiblemodslist[@]}" ]; do
  214. # Set values for convenience
  215. displayedmodname="${compatiblemodslist[compatiblemodslistindex]}"
  216. displayedmodcommand="${compatiblemodslist[compatiblemodslistindex+1]}"
  217. displayedmodsite="${compatiblemodslist[compatiblemodslistindex+2]}"
  218. displayedmoddescription="${compatiblemodslist[compatiblemodslistindex+3]}"
  219. # Output mods to the user
  220. echo -e "\e[1m${displayedmodname}\e[0m - ${displayedmoddescription} - ${displayedmodsite}"
  221. echo -e " * \e[36m${displayedmodcommand}\e[0m"
  222. # Increment index from the amount of values we just displayed
  223. let "compatiblemodslistindex+=4"
  224. done
  225. # If no mods are found
  226. if [ -z "${compatiblemodslist}" ]; then
  227. fn_print_fail "No mods are currently available for ${gamename}."
  228. core_exit.sh
  229. fi
  230. }
  231. # Get details of a mod any (relevant and unique, such as full mod name or install command) value
  232. fn_mod_get_info_from_command(){
  233. # Variable to know when job is done
  234. modinfocommand="0"
  235. # Find entry in global array
  236. for ((index=0; index <= ${#mods_global_array[@]}; index++)); do
  237. # When entry is found
  238. if [ "${mods_global_array[index]}" == "${currentmod}" ]; then
  239. # Go back to the previous "MOD" separator
  240. for ((index=index; index <= ${#mods_global_array[@]}; index--)); do
  241. # When "MOD" is found
  242. if [ "${mods_global_array[index]}" == "MOD" ]; then
  243. # Get info
  244. fn_mod_info
  245. modinfocommand="1"
  246. break
  247. fi
  248. done
  249. fi
  250. # Exit the loop if job is done
  251. if [ "${modinfocommand}" == "1" ]; then
  252. break
  253. fi
  254. done
  255. }
  256. fn_gsm_requirements
  257. fn_mods_scrape_urls
  258. fn_mods_info
  259. fn_mods_available