mods_core.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. #!/bin/bash
  2. # LinuxGSM command_mods_install.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.com
  6. # Description: Core functions for mods list/install/update/remove
  7. local commandname="MODS"
  8. local commandaction="Mods"
  9. local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
  10. # Files and Directories.
  11. modsdir="${lgsmdir}/mods"
  12. modstmpdir="${modsdir}/tmp"
  13. extractdir="${modstmpdir}/extract"
  14. modsinstalledlist="installed-mods.txt"
  15. modsinstalledlistfullpath="${modsdir}/${modsinstalledlist}"
  16. ## Installation.
  17. # Download management.
  18. fn_mod_install_files(){
  19. fn_fetch_file "${modurl}" "${modstmpdir}" "${modfilename}"
  20. # Check if variable is valid checking if file has been downloaded and exists.
  21. if [ ! -f "${modstmpdir}/${modfilename}" ]; then
  22. fn_print_failure "An issue occurred downloading ${modprettyname}"
  23. fn_script_log_fatal "An issue occurred downloading ${modprettyname}"
  24. core_exit.sh
  25. fi
  26. if [ ! -d "${extractdir}" ]; then
  27. mkdir -p "${extractdir}"
  28. fi
  29. fn_dl_extract "${modstmpdir}" "${modfilename}" "${extractdir}"
  30. }
  31. # Convert mod files to lowercase if needed.
  32. fn_mod_lowercase(){
  33. if [ "${modlowercase}" == "LowercaseOn" ]; then
  34. echo -en "converting ${modprettyname} files to lowercase..."
  35. fn_sleep_time
  36. fn_script_log_info "Converting ${modprettyname} files to lowercase"
  37. fileswc=$(find "${extractdir}" -depth | wc -l)
  38. echo -en "\r"
  39. while read -r src; do
  40. dst=$(dirname "${src}$(/)basename" "${src}" | tr '[:upper:]' '[:lower:]')
  41. if [ "${src}" != "${dst}" ]
  42. then
  43. [ ! -e "${dst}" ] && mv -T "${src}" "${dst}" || echo -e "${src} was not renamed"
  44. local exitcode=$?
  45. ((renamedwc++))
  46. fi
  47. echo -en "${renamedwc} / ${totalfileswc} / ${fileswc} converting ${modprettyname} files to lowercase..." $'\r'
  48. ((totalfileswc++))
  49. done < <(find "${extractdir}" -depth)
  50. echo -en "${renamedwc} / ${totalfileswc} / ${fileswc} converting ${modprettyname} files to lowercase..."
  51. if [ ${exitcode} -ne 0 ]; then
  52. fn_print_fail_eol_nl
  53. core_exit.sh
  54. else
  55. fn_print_ok_eol_nl
  56. fi
  57. fn_sleep_time
  58. fi
  59. }
  60. # Create ${modcommand}-files.txt containing the full extracted file/directory list.
  61. fn_mod_create_filelist(){
  62. echo -en "building ${modcommand}-files.txt..."
  63. fn_sleep_time
  64. # ${modsdir}/${modcommand}-files.txt.
  65. find "${extractdir}" -mindepth 1 -printf '%P\n' > "${modsdir}/${modcommand}-files.txt"
  66. local exitcode=$?
  67. if [ ${exitcode} -ne 0 ]; then
  68. fn_print_fail_eol_nl
  69. fn_script_log_fatal "Building ${modsdir}/${modcommand}-files.txt"
  70. core_exit.sh
  71. else
  72. fn_print_ok_eol_nl
  73. fn_script_log_pass "Building ${modsdir}/${modcommand}-files.txt"
  74. fi
  75. # Adding removed files if needed.
  76. if [ -f "${modsdir}/.removedfiles.tmp" ]; then
  77. cat "${modsdir}/.removedfiles.tmp" >> "${modsdir}/${modcommand}-files.txt"
  78. fi
  79. fn_sleep_time
  80. }
  81. # Copy the mod into serverfiles.
  82. fn_mod_copy_destination(){
  83. echo -en "copying ${modprettyname} to ${modinstalldir}..."
  84. fn_sleep_time
  85. cp -Rf "${extractdir}/." "${modinstalldir}/"
  86. local exitcode=$?
  87. if [ ${exitcode} -ne 0 ]; then
  88. fn_print_fail_eol_nl
  89. fn_script_log_fatal "Copying ${modprettyname} to ${modinstalldir}"
  90. else
  91. fn_print_ok_eol_nl
  92. fn_script_log_pass "Copying ${modprettyname} to ${modinstalldir}"
  93. fi
  94. }
  95. # Add the mod to the installed-mods.txt.
  96. fn_mod_add_list(){
  97. if [ ! -n "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
  98. echo -e "${modcommand}" >> "${modsinstalledlistfullpath}"
  99. fn_script_log_info "${modcommand} added to ${modsinstalledlist}"
  100. fi
  101. }
  102. # Prevent sensitive directories from being erased upon uninstall by removing them from: ${modcommand}-files.txt.
  103. fn_mod_tidy_files_list(){
  104. # Check file list validity.
  105. fn_check_mod_files_list
  106. # Output to the user
  107. echo -en "tidy up ${modcommand}-files.txt..."
  108. fn_sleep_time
  109. fn_script_log_info "Tidy up ${modcommand}-files.txt"
  110. # Lines/files to remove from file list (end with ";" separator).
  111. removefromlist="cfg;addons;RustDedicated_Data;RustDedicated_Data\/Managed;RustDedicated_Data\/Managed\/x86;RustDedicated_Data\/Managed\/x64;"
  112. # Loop through files to remove from file list,
  113. # generate elements to remove from list.
  114. removefromlistamount=$(echo -e "${removefromlist}" | awk -F ';' '{ print NF }')
  115. # Test all subvalue of "removefromlist" using the ";" separator.
  116. for ((filesindex=1; filesindex < removefromlistamount; filesindex++)); do
  117. # Put current file into test variable.
  118. removefilevar=$(echo -e "${removefromlist}" | awk -F ';' -v x=${filesindex} '{ print $x }')
  119. # Delete line(s) matching exactly.
  120. sed -i "/^${removefilevar}$/d" "${modsdir}/${modcommand}-files.txt"
  121. # Exit on error.
  122. local exitcode=$?
  123. if [ ${exitcode} -ne 0 ]; then
  124. fn_print_fail_eol_nl
  125. fn_script_log_fatal "Error while tidying line: ${removefilevar} from: ${modsdir}/${modcommand}-files.txt"
  126. core_exit.sh
  127. break
  128. fi
  129. done
  130. fn_print_ok_eol_nl
  131. # Sourcemod fix
  132. # Remove metamod from sourcemod fileslist.
  133. if [ "${modcommand}" == "sourcemod" ]; then
  134. # Remove addons/metamod & addons/metamod/sourcemod.vdf from ${modcommand}-files.txt.
  135. sed -i "/^addons\/metamod$/d" "${modsdir}/${modcommand}-files.txt"
  136. sed -i "/^addons\/metamod\/sourcemod.vdf$/d" "${modsdir}/${modcommand}-files.txt"
  137. fi
  138. # Remove common paths from deletion list (Add your sourcemod mod here)
  139. if [ "${modcommand}" == "gokz" ] || [ "${modcommand}" == "ttt" ] || [ "${modcommand}" == "steamworks" ] || [ "${modcommand}" == "get5" ]; then
  140. sed -i "/^addons\/sourcemod$/d" "${modsdir}/${modcommand}-files.txt"
  141. sed -i "/^addons\/sourcemod\/configs$/d" "${modsdir}/${modcommand}-files.txt"
  142. sed -i "/^addons\/sourcemod\/extensions$/d" "${modsdir}/${modcommand}-files.txt"
  143. sed -i "/^addons\/sourcemod\/logs$/d" "${modsdir}/${modcommand}-files.txt"
  144. sed -i "/^addons\/sourcemod\/plugins$/d" "${modsdir}/${modcommand}-files.txt"
  145. sed -i "/^addons\/sourcemod\/plugins\/disabled$/d" "${modsdir}/${modcommand}-files.txt"
  146. sed -i "/^addons\/sourcemod\/scripting$/d" "${modsdir}/${modcommand}-files.txt"
  147. sed -i "/^addons\/sourcemod\/scripting\/include$/d" "${modsdir}/${modcommand}-files.txt"
  148. sed -i "/^addons\/sourcemod\/translations$/d" "${modsdir}/${modcommand}-files.txt"
  149. # Don't delete directories of translations like 'fr', 'sv', 'de', etc
  150. sed -i "/^addons\/sourcemod\/translations\/[A-Za-z0-9_]*$/d" "${modsdir}/${modcommand}-files.txt"
  151. sed -i "/^cfg\/sourcemod$/d" "${modsdir}/${modcommand}-files.txt"
  152. sed -i "/^maps$/d" "${modsdir}/${modcommand}-files.txt"
  153. sed -i "/^materialss$/d" "${modsdir}/${modcommand}-files.txt"
  154. sed -i "/^materials\/models$/d" "${modsdir}/${modcommand}-files.txt"
  155. sed -i "/^materials\/models\/weapons$/d" "${modsdir}/${modcommand}-files.txt"
  156. sed -i "/^materials\/darkness$/d" "${modsdir}/${modcommand}-files.txt"
  157. sed -i "/^materials\/decals$/d" "${modsdir}/${modcommand}-files.txt"
  158. sed -i "/^materials\/overlays$/d" "${modsdir}/${modcommand}-files.txt"
  159. sed -i "/^models$/d" "${modsdir}/${modcommand}-files.txt"
  160. sed -i "/^models\/weapons$/d" "${modsdir}/${modcommand}-files.txt"
  161. sed -i "/^sound$/d" "${modsdir}/${modcommand}-files.txt"
  162. sed -i "/^sound\/weapons$/d" "${modsdir}/${modcommand}-files.txt"
  163. fi
  164. # Remove paths of specific mods from deletion list
  165. if [ "${modcommand}" == "gokz" ]; then
  166. sed -i "/^addons\/sourcemod\/scripting\/include\/smjansson.inc$/d" "${modsdir}/${modcommand}-files.txt"
  167. sed -i "/^addons\/sourcemod\/scripting\/include\/GlobalAPI-Core.inc$/d" "${modsdir}/${modcommand}-files.txt"
  168. sed -i "/^addons\/sourcemod\/scripting\/include\/sourcebanspp.inc$/d" "${modsdir}/${modcommand}-files.txt"
  169. sed -i "/^addons\/sourcemod\/scripting\/include\/autoexecconfig.inc$/d" "${modsdir}/${modcommand}-files.txt"
  170. sed -i "/^addons\/sourcemod\/scripting\/include\/colorvariables.inc$/d" "${modsdir}/${modcommand}-files.txt"
  171. sed -i "/^addons\/sourcemod\/scripting\/include\/movementapi.inc$/d" "${modsdir}/${modcommand}-files.txt"
  172. sed -i "/^addons\/sourcemod\/scripting\/include\/movement.inc$/d" "${modsdir}/${modcommand}-files.txt"
  173. sed -i "/^addons\/sourcemod\/scripting\/include\/dhooks.inc$/d" "${modsdir}/${modcommand}-files.txt"
  174. sed -i "/^addons\/sourcemod\/scripting\/include\/updater.inc$/d" "${modsdir}/${modcommand}-files.txt"
  175. fi
  176. }
  177. ## Information Gathering.
  178. # Get details of a mod any (relevant and unique, such as full mod name or install command) value.
  179. fn_mod_get_info(){
  180. # Variable to know when job is done.
  181. modinfocommand="0"
  182. # Find entry in global array.
  183. for ((index=0; index <= ${#mods_global_array[@]}; index++)); do
  184. # When entry is found.
  185. if [ "${mods_global_array[index]}" == "${currentmod}" ]; then
  186. # Go back to the previous "MOD" separator.
  187. for ((index=index; index <= ${#mods_global_array[@]}; index--)); do
  188. # When "MOD" is found.
  189. if [ "${mods_global_array[index]}" == "MOD" ]; then
  190. # Get info.
  191. fn_mods_define
  192. modinfocommand="1"
  193. break
  194. fi
  195. done
  196. fi
  197. # Exit the loop if job is done.
  198. if [ "${modinfocommand}" == "1" ]; then
  199. break
  200. fi
  201. done
  202. # What happens if mod is not found.
  203. if [ "${modinfocommand}" == "0" ]; then
  204. fn_script_log_error "Could not find information for ${currentmod}"
  205. fn_print_error_nl "Could not find information for ${currentmod}"
  206. core_exit.sh
  207. fi
  208. }
  209. # Define all variables for a mod at once when index is set to a separator.
  210. fn_mods_define(){
  211. if [ -z "$index" ]; then
  212. fn_script_log_fatal "index variable not set. Please report an issue."
  213. fn_print_error "index variable not set. Please report an issue."
  214. echo -e "* https://github.com/GameServerManagers/LinuxGSM/issues"
  215. core_exit.sh
  216. fi
  217. modcommand="${mods_global_array[index+1]}"
  218. modprettyname="${mods_global_array[index+2]}"
  219. modurl="${mods_global_array[index+3]}"
  220. modfilename="${mods_global_array[index+4]}"
  221. modsubdirs="${mods_global_array[index+5]}"
  222. modlowercase="${mods_global_array[index+6]}"
  223. modinstalldir="${mods_global_array[index+7]}"
  224. modkeepfiles="${mods_global_array[index+8]}"
  225. modengines="${mods_global_array[index+9]}"
  226. modgames="${mods_global_array[index+10]}"
  227. modexcludegames="${mods_global_array[index+11]}"
  228. modsite="${mods_global_array[index+12]}"
  229. moddescription="${mods_global_array[index+13]}"
  230. }
  231. # Builds list of installed mods.
  232. # using installed-mods.txt grabing mod info from mods_list.sh.
  233. fn_mods_installed_list(){
  234. fn_mods_count_installed
  235. # Set/reset variables.
  236. installedmodsline="1"
  237. installedmodslist=()
  238. modprettynamemaxlength="0"
  239. modsitemaxlength="0"
  240. moddescriptionmaxlength="0"
  241. modcommandmaxlength="0"
  242. # Loop through every line of the installed mods list ${modsinstalledlistfullpath}.
  243. while [ "${installedmodsline}" -le "${installedmodscount}" ]; do
  244. currentmod=$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")
  245. # Get mod info to make sure mod exists.
  246. fn_mod_get_info
  247. # Add the mod to available commands.
  248. installedmodslist+=( "${modcommand}" )
  249. # Increment line check.
  250. ((installedmodsline++))
  251. done
  252. if [ -n "${installedmodscount}" ]; then
  253. fn_script_log_info "${installedmodscount} addons/mods are currently installed"
  254. fi
  255. }
  256. # Loops through mods_global_array to define available mods & provide available commands for mods installation.
  257. fn_mods_available(){
  258. # First, reset variables.
  259. compatiblemodslist=()
  260. availablemodscommands=()
  261. # Find compatible games.
  262. # Find separators through the global array.
  263. for ((index="0"; index <= ${#mods_global_array[@]}; index++)); do
  264. # If current value is a separator; then.
  265. if [ "${mods_global_array[index]}" == "${modseparator}" ]; then
  266. # Set mod variables.
  267. fn_mods_define
  268. # Test if game is compatible.
  269. fn_mod_compatible_test
  270. # If game is compatible.
  271. if [ "${modcompatibility}" == "1" ]; then
  272. # Put it into an array to prepare user output.
  273. compatiblemodslist+=( "${modprettyname}" "${modcommand}" "${modsite}" "${moddescription}" )
  274. # Keep available commands in an array to make life easier.
  275. availablemodscommands+=( "${modcommand}" )
  276. fi
  277. fi
  278. done
  279. }
  280. ## Mod compatibility check.
  281. # Find out if a game is compatible with a mod from a modgames (list of games supported by a mod) variable.
  282. fn_compatible_mod_games(){
  283. # Reset test value.
  284. modcompatiblegame="0"
  285. # If value is set to GAMES (ignore).
  286. if [ "${modgames}" != "GAMES" ]; then
  287. # How many games we need to test.
  288. gamesamount=$(echo -e "${modgames}" | awk -F ';' '{ print NF }')
  289. # Test all subvalue of "modgames" using the ";" separator.
  290. for ((gamevarindex=1; gamevarindex < gamesamount; gamevarindex++)); do
  291. # Put current game name into modtest variable.
  292. gamemodtest=$( echo -e "${modgames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )
  293. # If game name matches.
  294. if [ "${gamemodtest}" == "${gamename}" ]; then
  295. # Mod is compatible.
  296. modcompatiblegame="1"
  297. fi
  298. done
  299. fi
  300. }
  301. # Find out if an engine is compatible with a mod from a modengines (list of engines supported by a mod) variable.
  302. fn_compatible_mod_engines(){
  303. # Reset test value.
  304. modcompatibleengine="0"
  305. # If value is set to ENGINES (ignore).
  306. if [ "${modengines}" != "ENGINES" ]; then
  307. # How many engines we need to test.
  308. enginesamount=$(echo -e "${modengines}" | awk -F ';' '{ print NF }')
  309. # Test all subvalue of "modengines" using the ";" separator.
  310. for ((gamevarindex=1; gamevarindex < ${enginesamount}; gamevarindex++)); do
  311. # Put current engine name into modtest variable.
  312. enginemodtest=$( echo -e "${modengines}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )
  313. # If engine name matches.
  314. if [ "${enginemodtest}" == "${engine}" ]; then
  315. # Mod is compatible.
  316. modcompatibleengine="1"
  317. fi
  318. done
  319. fi
  320. }
  321. # Find out if a game is not compatible with a mod from a modnotgames (list of games not supported by a mod) variable.
  322. fn_not_compatible_mod_games(){
  323. # Reset test value.
  324. modeincompatiblegame="0"
  325. # If value is set to NOTGAMES (ignore).
  326. if [ "${modexcludegames}" != "NOTGAMES" ]; then
  327. # How many engines we need to test.
  328. excludegamesamount=$(echo -e "${modexcludegames}" | awk -F ';' '{ print NF }')
  329. # Test all subvalue of "modexcludegames" using the ";" separator.
  330. for ((gamevarindex=1; gamevarindex < excludegamesamount; gamevarindex++)); do
  331. # Put current engine name into modtest variable.
  332. excludegamemodtest=$( echo -e "${modexcludegames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }' )
  333. # If engine name matches.
  334. if [ "${excludegamemodtest}" == "${gamename}" ]; then
  335. # Mod is compatible.
  336. modeincompatiblegame="1"
  337. fi
  338. done
  339. fi
  340. }
  341. # Sums up if a mod is compatible or not with modcompatibility=0/1.
  342. fn_mod_compatible_test(){
  343. # Test game and engine compatibility.
  344. fn_compatible_mod_games
  345. fn_compatible_mod_engines
  346. fn_not_compatible_mod_games
  347. if [ "${modeincompatiblegame}" == "1" ]; then
  348. modcompatibility="0"
  349. elif [ "${modcompatibleengine}" == "1" ]||[ "${modcompatiblegame}" == "1" ]; then
  350. modcompatibility="1"
  351. else
  352. modcompatibility="0"
  353. fi
  354. }
  355. ## Directory management.
  356. # Create mods files and directories if it doesn't exist.
  357. fn_create_mods_dir(){
  358. # Create lgsm data modsdir.
  359. if [ ! -d "${modsdir}" ]; then
  360. echo -en "creating LinuxGSM mods data directory ${modsdir}..."
  361. mkdir -p "${modsdir}"
  362. exitcode=$?
  363. if [ ${exitcode} -ne 0 ]; then
  364. fn_print_fail_eol_nl
  365. fn_script_log_fatal "Creating mod download dir ${modsdir}"
  366. core_exit.sh
  367. else
  368. fn_print_ok_eol_nl
  369. fn_script_log_pass "Creating mod download dir ${modsdir}"
  370. fi
  371. fn_sleep_time
  372. fi
  373. # Create mod install directory.
  374. if [ ! -d "${modinstalldir}" ]; then
  375. echo -en "creating mods install directory ${modinstalldir}..."
  376. mkdir -p "${modinstalldir}"
  377. exitcode=$?
  378. if [ ${exitcode} -ne 0 ]; then
  379. fn_print_fail_eol_nl
  380. fn_script_log_fatal "Creating mod install directory ${modinstalldir}"
  381. core_exit.sh
  382. else
  383. fn_print_ok_eol_nl
  384. fn_script_log_pass "Creating mod install directory ${modinstalldir}"
  385. fi
  386. fn_sleep_time
  387. fi
  388. # Create lgsm/data/${modsinstalledlist}.
  389. if [ ! -f "${modsinstalledlistfullpath}" ]; then
  390. touch "${modsinstalledlistfullpath}"
  391. fn_script_log_info "Created ${modsinstalledlistfullpath}"
  392. fi
  393. }
  394. # Create tmp download mod directory.
  395. fn_mods_create_tmp_dir(){
  396. if [ ! -d "${modstmpdir}" ]; then
  397. mkdir -p "${modstmpdir}"
  398. exitcode=$?
  399. echo -en "creating mod download directory ${modstmpdir}..."
  400. if [ ${exitcode} -ne 0 ]; then
  401. fn_print_fail_eol_nl
  402. fn_script_log_fatal "Creating mod download directory ${modstmpdir}"
  403. core_exit.sh
  404. else
  405. fn_print_ok_eol_nl
  406. fn_script_log_pass "Creating mod download directory ${modstmpdir}"
  407. fi
  408. fi
  409. }
  410. # Remove the tmp mod download directory when finished.
  411. fn_mods_clear_tmp_dir(){
  412. if [ -d "${modstmpdir}" ]; then
  413. echo -en "clearing mod download directory ${modstmpdir}..."
  414. rm -r "${modstmpdir}"
  415. exitcode=$?
  416. if [ ${exitcode} -ne 0 ]; then
  417. fn_print_fail_eol_nl
  418. fn_script_log_fatal "Clearing mod download directory ${modstmpdir}"
  419. core_exit.sh
  420. else
  421. fn_print_ok_eol_nl
  422. fn_script_log_pass "Clearing mod download directory ${modstmpdir}"
  423. fi
  424. fi
  425. # Clear temp file list as well.
  426. if [ -f "${modsdir}/.removedfiles.tmp" ]; then
  427. rm "${modsdir}/.removedfiles.tmp"
  428. fi
  429. }
  430. # Counts how many mods were installed.
  431. fn_mods_count_installed(){
  432. if [ -f "${modsinstalledlistfullpath}" ]; then
  433. installedmodscount=$(wc -l < "${modsinstalledlistfullpath}")
  434. else
  435. installedmodscount=0
  436. fi
  437. }
  438. # Exits if no mods were installed.
  439. fn_mods_check_installed(){
  440. # Count installed mods.
  441. fn_mods_count_installed
  442. # If no mods are found.
  443. if [ ${installedmodscount} -eq 0 ]; then
  444. echo -e ""
  445. fn_print_failure_nl "No installed mods or addons were found"
  446. echo -e " * Install mods using LinuxGSM first with: ./${selfname} mods-install"
  447. fn_script_log_error "No installed mods or addons were found."
  448. core_exit.sh
  449. fi
  450. }
  451. # Checks that mod files list exists and isn't empty.
  452. fn_check_mod_files_list(){
  453. # File list must exist and be valid before any operation on it.
  454. if [ -f "${modsdir}/${modcommand}-files.txt" ]; then
  455. # How many lines is the file list.
  456. modsfilelistsize=$(wc -l < "${modsdir}/${modcommand}-files.txt")
  457. # If file list is empty.
  458. if [ "${modsfilelistsize}" -eq 0 ]; then
  459. fn_print_failure "${modcommand}-files.txt is empty"
  460. echo -e "* Unable to remove ${modprettyname}"
  461. fn_script_log_fatal "${modcommand}-files.txt is empty: Unable to remove ${modprettyname}."
  462. core_exit.sh
  463. fi
  464. else
  465. fn_print_failure "${modsdir}/${modcommand}-files.txt does not exist"
  466. fn_script_log_fatal "${modsdir}/${modcommand}-files.txt does not exist: Unable to remove ${modprettyname}."
  467. core_exit.sh
  468. fi
  469. }
  470. ## Database initialisation.
  471. mods_list.sh
  472. fn_mods_available