mods_core.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. #!/bin/bash
  2. # LGSM command_mods_install.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Core functions for mods list/install/update/remove
  7. local commandname="MODS"
  8. local commandaction="addons/mods"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. ## Useful variables
  11. # Files and Directories
  12. modsdir="${lgsmdir}/mods"
  13. modstmpdir="${modsdir}/tmp"
  14. extractdir="${modstmpdir}/extract"
  15. modsdatadir="${modsdir}"
  16. modslockfile="installed-mods-listing"
  17. modslockfilefullpath="${modsdatadir}/${modslockfile}"
  18. # Database initialisation
  19. mods_list.sh
  20. # Sets some lgsm requirements
  21. fn_lgsm_requirements(){
  22. # If tmpdir variable doesn't exist, LGSM is too old
  23. if [ -z "${tmpdir}" ]||[ -z "${lgsmdir}" ]; then
  24. fn_print_fail "Your LinuxGSM version is too old."
  25. echo " * Please do a full update, including ${selfname} script."
  26. core_exit.sh
  27. fi
  28. }
  29. # Create mods files and directories if it doesn't exist
  30. # Assuming the game is already installed as mods_list.sh checked for it.
  31. fn_mods_files(){
  32. if [ ! -d "${modinstalldir}" ]; then
  33. fn_script_log_info "Creating mods directory: ${modinstalldir}"
  34. echo "Creating mods directory"
  35. sleep 0.5
  36. mkdir -pv "${modinstalldir}"
  37. fi
  38. # Create data/mods directory
  39. if [ ! -d "${modsdatadir}" ]; then
  40. mkdir -p "${modsdatadir}"
  41. fn_script_log "Created ${modsdatadir}"
  42. fi
  43. # Create lgsm/data/${modslockfile}
  44. if [ ! -f "${modslockfilefullpath}" ]; then
  45. touch "${modslockfilefullpath}"
  46. fn_script_log "Created ${modslockfilefullpath}"
  47. fi
  48. }
  49. # Clear mod download directory so that there is only one file in it since we don't know the file name and extention
  50. fn_clear_tmp_mods(){
  51. if [ -d "${modstmpdir}" ]; then
  52. rm -r "${modstmpdir}"
  53. fn_script_log "Clearing mod download directory: ${modstmpdir}"
  54. fi
  55. # Clear temp file list as well
  56. if [ -f "${modsdatadir}/.removedfiles.tmp" ]; then
  57. rm "${modsdatadir}/.removedfiles.tmp"
  58. fi
  59. }
  60. # Create tmp download mod directory
  61. fn_mods_tmpdir(){
  62. if [ ! -d "${modstmpdir}" ]; then
  63. mkdir -p "${modstmpdir}"
  64. fn_script_log "Creating mod download directory: ${modstmpdir}"
  65. fi
  66. }
  67. fn_install_mod_dl_extract(){
  68. fn_fetch_file "${modurl}" "${modstmpdir}" "${modfilename}"
  69. # Check if variable is valid checking if file has been downloaded and exists
  70. if [ ! -f "${modstmpdir}/${modfilename}" ]; then
  71. fn_print_failure "An issue occurred upon downloading ${modprettyname}"
  72. core_exit.sh
  73. fi
  74. if [ ! -d "${extractdir}" ]; then
  75. mkdir -p "${extractdir}"
  76. fi
  77. fn_dl_extract "${modstmpdir}" "${filename}" "${extractdir}"
  78. }
  79. # Convert mod files to lowercase if needed
  80. fn_mod_lowercase(){
  81. if [ "${modlowercase}" == "LowercaseOn" ]; then
  82. echo -ne "converting ${modprettyname} files to lowercase..."
  83. sleep 0.5
  84. fn_script_log "Converting ${modprettyname} files to lowercase"
  85. files=$(find "${extractdir}" -depth | wc -l)
  86. echo -en "\r"
  87. while read SRC; do
  88. DST=`dirname "${SRC}"`/`basename "${SRC}" | tr '[A-Z]' '[a-z]'`
  89. if [ "${SRC}" != "${DST}" ]
  90. then
  91. [ ! -e "${DST}" ] && mv -T "${SRC}" "${DST}" || echo "${SRC} was not renamed"
  92. ((renamedwc++))
  93. fi
  94. echo -ne "${renamedwc} / ${totalfileswc} / $files converting ${modprettyname} files to lowercase..." $'\r'
  95. ((totalfileswc++))
  96. done < <(find "${extractdir}" -depth)
  97. echo -ne "${renamedwc} / ${totalfileswc} / $files converting ${modprettyname} files to lowercase..."
  98. local exitcode=$?
  99. if [ ${exitcode} -ne 0 ]; then
  100. fn_print_fail_eol_nl
  101. else
  102. fn_print_ok_eol_nl
  103. fi
  104. sleep 0.5
  105. fi
  106. }
  107. # Don't overwrite specified files upon update (set by ${modkeepfiles})
  108. # For that matter, remove cfg files after extraction before copying them to destination
  109. fn_remove_cfg_files(){
  110. if [ "${modkeepfiles}" != "OVERWRITE" ]&&[ "${modkeepfiles}" != "NOUPDATE" ]; then
  111. fn_print_dots "Allow for not overwriting ${modprettyname} config files"
  112. fn_script_log "Allow for not overwriting ${modprettyname} config files"
  113. sleep 0.5
  114. # Let's count how many files there are to remove
  115. removefilesamount="$(echo "${modkeepfiles}" | awk -F ';' '{ print NF }')"
  116. # Test all subvalue of "modkeepfiles" using the ";" separator
  117. for ((removefilesindex=1; removefilesindex < ${removefilesamount}; removefilesindex++)); do
  118. # Put current file we're looking for into a variable
  119. filetoremove="$( echo "${modkeepfiles}" | awk -F ';' -v x=${removefilesindex} '{ print $x }' )"
  120. # If it matches an existing file that have been extracted
  121. if [ -f "${extractdir}/${filetoremove}" ]||[ -d "${extractdir}/${filetoremove}" ]; then
  122. # Then delete the file!
  123. rm -r "${extractdir}/${filetoremove}"
  124. # Write this file path in a tmp file, to rebuild a full file list since it is rebuilt upon update
  125. if [ ! -f "${modsdatadir}/.removedfiles.tmp" ]; then
  126. touch "${modsdatadir}/.removedfiles.tmp"
  127. fi
  128. echo "${filetoremove}" >> "${modsdatadir}/.removedfiles.tmp"
  129. fi
  130. done
  131. fn_print_ok "Allow for preserving ${modprettyname} config files"
  132. sleep 0.5
  133. fi
  134. }
  135. # Create ${modcommand}-files.txt containing the full extracted file/directory list
  136. fn_mod_fileslist(){
  137. echo -ne "building ${modcommand}-files.txt..."
  138. fn_script_log "Building ${modcommand}-files.txt"
  139. sleep 0.5
  140. # ${modsdatadir}/${modcommand}-files.txt
  141. find "${extractdir}" -mindepth 1 -printf '%P\n' > "${modsdatadir}"/${modcommand}-files.txt
  142. local exitcode=$?
  143. if [ ${exitcode} -ne 0 ]; then
  144. fn_print_fail_eol_nl
  145. else
  146. fn_print_ok_eol_nl
  147. fi
  148. fn_script_log "Writing file list: ${modsdatadir}/${modcommand}-files.txt}"
  149. # Adding removed files if needed
  150. if [ -f "${modsdatadir}/.removedfiles.tmp" ]; then
  151. cat "${modsdatadir}/.removedfiles.tmp" >> "${modsdatadir}"/${modcommand}-files.txt
  152. fi
  153. sleep 0.5
  154. }
  155. # Copy the mod to the destination ${modinstalldir}
  156. fn_mod_copy_destination(){
  157. echo -ne "copying ${modprettyname} to ${modinstalldir}..."
  158. fn_script_log "Copying ${modprettyname} to ${modinstalldir}"
  159. sleep 0.5
  160. cp -Rf "${extractdir}/." "${modinstalldir}/"
  161. local exitcode=$?
  162. if [ ${exitcode} -ne 0 ]; then
  163. fn_print_fail_eol_nl
  164. else
  165. fn_print_ok_eol_nl
  166. fi
  167. }
  168. # Check if the mod is already installed and warn the user
  169. fn_mod_already_installed(){
  170. if [ -f "${modslockfilefullpath}" ]; then
  171. if [ -n "$(sed -n "/^${modcommand}$/p" "${modslockfilefullpath}")" ]; then
  172. fn_print_warning_nl "${modprettyname} has already been installed"
  173. sleep 1
  174. echo " * Config files, if any, might be overwritten."
  175. while true; do
  176. read -e -i "y" -p "Continue? [Y/n]" yn
  177. case $yn in
  178. [Yy]* ) break;;
  179. [Nn]* ) echo Exiting; core_exit.sh;;
  180. * ) echo "Please answer yes or no.";;
  181. esac
  182. done
  183. fi
  184. fn_script_log "${modprettyname} is already installed, overwriting any file."
  185. fi
  186. }
  187. # Add the mod to the installed mods list
  188. fn_mod_add_list(){
  189. # Append modname to lockfile if it's not already in it
  190. if [ ! -n "$(sed -n "/^${modcommand}$/p" "${modslockfilefullpath}")" ]; then
  191. echo "${modcommand}" >> "${modslockfilefullpath}"
  192. fn_script_log "${modcommand} added to ${modslockfile}"
  193. fi
  194. }
  195. fn_check_files_list(){
  196. # File list must exist and be valid before any operation on it
  197. if [ -f "${modsdatadir}/${modcommand}-files.txt" ]; then
  198. # How many lines is the file list
  199. modsfilelistsize="$(cat "${modsdatadir}/${modcommand}-files.txt" | wc -l)"
  200. # If file list is empty
  201. if [ $modsfilelistsize -eq 0 ]; then
  202. fn_print_error_nl "${modcommand}-files.txt is empty"
  203. echo "Exiting."
  204. fn_scrip_log_fatal "${modcommand}-files.txt is empty"
  205. exitcode="2"
  206. core_exit.sh
  207. fi
  208. else
  209. fn_print_error_nl "${modsdatadir}/${modcommand}-files.txt don't exist"
  210. echo "Exiting."
  211. fn_scrip_log_fatal "${modsdatadir}/${modcommand}-files.txt don't exist"
  212. exitcode="2"
  213. core_exit.sh
  214. fi
  215. }
  216. # Apply some post-install fixes to make sure everything will be fine
  217. fn_postinstall_tasks(){
  218. # Prevent sensitive directories from being erased upon uninstall by removing them from: ${modsdatadir}/${modcommand}-files.txt
  219. # Check file validity
  220. fn_check_files_list
  221. # Output to the user
  222. echo -ne "tidy up ${modcommand}-files.txt..."
  223. sleep 0.5
  224. fn_script_log_info "Rearranging ${modcommand}-files.txt"
  225. # What lines/files to remove from file list (end var with a ";" separator)
  226. removefromlist="cfg;addons;"
  227. # Loop through files to remove from file list,
  228. # that way these files won't get removed upon uninstall
  229. # How many elements to remove from list
  230. removefromlistamount="$(echo "${removefromlist}" | awk -F ';' '{ print NF }')"
  231. # Test all subvalue of "removefromlist" using the ";" separator
  232. for ((filesindex=1; filesindex < ${removefromlistamount}; filesindex++)); do
  233. # Put current file into test variable
  234. removefilevar="$( echo "${removefromlist}" | awk -F ';' -v x=${filesindex} '{ print $x }' )"
  235. # Then delete matching line(s)!
  236. sed -i "/^${removefilevar}$/d" "${modsdatadir}/${modcommand}-files.txt"
  237. local exitcode=$?
  238. if [ ${exitcode} -ne 0 ]; then
  239. break
  240. fi
  241. done
  242. if [ ${exitcode} -ne 0 ]; then
  243. fn_print_fail_eol_nl
  244. else
  245. fn_print_ok_eol_nl
  246. fi
  247. # Sourcemod fix
  248. # Remove metamod from sourcemod fileslist
  249. if [ "${modcommand}" == "sourcemod" ]; then
  250. # Remove addons/metamod & addons/metamod/sourcemod.vdf from ${modcommand}-files.txt
  251. sed -i "/^addons\/metamod$/d" "${modsdatadir}/${modcommand}-files.txt"
  252. sed -i "/^addons\/metamod\/sourcemod.vdf$/d" "${modsdatadir}/${modcommand}-files.txt"
  253. fi
  254. }
  255. # Apply some post-uninstall fixes to make sure everything will be fine
  256. fn_postuninstall_tasks(){
  257. # Oxide fix
  258. # Oxide replaces server files, so a validate is required after uninstall
  259. if [ "${engine}" == "unity3d" ]&&[[ "${modprettyname}" == *"Oxide"* ]]; then
  260. fn_print_information_nl "Validating to restore original ${gamename} files replaced by Oxide"
  261. fn_script_log "Validating to restore original ${gamename} files replaced by Oxide"
  262. exitbypass="1"
  263. command_validate.sh
  264. unset exitbypass
  265. fi
  266. }
  267. #########################
  268. ## mods_list.sh arrays ##
  269. #########################
  270. ## Define info for a mod
  271. # Define all variables from a mod at once when index is set to a separator
  272. fn_mod_info(){
  273. # If for some reason no index is set, none of this can work
  274. if [ -z "$index" ]; then
  275. fn_print_error "index variable not set. Please report an issue to LGSM Team."
  276. echo "* https://github.com/GameServerManagers/LinuxGSM/issues"
  277. exitcode="1"
  278. core_exit.sh
  279. fi
  280. modcommand="${mods_global_array[index+1]}"
  281. modprettyname="${mods_global_array[index+2]}"
  282. modurl="${mods_global_array[index+3]}"
  283. modfilename="${mods_global_array[index+4]}"
  284. modsubdirs="${mods_global_array[index+5]}"
  285. modlowercase="${mods_global_array[index+6]}"
  286. modinstalldir="${mods_global_array[index+7]}"
  287. modkeepfiles="${mods_global_array[index+8]}"
  288. modengines="${mods_global_array[index+9]}"
  289. modgames="${mods_global_array[index+10]}"
  290. modexcludegames="${mods_global_array[index+11]}"
  291. modsite="${mods_global_array[index+12]}"
  292. moddescription="${mods_global_array[index+13]}"
  293. }
  294. ## Mod compatibility check
  295. # Find out if a game is compatible with a mod from a modgames (list of games supported by a mod) variable
  296. fn_compatible_mod_games(){
  297. # Reset test value
  298. modcompatiblegame="0"
  299. # If value is set to GAMES (ignore)
  300. if [ "${modgames}" != "GAMES" ]; then
  301. # How many games we need to test
  302. gamesamount="$(echo "${modgames}" | awk -F ';' '{ print NF }')"
  303. # Test all subvalue of "modgames" using the ";" separator
  304. for ((gamevarindex=1; gamevarindex < ${gamesamount}; gamevarindex++)); do
  305. # Put current game name into modtest variable
  306. gamemodtest="$( echo "${modgames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
  307. # If game name matches
  308. if [ "${gamemodtest}" == "${gamename}" ]; then
  309. # Mod is compatible !
  310. modcompatiblegame="1"
  311. fi
  312. done
  313. fi
  314. }
  315. # Find out if an engine is compatible with a mod from a modengines (list of engines supported by a mod) variable
  316. fn_compatible_mod_engines(){
  317. # Reset test value
  318. modcompatibleengine="0"
  319. # If value is set to ENGINES (ignore)
  320. if [ "${modengines}" != "ENGINES" ]; then
  321. # How many engines we need to test
  322. enginesamount="$(echo "${modengines}" | awk -F ';' '{ print NF }')"
  323. # Test all subvalue of "modengines" using the ";" separator
  324. for ((gamevarindex=1; gamevarindex < ${enginesamount}; gamevarindex++)); do
  325. # Put current engine name into modtest variable
  326. enginemodtest="$( echo "${modengines}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
  327. # If engine name matches
  328. if [ "${enginemodtest}" == "${engine}" ]; then
  329. # Mod is compatible !
  330. modcompatibleengine="1"
  331. fi
  332. done
  333. fi
  334. }
  335. # Find out if a game is not compatible with a mod from a modnotgames (list of games not supported by a mod) variable
  336. fn_not_compatible_mod_games(){
  337. # Reset test value
  338. modeincompatiblegame="0"
  339. # If value is set to NOTGAMES (ignore)
  340. if [ "${modexcludegames}" != "NOTGAMES" ]; then
  341. # How many engines we need to test
  342. excludegamesamount="$(echo "${modexcludegames}" | awk -F ';' '{ print NF }')"
  343. # Test all subvalue of "modexcludegames" using the ";" separator
  344. for ((gamevarindex=1; gamevarindex < ${excludegamesamount}; gamevarindex++)); do
  345. # Put current engine name into modtest variable
  346. excludegamemodtest="$( echo "${modexcludegames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )"
  347. # If engine name matches
  348. if [ "${excludegamemodtest}" == "${gamename}" ]; then
  349. # Mod is compatible !
  350. modeincompatiblegame="1"
  351. fi
  352. done
  353. fi
  354. }
  355. # Sums up if a mod is compatible or not with modcompatibility=0/1
  356. fn_mod_compatible_test(){
  357. # Test game and engine compatibility
  358. fn_compatible_mod_games
  359. fn_compatible_mod_engines
  360. fn_not_compatible_mod_games
  361. if [ "${modeincompatiblegame}" == "1" ]; then
  362. modcompatibility="0"
  363. elif [ "${modcompatibleengine}" == "1" ]||[ "${modcompatiblegame}" == "1" ]; then
  364. modcompatibility="1"
  365. else
  366. modcompatibility="0"
  367. fi
  368. }
  369. # Checks if a mod is compatibile for installation
  370. # Provides available mods for installation
  371. # Provides commands for mods installation
  372. fn_mods_available(){
  373. # First, reset variables
  374. compatiblemodslist=()
  375. availablemodscommands=()
  376. modprettynamemaxlength="0"
  377. modsitemaxlength="0"
  378. moddescriptionmaxlength="0"
  379. modcommandmaxlength="0"
  380. # Find compatible games
  381. # Find separators through the global array
  382. for ((index="0"; index <= ${#mods_global_array[@]}; index++)); do
  383. # If current value is a separator; then
  384. if [ "${mods_global_array[index]}" == "${modseparator}" ]; then
  385. # Set mod variables
  386. fn_mod_info
  387. # Test if game is compatible
  388. fn_mod_compatible_test
  389. # If game is compatible
  390. if [ "${modcompatibility}" == "1" ]; then
  391. # Put it into an array to prepare user output
  392. compatiblemodslist+=( "${modprettyname}" "${modcommand}" "${modsite}" "${moddescription}" )
  393. # Keep available commands in an array to make life easier
  394. availablemodscommands+=( "${modcommand}" )
  395. fi
  396. fi
  397. done
  398. }
  399. # Output available mods in a nice way to the user
  400. fn_mods_show_available(){
  401. # Set and reset vars
  402. compatiblemodslistindex=0
  403. # As long as we're within index values
  404. while [ "${compatiblemodslistindex}" -lt "${#compatiblemodslist[@]}" ]; do
  405. # Set values for convenience
  406. displayedmodname="${compatiblemodslist[compatiblemodslistindex]}"
  407. displayedmodcommand="${compatiblemodslist[compatiblemodslistindex+1]}"
  408. displayedmodsite="${compatiblemodslist[compatiblemodslistindex+2]}"
  409. displayedmoddescription="${compatiblemodslist[compatiblemodslistindex+3]}"
  410. # Output mods to the user
  411. echo -e "\e[1m${displayedmodname}${default} - ${displayedmoddescription} - ${displayedmodsite}"
  412. echo -e " * ${cyan}${displayedmodcommand}${default}"
  413. # Increment index from the amount of values we just displayed
  414. let "compatiblemodslistindex+=4"
  415. done
  416. # If no mods are found
  417. if [ -z "${compatiblemodslist}" ]; then
  418. fn_print_fail "No mods are currently available for ${gamename}."
  419. core_exit.sh
  420. fi
  421. }
  422. # Checks if mods have been installed
  423. # Also returns ${installedmodscount} if mods were found
  424. fn_check_installed_mods(){
  425. # Count installed mods
  426. if [ -f "${modslockfilefullpath}" ]; then
  427. installedmodscount="$(cat "${modslockfilefullpath}" | wc -l)"
  428. fi
  429. }
  430. # A simple function to exit if no mods were installed
  431. # Also returns ${installedmodscount} if mods were found
  432. fn_mods_exit_if_not_installed(){
  433. # Checks if mods have been installed
  434. # Also returns ${installedmodscount} if mods were found
  435. fn_check_installed_mods
  436. # If no mods lockfile is found or if it is empty
  437. if [ ! -f "${modslockfilefullpath}" ]||[ -z "${installedmodscount}" ]||[ ${installedmodscount} -le 0 ]; then
  438. fn_print_information_nl "No installed mods or addons were found"
  439. echo " * Install mods using LGSM first with: ./${selfname} mods-install"
  440. fn_script_log_info "No installed mods or addons were found."
  441. core_exit.sh
  442. fi
  443. }
  444. # Builds installed mods list and sets available commands according to installed mods
  445. # (requires ${installedmodscount} from fn_check_installed_mods)
  446. fn_mods_available_commands_from_installed(){
  447. # Set/reset variables
  448. installedmodsline="1"
  449. installedmodslist=()
  450. # Loop through every line of the installed mods list ${modslockfilefullpath}
  451. while [ ${installedmodsline} -le ${installedmodscount} ]; do
  452. currentmod="$(sed "${installedmodsline}q;d" "${modslockfilefullpath}")"
  453. # Get mod info to make sure mod exists
  454. fn_mod_get_info_from_command
  455. # Add the mod to available commands
  456. installedmodslist+=( "${modcommand}" )
  457. # Increment line check
  458. let installedmodsline=installedmodsline+1
  459. done
  460. }
  461. # Displays a detailed list of installed mods
  462. # Requires fn_check_installed_mods and fn_mods_available_commands_from_installed to run
  463. fn_installed_mods_detailed_list(){
  464. fn_check_installed_mods
  465. fn_mods_available_commands_from_installed
  466. # Were now based on ${installedmodslist} array's values
  467. # We're gonna go through all available commands, get details and display them to the user
  468. for ((dlindex=0; dlindex < ${#installedmodslist[@]}; dlindex++)); do
  469. # Current mod is the "dlindex" value of the array we're going through
  470. currentmod="${installedmodslist[dlindex]}"
  471. # Get mod info
  472. fn_mod_get_info_from_command
  473. # Display mod info to the user
  474. echo -e "\e[1m${modprettyname}${default} - ${moddescription} - ${modsite}"
  475. echo -e " * ${cyan}${modcommand}${default}"
  476. done
  477. }
  478. # Displays a detailed list of installed mods
  479. # Requires fn_check_installed_mods and fn_mods_available_commands_from_installed to run
  480. fn_installed_mods_medium_list(){
  481. fn_check_installed_mods
  482. fn_mods_available_commands_from_installed
  483. # Were now based on ${installedmodslist} array's values
  484. # We're gonna go through all available commands, get details and display them to the user
  485. for ((mlindex=0; mlindex < ${#installedmodslist[@]}; mlindex++)); do
  486. # Current mod is the "mlindex" value of the array we're going through
  487. currentmod="${installedmodslist[mlindex]}"
  488. # Get mod info
  489. fn_mod_get_info_from_command
  490. # Display mod info to the user
  491. echo -e "${cyan}${modcommand}${default} - \e[1m${modprettyname}${default} - ${moddescription}"
  492. done
  493. }
  494. # Displays a simple list of installed mods
  495. # Requires fn_check_installed_mods and fn_mods_available_commands_from_installed to run
  496. # This list is only displayed when some mods are installed
  497. fn_installed_mods_light_list(){
  498. fn_check_installed_mods
  499. fn_mods_available_commands_from_installed
  500. if [ "${installedmodscount}" -gt 0 ]; then
  501. echo "Installed addons/mods"
  502. echo "================================="
  503. # Were now based on ${installedmodslist} array's values
  504. # We're gonna go through all available commands, get details and display them to the user
  505. for ((llindex=0; llindex < ${#installedmodslist[@]}; llindex++)); do
  506. # Current mod is the "llindex" value of the array we're going through
  507. currentmod="${installedmodslist[llindex]}"
  508. # Get mod info
  509. fn_mod_get_info_from_command
  510. # Display simple mod info to the user
  511. echo -e " * \e[1m${green}${modcommand}${default}${default}"
  512. done
  513. echo ""
  514. fi
  515. }
  516. # Displays a simple list of installed mods for mods-update command
  517. # Requires fn_check_installed_mods and fn_mods_available_commands_from_installed to run
  518. fn_installed_mods_update_list(){
  519. fn_check_installed_mods
  520. fn_mods_available_commands_from_installed
  521. echo "================================="
  522. echo "Installed addons/mods"
  523. # Were now based on ${installedmodslist} array's values
  524. # We're gonna go through all available commands, get details and display them to the user
  525. for ((ulindex=0; ulindex < ${#installedmodslist[@]}; ulindex++)); do
  526. # Current mod is the "ulindex" value of the array we're going through
  527. currentmod="${installedmodslist[ulindex]}"
  528. # Get mod info
  529. fn_mod_get_info_from_command
  530. # Display simple mod info to the user according to the update policy
  531. # If modkeepfiles is not set for some reason, that's a problem
  532. if [ -z "${modkeepfiles}" ]; then
  533. fn_script_log_error "Couldn't find update policy for ${modprettyname}"
  534. fn_print_error_nl "Couldn't find update policy for ${modprettyname}"
  535. exitcode="1"
  536. core_exit.sh
  537. # If the mod won't get updated
  538. elif [ "${modkeepfiles}" == "NOUPDATE" ]; then
  539. echo -e " * \e[31m${modprettyname}${default} (won't be updated)"
  540. # If the mode is just overwritten
  541. elif [ "${modkeepfiles}" == "OVERWRITE" ]; then
  542. echo -e " * \e[1m${modprettyname}${default} (overwrite)"
  543. else
  544. echo -e " * ${yellow}${modprettyname}${default} (common custom files remain untouched)"
  545. fi
  546. done
  547. }
  548. # Get details of a mod any (relevant and unique, such as full mod name or install command) value
  549. fn_mod_get_info_from_command(){
  550. # Variable to know when job is done
  551. modinfocommand="0"
  552. # Find entry in global array
  553. for ((index=0; index <= ${#mods_global_array[@]}; index++)); do
  554. # When entry is found
  555. if [ "${mods_global_array[index]}" == "${currentmod}" ]; then
  556. # Go back to the previous "MOD" separator
  557. for ((index=index; index <= ${#mods_global_array[@]}; index--)); do
  558. # When "MOD" is found
  559. if [ "${mods_global_array[index]}" == "MOD" ]; then
  560. # Get info
  561. fn_mod_info
  562. modinfocommand="1"
  563. break
  564. fi
  565. done
  566. fi
  567. # Exit the loop if job is done
  568. if [ "${modinfocommand}" == "1" ]; then
  569. break
  570. fi
  571. done
  572. # What happens if mod is not found
  573. if [ "${modinfocommand}" == "0" ]; then
  574. fn_script_log_error "Couldn't find information for ${currentmod}"
  575. fn_print_error_nl "Couldn't find information for ${currentmod}"
  576. exitcode="1"
  577. core_exit.sh
  578. fi
  579. }
  580. fn_lgsm_requirements
  581. fn_mods_scrape_urls
  582. fn_mods_info
  583. fn_mods_available