mods_core.sh 18 KB

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