mods_core.sh 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. #!/bin/bash
  2. # LinuxGSM command_mods_install.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Core modules for mods list/install/update/remove
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. # Files and Directories.
  9. modsdir="${lgsmdir}/mods"
  10. modstmpdir="${modsdir}/tmp"
  11. extractdest="${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 "${extractdest}" ]; then
  25. mkdir -p "${extractdest}"
  26. fi
  27. fn_dl_extract "${modstmpdir}" "${modfilename}" "${extractdest}"
  28. }
  29. # Convert mod files to lowercase if needed.
  30. fn_mod_lowercase() {
  31. # Checking lowercase settings from mods array definition
  32. if [ "${modlowercase}" == "LowercaseOn" ]; then
  33. echo -en "converting ${modprettyname} files to lowercase..."
  34. fn_sleep_time
  35. fn_script_log_info "Converting ${modprettyname} files to lowercase"
  36. # Total files and directories for the mod, to output to the user
  37. fileswc=$(find "${extractdest}" | wc -l)
  38. # Total uppercase files and directories for the mod, to output to the user
  39. filesupperwc=$(find "${extractdest}" -name '*[[:upper:]]*' | wc -l)
  40. fn_script_log_info "Found ${filesupperwc} uppercase files out of ${fileswc}, converting"
  41. echo -en "Found ${filesupperwc} uppercase files out of ${fileswc}, converting..."
  42. # Convert files and directories starting from the deepest to prevent issues (-depth argument)
  43. while read -r src; do
  44. # We have to convert only the last file from the path, otherwise we will fail to convert anything if a parent dir has any uppercase
  45. # therefore, we have to separate the end of the filename to only lowercase it rather than the whole line
  46. # Gather parent dir, filename lowercase filename, and set lowercase destination name
  47. latestparentdir=$(dirname "${src}")
  48. latestfilelc=$(basename "${src}" | tr '[:upper:]' '[:lower:]')
  49. dst="${latestparentdir}/${latestfilelc}"
  50. # Only convert if destination does not already exist for some reason
  51. if [ ! -e "${dst}" ]; then
  52. # Finally we can rename the file
  53. mv "${src}" "${dst}"
  54. # Exit if it fails for any reason
  55. local exitcode=$?
  56. if [ "${exitcode}" != 0 ]; then
  57. fn_print_fail_eol_nl
  58. core_exit.sh
  59. fi
  60. fi
  61. done < <(find "${extractdest}" -depth -name '*[[:upper:]]*')
  62. fn_print_ok_eol_nl
  63. fi
  64. }
  65. # Create ${modcommand}-files.txt containing the full extracted file/directory list.
  66. fn_mod_create_filelist() {
  67. echo -en "building ${modcommand}-files.txt..."
  68. fn_sleep_time
  69. # ${modsdir}/${modcommand}-files.txt.
  70. find "${extractdest}" -mindepth 1 -printf '%P\n' > "${modsdir}/${modcommand}-files.txt"
  71. local exitcode=$?
  72. if [ "${exitcode}" != 0 ]; then
  73. fn_print_fail_eol_nl
  74. fn_script_log_fatal "Building ${modsdir}/${modcommand}-files.txt"
  75. core_exit.sh
  76. else
  77. fn_print_ok_eol_nl
  78. fn_script_log_pass "Building ${modsdir}/${modcommand}-files.txt"
  79. fi
  80. # Adding removed files if needed.
  81. if [ -f "${modsdir}/.removedfiles.tmp" ]; then
  82. cat "${modsdir}/.removedfiles.tmp" >> "${modsdir}/${modcommand}-files.txt"
  83. fi
  84. }
  85. # Copy the mod into serverfiles.
  86. fn_mod_copy_destination() {
  87. echo -en "copying ${modprettyname} to ${modinstalldir}..."
  88. fn_sleep_time
  89. cp -Rf "${extractdest}/." "${modinstalldir}/"
  90. local exitcode=$?
  91. if [ "${exitcode}" != 0 ]; then
  92. fn_print_fail_eol_nl
  93. fn_script_log_fatal "Copying ${modprettyname} to ${modinstalldir}"
  94. else
  95. fn_print_ok_eol_nl
  96. fn_script_log_pass "Copying ${modprettyname} to ${modinstalldir}"
  97. fi
  98. }
  99. # Add the mod to the installed-mods.txt.
  100. fn_mod_add_list() {
  101. if [ -z "$(sed -n "/^${modcommand}$/p" "${modsinstalledlistfullpath}")" ]; then
  102. echo -e "${modcommand}" >> "${modsinstalledlistfullpath}"
  103. fn_script_log_info "${modcommand} added to ${modsinstalledlist}"
  104. fi
  105. }
  106. # Prevent sensitive directories from being erased upon uninstall by removing them from: ${modcommand}-files.txt.
  107. fn_mod_tidy_files_list() {
  108. # Check file list validity.
  109. fn_check_mod_files_list
  110. # Output to the user
  111. echo -en "tidy up ${modcommand}-files.txt..."
  112. fn_sleep_time
  113. fn_script_log_info "Tidy up ${modcommand}-files.txt"
  114. # Lines/files to remove from file list (end with ";" separator).
  115. removefromlist="cfg;addons;RustDedicated_Data;RustDedicated_Data\/Managed;RustDedicated_Data\/Managed\/x86;RustDedicated_Data\/Managed\/x64;"
  116. # Loop through files to remove from file list,
  117. # generate elements to remove from list.
  118. removefromlistamount=$(echo -e "${removefromlist}" | awk -F ';' '{ print NF }')
  119. # Test all subvalue of "removefromlist" using the ";" separator.
  120. for ((filesindex = 1; filesindex < removefromlistamount; filesindex++)); do
  121. # Put current file into test variable.
  122. removefilevar=$(echo -e "${removefromlist}" | awk -F ';' -v x=${filesindex} '{ print $x }')
  123. # Delete line(s) matching exactly.
  124. sed -i "/^${removefilevar}$/d" "${modsdir}/${modcommand}-files.txt"
  125. # Exit on error.
  126. local exitcode=$?
  127. if [ "${exitcode}" != 0 ]; then
  128. fn_print_fail_eol_nl
  129. fn_script_log_fatal "Error while tidying line: ${removefilevar} from: ${modsdir}/${modcommand}-files.txt"
  130. core_exit.sh
  131. break
  132. fi
  133. done
  134. fn_print_ok_eol_nl
  135. # Sourcemod fix
  136. # Remove metamod from sourcemod fileslist.
  137. if [ "${modcommand}" == "sourcemod" ]; then
  138. # Remove addons/metamod & addons/metamod/sourcemod.vdf from ${modcommand}-files.txt.
  139. sed -i "/^addons\/metamod$/d" "${modsdir}/${modcommand}-files.txt"
  140. sed -i "/^addons\/metamod\/sourcemod.vdf$/d" "${modsdir}/${modcommand}-files.txt"
  141. fi
  142. # Remove common paths from deletion list (Add your sourcemod mod here)
  143. if [ "${modcommand}" == "gokz" ] || [ "${modcommand}" == "ttt" ] || [ "${modcommand}" == "steamworks" ] || [ "${modcommand}" == "get5" ]; then
  144. sed -i "/^addons\/sourcemod$/d" "${modsdir}/${modcommand}-files.txt"
  145. sed -i "/^addons\/sourcemod\/configs$/d" "${modsdir}/${modcommand}-files.txt"
  146. sed -i "/^addons\/sourcemod\/extensions$/d" "${modsdir}/${modcommand}-files.txt"
  147. sed -i "/^addons\/sourcemod\/logs$/d" "${modsdir}/${modcommand}-files.txt"
  148. sed -i "/^addons\/sourcemod\/plugins$/d" "${modsdir}/${modcommand}-files.txt"
  149. sed -i "/^addons\/sourcemod\/plugins\/disabled$/d" "${modsdir}/${modcommand}-files.txt"
  150. sed -i "/^addons\/sourcemod\/scripting$/d" "${modsdir}/${modcommand}-files.txt"
  151. sed -i "/^addons\/sourcemod\/scripting\/include$/d" "${modsdir}/${modcommand}-files.txt"
  152. sed -i "/^addons\/sourcemod\/translations$/d" "${modsdir}/${modcommand}-files.txt"
  153. # Don't delete directories of translations like 'fr', 'sv', 'de', etc
  154. sed -i "/^addons\/sourcemod\/translations\/[A-Za-z0-9_]*$/d" "${modsdir}/${modcommand}-files.txt"
  155. sed -i "/^cfg\/sourcemod$/d" "${modsdir}/${modcommand}-files.txt"
  156. sed -i "/^maps$/d" "${modsdir}/${modcommand}-files.txt"
  157. sed -i "/^materialss$/d" "${modsdir}/${modcommand}-files.txt"
  158. sed -i "/^materials\/models$/d" "${modsdir}/${modcommand}-files.txt"
  159. sed -i "/^materials\/models\/weapons$/d" "${modsdir}/${modcommand}-files.txt"
  160. sed -i "/^materials\/darkness$/d" "${modsdir}/${modcommand}-files.txt"
  161. sed -i "/^materials\/decals$/d" "${modsdir}/${modcommand}-files.txt"
  162. sed -i "/^materials\/overlays$/d" "${modsdir}/${modcommand}-files.txt"
  163. sed -i "/^models$/d" "${modsdir}/${modcommand}-files.txt"
  164. sed -i "/^models\/weapons$/d" "${modsdir}/${modcommand}-files.txt"
  165. sed -i "/^sound$/d" "${modsdir}/${modcommand}-files.txt"
  166. sed -i "/^sound\/weapons$/d" "${modsdir}/${modcommand}-files.txt"
  167. fi
  168. # Remove paths of specific mods from deletion list
  169. if [ "${modcommand}" == "gokz" ]; then
  170. sed -i "/^addons\/sourcemod\/scripting\/include\/smjansson.inc$/d" "${modsdir}/${modcommand}-files.txt"
  171. sed -i "/^addons\/sourcemod\/scripting\/include\/GlobalAPI-Core.inc$/d" "${modsdir}/${modcommand}-files.txt"
  172. sed -i "/^addons\/sourcemod\/scripting\/include\/sourcebanspp.inc$/d" "${modsdir}/${modcommand}-files.txt"
  173. sed -i "/^addons\/sourcemod\/scripting\/include\/autoexecconfig.inc$/d" "${modsdir}/${modcommand}-files.txt"
  174. sed -i "/^addons\/sourcemod\/scripting\/include\/colorvariables.inc$/d" "${modsdir}/${modcommand}-files.txt"
  175. sed -i "/^addons\/sourcemod\/scripting\/include\/movementapi.inc$/d" "${modsdir}/${modcommand}-files.txt"
  176. sed -i "/^addons\/sourcemod\/scripting\/include\/movement.inc$/d" "${modsdir}/${modcommand}-files.txt"
  177. sed -i "/^addons\/sourcemod\/scripting\/include\/dhooks.inc$/d" "${modsdir}/${modcommand}-files.txt"
  178. sed -i "/^addons\/sourcemod\/scripting\/include\/updater.inc$/d" "${modsdir}/${modcommand}-files.txt"
  179. fi
  180. }
  181. ## Information Gathering.
  182. # Get details of a mod any (relevant and unique, such as full mod name or install command) value.
  183. fn_mod_get_info() {
  184. # Variable to know when job is done.
  185. modinfocommand="0"
  186. # Find entry in global array.
  187. for ((index = 0; index <= ${#mods_global_array[@]}; index++)); do
  188. # When entry is found.
  189. if [ "${mods_global_array[index]}" == "${currentmod}" ]; then
  190. # Go back to the previous "MOD" separator.
  191. for ((index = index; index <= ${#mods_global_array[@]}; index--)); do
  192. # When "MOD" is found.
  193. if [ "${mods_global_array[index]}" == "MOD" ]; then
  194. # Get info.
  195. fn_mods_define
  196. modinfocommand="1"
  197. break
  198. fi
  199. done
  200. fi
  201. # Exit the loop if job is done.
  202. if [ "${modinfocommand}" == "1" ]; then
  203. break
  204. fi
  205. done
  206. # What happens if mod is not found.
  207. if [ "${modinfocommand}" == "0" ]; then
  208. fn_script_log_error "Could not find information for ${currentmod}"
  209. fn_print_error_nl "Could not find information for ${currentmod}"
  210. core_exit.sh
  211. fi
  212. }
  213. # Define all variables for a mod at once when index is set to a separator.
  214. fn_mods_define() {
  215. if [ -z "$index" ]; then
  216. fn_script_log_fatal "index variable not set. Please report an issue."
  217. fn_print_error "index variable not set. Please report an issue."
  218. echo -e "* https://github.com/GameServerManagers/LinuxGSM/issues"
  219. core_exit.sh
  220. fi
  221. modcommand="${mods_global_array[index + 1]}"
  222. modprettyname="${mods_global_array[index + 2]}"
  223. modurl="${mods_global_array[index + 3]}"
  224. modfilename="${mods_global_array[index + 4]}"
  225. modsubdirs="${mods_global_array[index + 5]}"
  226. modlowercase="${mods_global_array[index + 6]}"
  227. modinstalldir="${mods_global_array[index + 7]}"
  228. modkeepfiles="${mods_global_array[index + 8]}"
  229. modengines="${mods_global_array[index + 9]}"
  230. modgames="${mods_global_array[index + 10]}"
  231. modexcludegames="${mods_global_array[index + 11]}"
  232. modsite="${mods_global_array[index + 12]}"
  233. moddescription="${mods_global_array[index + 13]}"
  234. }
  235. # Builds list of installed mods.
  236. # using installed-mods.txt grabing mod info from mods_list.sh.
  237. fn_mods_installed_list() {
  238. fn_mods_count_installed
  239. # Set/reset variables.
  240. installedmodsline="1"
  241. installedmodslist=()
  242. modprettynamemaxlength="0"
  243. modsitemaxlength="0"
  244. moddescriptionmaxlength="0"
  245. modcommandmaxlength="0"
  246. # Loop through every line of the installed mods list ${modsinstalledlistfullpath}.
  247. while [ "${installedmodsline}" -le "${installedmodscount}" ]; do
  248. currentmod=$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")
  249. # Get mod info to make sure mod exists.
  250. fn_mod_get_info
  251. # Add the mod to available commands.
  252. installedmodslist+=("${modcommand}")
  253. # Increment line check.
  254. ((installedmodsline++))
  255. done
  256. if [ "${installedmodscount}" ]; then
  257. fn_script_log_info "${installedmodscount} addons/mods are currently installed"
  258. fi
  259. }
  260. # Loops through mods_global_array to define available mods & provide available commands for mods installation.
  261. fn_mods_available() {
  262. # First, reset variables.
  263. compatiblemodslist=()
  264. availablemodscommands=()
  265. # Find compatible games.
  266. # Find separators through the global array.
  267. for ((index = "0"; index <= ${#mods_global_array[@]}; index++)); do
  268. # If current value is a separator; then.
  269. if [ "${mods_global_array[index]}" == "${modseparator}" ]; then
  270. # Set mod variables.
  271. fn_mods_define
  272. # Test if game is compatible.
  273. fn_mod_compatible_test
  274. # If game is compatible.
  275. if [ "${modcompatibility}" == "1" ]; then
  276. # Put it into an array to prepare user output.
  277. compatiblemodslist+=("${modprettyname}" "${modcommand}" "${modsite}" "${moddescription}")
  278. # Keep available commands in an array to make life easier.
  279. availablemodscommands+=("${modcommand}")
  280. fi
  281. fi
  282. done
  283. }
  284. ## Mod compatibility check.
  285. # Find out if a game is compatible with a mod from a modgames (list of games supported by a mod) variable.
  286. fn_compatible_mod_games() {
  287. # Reset test value.
  288. modcompatiblegame="0"
  289. # If value is set to GAMES (ignore).
  290. if [ "${modgames}" != "GAMES" ]; then
  291. # How many games we need to test.
  292. gamesamount=$(echo -e "${modgames}" | awk -F ';' '{ print NF }')
  293. # Test all subvalue of "modgames" using the ";" separator.
  294. for ((gamevarindex = 1; gamevarindex < gamesamount; gamevarindex++)); do
  295. # Put current game name into modtest variable.
  296. gamemodtest=$(echo -e "${modgames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }')
  297. # If game name matches.
  298. if [ "${gamemodtest}" == "${gamename}" ]; then
  299. # Mod is compatible.
  300. modcompatiblegame="1"
  301. fi
  302. done
  303. fi
  304. }
  305. # Find out if an engine is compatible with a mod from a modengines (list of engines supported by a mod) variable.
  306. fn_compatible_mod_engines() {
  307. # Reset test value.
  308. modcompatibleengine="0"
  309. # If value is set to ENGINES (ignore).
  310. if [ "${modengines}" != "ENGINES" ]; then
  311. # How many engines we need to test.
  312. enginesamount=$(echo -e "${modengines}" | awk -F ';' '{ print NF }')
  313. # Test all subvalue of "modengines" using the ";" separator.
  314. for ((gamevarindex = 1; gamevarindex < ${enginesamount}; gamevarindex++)); do
  315. # Put current engine name into modtest variable.
  316. enginemodtest=$(echo -e "${modengines}" | awk -F ';' -v x=${gamevarindex} '{ print $x }')
  317. # If engine name matches.
  318. if [ "${enginemodtest}" == "${engine}" ]; then
  319. # Mod is compatible.
  320. modcompatibleengine="1"
  321. fi
  322. done
  323. fi
  324. }
  325. # Find out if a game is not compatible with a mod from a modnotgames (list of games not supported by a mod) variable.
  326. fn_not_compatible_mod_games() {
  327. # Reset test value.
  328. modeincompatiblegame="0"
  329. # If value is set to NOTGAMES (ignore).
  330. if [ "${modexcludegames}" != "NOTGAMES" ]; then
  331. # How many engines we need to test.
  332. excludegamesamount=$(echo -e "${modexcludegames}" | awk -F ';' '{ print NF }')
  333. # Test all subvalue of "modexcludegames" using the ";" separator.
  334. for ((gamevarindex = 1; gamevarindex < excludegamesamount; gamevarindex++)); do
  335. # Put current engine name into modtest variable.
  336. excludegamemodtest=$(echo -e "${modexcludegames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }')
  337. # If engine name matches.
  338. if [ "${excludegamemodtest}" == "${gamename}" ]; then
  339. # Mod is compatible.
  340. modeincompatiblegame="1"
  341. fi
  342. done
  343. fi
  344. }
  345. # Sums up if a mod is compatible or not with modcompatibility=0/1.
  346. fn_mod_compatible_test() {
  347. # Test game and engine compatibility.
  348. fn_compatible_mod_games
  349. fn_compatible_mod_engines
  350. fn_not_compatible_mod_games
  351. if [ "${modeincompatiblegame}" == "1" ]; then
  352. modcompatibility="0"
  353. elif [ "${modcompatibleengine}" == "1" ] || [ "${modcompatiblegame}" == "1" ]; then
  354. modcompatibility="1"
  355. else
  356. modcompatibility="0"
  357. fi
  358. }
  359. ## Directory management.
  360. # Create mods files and directories if it doesn't exist.
  361. fn_create_mods_dir() {
  362. # Create lgsm data modsdir.
  363. if [ ! -d "${modsdir}" ]; then
  364. echo -en "creating LinuxGSM mods data directory ${modsdir}..."
  365. mkdir -p "${modsdir}"
  366. exitcode=$?
  367. if [ "${exitcode}" != 0 ]; then
  368. fn_print_fail_eol_nl
  369. fn_script_log_fatal "Creating mod download dir ${modsdir}"
  370. core_exit.sh
  371. else
  372. fn_print_ok_eol_nl
  373. fn_script_log_pass "Creating mod download dir ${modsdir}"
  374. fi
  375. fi
  376. # Create mod install directory.
  377. if [ ! -d "${modinstalldir}" ]; then
  378. echo -en "creating mods install directory ${modinstalldir}..."
  379. mkdir -p "${modinstalldir}"
  380. exitcode=$?
  381. if [ "${exitcode}" != 0 ]; then
  382. fn_print_fail_eol_nl
  383. fn_script_log_fatal "Creating mod install directory ${modinstalldir}"
  384. core_exit.sh
  385. else
  386. fn_print_ok_eol_nl
  387. fn_script_log_pass "Creating mod install directory ${modinstalldir}"
  388. fi
  389. fi
  390. # Create lgsm/data/${modsinstalledlist}.
  391. if [ ! -f "${modsinstalledlistfullpath}" ]; then
  392. touch "${modsinstalledlistfullpath}"
  393. fn_script_log_info "Created ${modsinstalledlistfullpath}"
  394. fi
  395. }
  396. # Create tmp download mod directory.
  397. fn_mods_create_tmp_dir() {
  398. if [ ! -d "${modstmpdir}" ]; then
  399. mkdir -p "${modstmpdir}"
  400. exitcode=$?
  401. echo -en "creating mod download directory ${modstmpdir}..."
  402. if [ "${exitcode}" != 0 ]; then
  403. fn_print_fail_eol_nl
  404. fn_script_log_fatal "Creating mod download directory ${modstmpdir}"
  405. core_exit.sh
  406. else
  407. fn_print_ok_eol_nl
  408. fn_script_log_pass "Creating mod download directory ${modstmpdir}"
  409. fi
  410. fi
  411. }
  412. # Remove the tmp mod download directory when finished.
  413. fn_mods_clear_tmp_dir() {
  414. if [ -d "${modstmpdir}" ]; then
  415. echo -en "clearing mod download directory ${modstmpdir}..."
  416. rm -rf "${modstmpdir:?}"
  417. exitcode=$?
  418. if [ "${exitcode}" != 0 ]; then
  419. fn_print_fail_eol_nl
  420. fn_script_log_fatal "Clearing mod download directory ${modstmpdir}"
  421. core_exit.sh
  422. else
  423. fn_print_ok_eol_nl
  424. fn_script_log_pass "Clearing mod download directory ${modstmpdir}"
  425. fi
  426. fi
  427. # Clear temp file list as well.
  428. if [ -f "${modsdir}/.removedfiles.tmp" ]; then
  429. rm -f "${modsdir:?}/.removedfiles.tmp"
  430. fi
  431. }
  432. # Counts how many mods were installed.
  433. fn_mods_count_installed() {
  434. if [ -f "${modsinstalledlistfullpath}" ]; then
  435. installedmodscount=$(wc -l < "${modsinstalledlistfullpath}")
  436. else
  437. installedmodscount=0
  438. fi
  439. }
  440. # Exits if no mods were installed.
  441. fn_mods_check_installed() {
  442. # Count installed mods.
  443. fn_mods_count_installed
  444. # If no mods are found.
  445. if [ ${installedmodscount} -eq 0 ]; then
  446. echo -e ""
  447. fn_print_failure_nl "No installed mods or addons were found"
  448. echo -e " * Install mods using LinuxGSM first with: ./${selfname} mods-install"
  449. fn_script_log_error "No installed mods or addons were found."
  450. core_exit.sh
  451. fi
  452. }
  453. # Checks that mod files list exists and isn't empty.
  454. fn_check_mod_files_list() {
  455. # File list must exist and be valid before any operation on it.
  456. if [ -f "${modsdir}/${modcommand}-files.txt" ]; then
  457. # How many lines is the file list.
  458. modsfilelistsize=$(wc -l < "${modsdir}/${modcommand}-files.txt")
  459. # If file list is empty.
  460. if [ "${modsfilelistsize}" -eq 0 ]; then
  461. fn_print_failure "${modcommand}-files.txt is empty"
  462. echo -e "* Unable to remove ${modprettyname}"
  463. fn_script_log_fatal "${modcommand}-files.txt is empty: Unable to remove ${modprettyname}."
  464. core_exit.sh
  465. fi
  466. else
  467. fn_print_failure "${modsdir}/${modcommand}-files.txt does not exist"
  468. fn_script_log_fatal "${modsdir}/${modcommand}-files.txt does not exist: Unable to remove ${modprettyname}."
  469. core_exit.sh
  470. fi
  471. }
  472. fn_mod_exist() {
  473. modreq=$1
  474. # requires one parameter, the mod
  475. if [ -f "${modsdir}/${modreq}-files.txt" ]; then
  476. # how many lines is the file list
  477. modsfilelistsize=$(wc -l < "${modsdir}/${modreq}-files.txt")
  478. # if file list is empty
  479. if [ "${modsfilelistsize}" -eq 0 ]; then
  480. fn_mod_required_fail_exist "${modreq}"
  481. fi
  482. else
  483. fn_mod_required_fail_exist "${modreq}"
  484. fi
  485. }
  486. fn_mod_required_fail_exist() {
  487. modreq=$1
  488. # requires one parameter, the mod
  489. fn_script_log_fatal "${modreq}-files.txt is empty: unable to find ${modreq} installed"
  490. echo -en "* Unable to find '${modreq}' which is required prior to installing this mod..."
  491. fn_print_fail_eol_nl
  492. core_exit.sh
  493. }
  494. fn_mod_liblist_gam_filenames() {
  495. # clear variables just in case
  496. moddll=""
  497. modso=""
  498. moddylib=""
  499. # default libraries
  500. case ${gamename} in
  501. "Counter-Strike 1.6")
  502. moddll="mp.dll"
  503. modso="cs.so"
  504. moddylib="cs.dylib"
  505. ;;
  506. "Day of Defeat")
  507. moddll="dod.dll"
  508. modso="dod.so"
  509. moddylib="dod.dylib"
  510. ;;
  511. "Team Fortress Classic")
  512. moddll="tfc.dll"
  513. modso="tfc.so"
  514. moddylib="tfc.dylib"
  515. ;;
  516. "Natural Selection")
  517. moddll="ns.dll"
  518. modso="ns_i386.so"
  519. moddylib=""
  520. ;;
  521. "The Specialists")
  522. moddll="mp.dll"
  523. modso="ts_i386.so"
  524. moddylib=""
  525. ;;
  526. "Half-Life: Deathmatch")
  527. moddll="hl.dll"
  528. modso="hl.so"
  529. moddylib="hl.dylib"
  530. ;;
  531. esac
  532. }
  533. # modifers for liblist.gam to add/remote metamod binaries
  534. fn_mod_install_liblist_gam_file() {
  535. fn_mod_liblist_gam_filenames
  536. if [ -f "${modinstalldir}/liblist.gam" ]; then
  537. # modify the liblist.gam file to initialize Metamod
  538. logentry="sed replace (dlls\\${moddll}) ${modinstalldir}/liblist.gam"
  539. echo -en "modifying gamedll in liblist.gam..."
  540. rpldll="s/dlls\\\\${moddll}/addons\/metamod\/dlls\/metamod.dll/g"
  541. sed -i $rpldll "${modinstalldir}/liblist.gam"
  542. grep -q "addons/metamod/dlls/metamod.dll" "${modinstalldir}/liblist.gam"
  543. exitcode=$?
  544. # if replacement back didn't happen, error out.
  545. if [ "${exitcode}" != 0 ]; then
  546. fn_script_log_fatal "${logentry}"
  547. fn_print_fail_eol_nl
  548. else
  549. fn_script_log_pass "${logentry}"
  550. fn_print_ok_eol_nl
  551. fi
  552. # modify the liblist.gam file to initialize metamod
  553. logentry="sed replace (dlls\\${modso}) ${modinstalldir}/liblist.gam"
  554. echo -en "modifying gamedll_linux in liblist.gam..."
  555. rplso="s/dlls\/${modso}/addons\/metamod\/dlls\/metamod.so/g"
  556. sed -i $rplso "${modinstalldir}/liblist.gam"
  557. grep -q "addons/metamod/dlls/metamod.so" "${modinstalldir}/liblist.gam"
  558. exitcode=$?
  559. # if replacement back didn't happen, error out
  560. if [ "${exitcode}" != 0 ]; then
  561. fn_script_log_fatal "${logentry}"
  562. fn_print_fail_eol_nl
  563. else
  564. fn_script_log_pass "${logentry}"
  565. fn_print_ok_eol_nl
  566. fi
  567. # mac os needs to be checked not all mods support mac os
  568. if [ -n "${moddylib}" ]; then
  569. # modify the liblist.gam file to initialize metamod
  570. logentry="sed replace (dlls\\${moddylib}) ${modinstalldir}/liblist.gam"
  571. echo -en "modifying gamedll_osx in liblist.gam..."
  572. rpldylib="s/dlls\/${moddylib}/addons\/metamod\/dlls\/metamod.dylib/g"
  573. sed -i $rpldylib "${modinstalldir}/liblist.gam"
  574. grep -q "addons/metamod/dlls/metamod.dylib" "${modinstalldir}/liblist.gam"
  575. exitcode=$?
  576. # if replacement back didn't happen, error out.
  577. if [ "${exitcode}" != 0 ]; then
  578. fn_script_log_fatal "${logentry}"
  579. fn_print_fail_eol_nl
  580. else
  581. fn_script_log_pass ${logentry}
  582. fn_print_ok_eol_nl
  583. fi
  584. fi
  585. fi
  586. }
  587. fn_mod_remove_liblist_gam_file() {
  588. fn_mod_liblist_gam_filenames
  589. if [ -f "${modinstalldir}/liblist.gam" ]; then
  590. # modify the liblist.gam file back to defaults
  591. logentry="sed replace (addons/metamod/dlls/metamod.dll) ${modinstalldir}/liblist.gam"
  592. echo -en "modifying gamedll in liblist.gam..."
  593. rpldll="s/addons\/metamod\/dlls\/metamod.dll/dlls\\\\${moddll}/g"
  594. sed -i $rpldll "${modinstalldir}/liblist.gam"
  595. grep -q "${moddll}" "${modinstalldir}/liblist.gam"
  596. exitcode=$?
  597. # if replacement back didn't happen, error out.
  598. if [ "${exitcode}" != 0 ]; then
  599. fn_script_log_fatal "${logentry}"
  600. fn_print_fail_eol_nl
  601. else
  602. fn_script_log_pass ${logentry}
  603. fn_print_ok_eol_nl
  604. fi
  605. # modify the liblist.gam file back to defaults
  606. logentry="sed replace (addons/metamod/dlls/metamod.so) ${modinstalldir}/liblist.gam"
  607. echo -en "modifying gamedll_linux in liblist.gam..."
  608. rplso="s/addons\/metamod\/dlls\/metamod.so/dlls\/${modso}/g"
  609. sed -i $rplso "${modinstalldir}/liblist.gam"
  610. grep -q "${modso}" "${modinstalldir}/liblist.gam"
  611. exitcode=$?
  612. # if replacement back didn't happen, error out
  613. if [ "${exitcode}" != 0 ]; then
  614. fn_script_log_fatal "${logentry}"
  615. fn_print_fail_eol_nl
  616. else
  617. fn_script_log_pass ${logentry}
  618. fn_print_ok_eol_nl
  619. fi
  620. # mac os needs to be checked not all mods support mac os
  621. if [ -n "${moddylib}" ]; then
  622. # modify the liblist.gam file back to defaults
  623. logentry="sed replace (addons/metamod/dlls/metamod.dylib) ${modinstalldir}/liblist.gam"
  624. echo -en "modifying gamedll_osx in liblist.gam..."
  625. rpldylib="s/addons\/metamod\/dlls\/metamod.dylib/dlls\/${moddylib}/g"
  626. sed -i $rpldylib "${modinstalldir}/liblist.gam"
  627. grep -q "${moddylib}" "${modinstalldir}/liblist.gam"
  628. # if replacement back didn't happen, error out.
  629. exitcode=$?
  630. if [ "${exitcode}" != 0 ]; then
  631. fn_script_log_fatal "${logentry}"
  632. fn_print_fail_eol_nl
  633. else
  634. fn_script_log_pass ${logentry}
  635. fn_print_ok_eol_nl
  636. fi
  637. fi
  638. fi
  639. }
  640. fn_mod_install_amxmodx_file() {
  641. # does plugins.ini exist?
  642. if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
  643. # since it does exist, is the entry already in plugins.ini
  644. logentry="line (linux addons/amxmodx/dlls/amxmodx_mm_i386.so) inserted into ${modinstalldir}/addons/metamod/plugins.ini"
  645. echo -en "adding amxmodx_mm_i386.so in plugins.ini..."
  646. grep -q "amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"
  647. exitcode=$?
  648. if [ "${exitcode}" != 0 ]; then
  649. # file exists but the entry does not, let's add it
  650. echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" >> "${modinstalldir}/addons/metamod/plugins.ini"
  651. exitcode=$?
  652. if [ "${exitcode}" != 0 ]; then
  653. fn_script_log_fatal "${logentry}"
  654. fn_print_fail_eol_nl
  655. else
  656. fn_script_log_pass ${logentry}
  657. fn_print_ok_eol_nl
  658. fi
  659. fi
  660. else
  661. # create new file and add the mod to it
  662. echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" > "${modinstalldir}/addons/metamod/plugins.ini"
  663. exitcode=$?
  664. if [ "${exitcode}" != 0 ]; then
  665. fn_script_log_fatal "${logentry}"
  666. fn_print_fail_eol_nl
  667. core_exit.sh
  668. else
  669. fn_script_log_pass ${logentry}
  670. fn_print_ok_eol_nl
  671. fi
  672. fi
  673. }
  674. fn_mod_remove_amxmodx_file() {
  675. if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
  676. # since it does exist, is the entry already in plugins.ini
  677. logentry="line (linux addons/amxmodx/dlls/amxmodx_mm_i386.so) removed from ${modinstalldir}/addons/metamod/plugins.ini"
  678. echo -en "removing amxmodx_mm_i386.so in plugins.ini..."
  679. grep -q "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"
  680. # iIs it found? If so remove it and clean up
  681. exitcode=$?
  682. if [ "${exitcode}" == 0 ]; then
  683. # delete the line we inserted
  684. sed -i '/linux addons\/amxmodx\/dlls\/amxmodx_mm_i386.so/d' "${modinstalldir}/addons/metamod/plugins.ini"
  685. # remove empty lines
  686. sed -i '/^$/d' "${modinstalldir}/addons/metamod/plugins.ini"
  687. exitcode=$?
  688. if [ "${exitcode}" != 0 ]; then
  689. fn_script_log_fatal "${logentry}"
  690. fn_print_fail_eol_nl
  691. else
  692. fn_script_log_pass ${logentry}
  693. fn_print_ok_eol_nl
  694. fi
  695. # if file is empty, remove it.
  696. if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
  697. rm -f "${modinstalldir}/addons/metamod/plugins.ini"
  698. fn_script_log_pass "file removed ${modinstalldir}/addons/metamod/plugins.ini because it was empty"
  699. fi
  700. fi
  701. fi
  702. }
  703. ## Database initialisation.
  704. mods_list.sh
  705. fn_mods_available