mods_core.sh 22 KB

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