mods_core.sh 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. #!/bin/bash
  2. # LinuxGSM command_mods_install.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://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_fail "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. exitcode=$?
  56. if [ "${exitcode}" -ne 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. exitcode=$?
  72. if [ "${exitcode}" -ne 0 ]; then
  73. fn_print_fail_eol_nl
  74. fn_script_log_fail "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. exitcode=$?
  91. if [ "${exitcode}" -ne 0 ]; then
  92. fn_print_fail_eol_nl
  93. fn_script_log_fail "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. exitcode=$?
  127. if [ "${exitcode}" -ne 0 ]; then
  128. fn_print_fail_eol_nl
  129. fn_script_log_fail "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_search = index; index_search >= 0; index_search--)); do
  192. # When "MOD" is found.
  193. if [ "${mods_global_array[index_search]}" == "MOD" ]; then
  194. # Get info.
  195. index=${index_search}
  196. fn_mods_define
  197. modinfocommand="1"
  198. break
  199. fi
  200. done
  201. fi
  202. # Exit the loop if job is done.
  203. if [ "${modinfocommand}" == "1" ]; then
  204. break
  205. fi
  206. done
  207. # What happens if mod is not found.
  208. if [ "${modinfocommand}" == "0" ]; then
  209. fn_script_log_error "Could not find information for ${currentmod}"
  210. fn_print_error_nl "Could not find information for ${currentmod}"
  211. core_exit.sh
  212. fi
  213. }
  214. # Define all variables for a mod at once when index is set to a separator.
  215. fn_mods_define() {
  216. if [ -z "$index" ]; then
  217. fn_script_log_fail "index variable not set. Please report an issue."
  218. fn_print_error "index variable not set. Please report an issue."
  219. echo -e "* https://github.com/GameServerManagers/LinuxGSM/issues"
  220. core_exit.sh
  221. fi
  222. modcommand="${mods_global_array[index + 1]}"
  223. modprettyname="${mods_global_array[index + 2]}"
  224. modurl="${mods_global_array[index + 3]}"
  225. modfilename="${mods_global_array[index + 4]}"
  226. modsubdirs="${mods_global_array[index + 5]}"
  227. modlowercase="${mods_global_array[index + 6]}"
  228. modinstalldir="${mods_global_array[index + 7]}"
  229. modkeepfiles="${mods_global_array[index + 8]}"
  230. modengines="${mods_global_array[index + 9]}"
  231. modgames="${mods_global_array[index + 10]}"
  232. modexcludegames="${mods_global_array[index + 11]}"
  233. modsite="${mods_global_array[index + 12]}"
  234. moddescription="${mods_global_array[index + 13]}"
  235. }
  236. # Builds list of installed mods.
  237. # using installed-mods.txt grabbing mod info from mods_list.sh.
  238. fn_mods_installed_list() {
  239. fn_mods_count_installed
  240. # Set/reset variables.
  241. installedmodsline="1"
  242. installedmodslist=()
  243. modprettynamemaxlength="0"
  244. modsitemaxlength="0"
  245. moddescriptionmaxlength="0"
  246. modcommandmaxlength="0"
  247. # Loop through every line of the installed mods list ${modsinstalledlistfullpath}.
  248. while [ "${installedmodsline}" -le "${installedmodscount}" ]; do
  249. currentmod=$(sed "${installedmodsline}q;d" "${modsinstalledlistfullpath}")
  250. # Get mod info to make sure mod exists.
  251. fn_mod_get_info
  252. # Add the mod to available commands.
  253. installedmodslist+=("${modcommand}")
  254. # Increment line check.
  255. ((installedmodsline++))
  256. done
  257. if [ "${installedmodscount}" ]; then
  258. fn_script_log_info "${installedmodscount} addons/mods are currently installed"
  259. fi
  260. }
  261. # Loops through mods_global_array to define available mods & provide available commands for mods installation.
  262. fn_mods_available() {
  263. # First, reset variables.
  264. compatiblemodslist=()
  265. availablemodscommands=()
  266. # Find compatible games.
  267. # Find separators through the global array.
  268. for ((index = "0"; index <= ${#mods_global_array[@]}; index++)); do
  269. # If current value is a separator; then.
  270. if [ "${mods_global_array[index]}" == "${modseparator}" ]; then
  271. # Set mod variables.
  272. fn_mods_define
  273. # Test if game is compatible.
  274. fn_mod_compatible_test
  275. # If game is compatible.
  276. if [ "${modcompatibility}" == "1" ]; then
  277. # Put it into an array to prepare user output.
  278. compatiblemodslist+=("${modprettyname}" "${modcommand}" "${modsite}" "${moddescription}")
  279. # Keep available commands in an array to make life easier.
  280. availablemodscommands+=("${modcommand}")
  281. fi
  282. fi
  283. done
  284. }
  285. ## Mod compatibility check.
  286. # Find out if a game is compatible with a mod from a modgames (list of games supported by a mod) variable.
  287. fn_compatible_mod_games() {
  288. # Reset test value.
  289. modcompatiblegame="0"
  290. # If value is set to GAMES (ignore).
  291. if [ "${modgames}" != "GAMES" ]; then
  292. # How many games we need to test.
  293. gamesamount=$(echo -e "${modgames}" | awk -F ';' '{ print NF }')
  294. # Test all subvalue of "modgames" using the ";" separator.
  295. for ((gamevarindex = 1; gamevarindex < gamesamount; gamevarindex++)); do
  296. # Put current game name into modtest variable.
  297. gamemodtest=$(echo -e "${modgames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }')
  298. # If game name matches.
  299. if [ "${gamemodtest}" == "${gamename}" ]; then
  300. # Mod is compatible.
  301. modcompatiblegame="1"
  302. fi
  303. done
  304. fi
  305. }
  306. # Find out if an engine is compatible with a mod from a modengines (list of engines supported by a mod) variable.
  307. fn_compatible_mod_engines() {
  308. # Reset test value.
  309. modcompatibleengine="0"
  310. # If value is set to ENGINES (ignore).
  311. if [ "${modengines}" != "ENGINES" ]; then
  312. # How many engines we need to test.
  313. enginesamount=$(echo -e "${modengines}" | awk -F ';' '{ print NF }')
  314. # Test all subvalue of "modengines" using the ";" separator.
  315. for ((gamevarindex = 1; gamevarindex < enginesamount; gamevarindex++)); do
  316. # Put current engine name into modtest variable.
  317. enginemodtest=$(echo -e "${modengines}" | awk -F ';' -v x=${gamevarindex} '{ print $x }')
  318. # If engine name matches.
  319. if [ "${enginemodtest}" == "${engine}" ]; then
  320. # Mod is compatible.
  321. modcompatibleengine="1"
  322. fi
  323. done
  324. fi
  325. }
  326. # Find out if a game is not compatible with a mod from a modnotgames (list of games not supported by a mod) variable.
  327. fn_not_compatible_mod_games() {
  328. # Reset test value.
  329. modeincompatiblegame="0"
  330. # If value is set to NOTGAMES (ignore).
  331. if [ "${modexcludegames}" != "NOTGAMES" ]; then
  332. # How many engines we need to test.
  333. excludegamesamount=$(echo -e "${modexcludegames}" | awk -F ';' '{ print NF }')
  334. # Test all subvalue of "modexcludegames" using the ";" separator.
  335. for ((gamevarindex = 1; gamevarindex < excludegamesamount; gamevarindex++)); do
  336. # Put current engine name into modtest variable.
  337. excludegamemodtest=$(echo -e "${modexcludegames}" | awk -F ';' -v x=${gamevarindex} '{ print $x }')
  338. # If engine name matches.
  339. if [ "${excludegamemodtest}" == "${gamename}" ]; then
  340. # Mod is compatible.
  341. modeincompatiblegame="1"
  342. fi
  343. done
  344. fi
  345. }
  346. # Sums up if a mod is compatible or not with modcompatibility=0/1.
  347. fn_mod_compatible_test() {
  348. # Test game and engine compatibility.
  349. fn_compatible_mod_games
  350. fn_compatible_mod_engines
  351. fn_not_compatible_mod_games
  352. if [ "${modeincompatiblegame}" == "1" ]; then
  353. modcompatibility="0"
  354. elif [ "${modcompatibleengine}" == "1" ] || [ "${modcompatiblegame}" == "1" ]; then
  355. modcompatibility="1"
  356. else
  357. modcompatibility="0"
  358. fi
  359. }
  360. ## Directory management.
  361. # Create mods files and directories if it doesn't exist.
  362. fn_create_mods_dir() {
  363. # Create lgsm data modsdir.
  364. if [ ! -d "${modsdir}" ]; then
  365. echo -en "creating LinuxGSM mods data directory ${modsdir}..."
  366. mkdir -p "${modsdir}"
  367. exitcode=$?
  368. if [ "${exitcode}" -ne 0 ]; then
  369. fn_print_fail_eol_nl
  370. fn_script_log_fail "Creating mod download dir ${modsdir}"
  371. core_exit.sh
  372. else
  373. fn_print_ok_eol_nl
  374. fn_script_log_pass "Creating mod download dir ${modsdir}"
  375. fi
  376. fi
  377. # Create mod install directory.
  378. if [ ! -d "${modinstalldir}" ]; then
  379. echo -en "creating mods install directory ${modinstalldir}..."
  380. mkdir -p "${modinstalldir}"
  381. exitcode=$?
  382. if [ "${exitcode}" -ne 0 ]; then
  383. fn_print_fail_eol_nl
  384. fn_script_log_fail "Creating mod install directory ${modinstalldir}"
  385. core_exit.sh
  386. else
  387. fn_print_ok_eol_nl
  388. fn_script_log_pass "Creating mod install directory ${modinstalldir}"
  389. fi
  390. fi
  391. # Create ${datadir}/${modsinstalledlist}.
  392. if [ ! -f "${modsinstalledlistfullpath}" ]; then
  393. touch "${modsinstalledlistfullpath}"
  394. fn_script_log_info "Created ${modsinstalledlistfullpath}"
  395. fi
  396. }
  397. # Create tmp download mod directory.
  398. fn_mods_create_tmp_dir() {
  399. if [ ! -d "${modstmpdir}" ]; then
  400. mkdir -p "${modstmpdir}"
  401. exitcode=$?
  402. echo -en "creating mod download directory ${modstmpdir}..."
  403. if [ "${exitcode}" -ne 0 ]; then
  404. fn_print_fail_eol_nl
  405. fn_script_log_fail "Creating mod download directory ${modstmpdir}"
  406. core_exit.sh
  407. else
  408. fn_print_ok_eol_nl
  409. fn_script_log_pass "Creating mod download directory ${modstmpdir}"
  410. fi
  411. fi
  412. }
  413. # Remove the tmp mod download directory when finished.
  414. fn_mods_clear_tmp_dir() {
  415. if [ -d "${modstmpdir}" ]; then
  416. echo -en "clearing mod download directory ${modstmpdir}..."
  417. rm -rf "${modstmpdir:?}"
  418. exitcode=$?
  419. if [ "${exitcode}" -ne 0 ]; then
  420. fn_print_fail_eol_nl
  421. fn_script_log_fail "Clearing mod download directory ${modstmpdir}"
  422. core_exit.sh
  423. else
  424. fn_print_ok_eol_nl
  425. fn_script_log_pass "Clearing mod download directory ${modstmpdir}"
  426. fi
  427. fi
  428. # Clear temp file list as well.
  429. if [ -f "${modsdir}/.removedfiles.tmp" ]; then
  430. rm -f "${modsdir:?}/.removedfiles.tmp"
  431. fi
  432. }
  433. # Counts how many mods were installed.
  434. fn_mods_count_installed() {
  435. if [ -f "${modsinstalledlistfullpath}" ]; then
  436. installedmodscount=$(wc -l < "${modsinstalledlistfullpath}")
  437. else
  438. installedmodscount=0
  439. fi
  440. }
  441. # Exits if no mods were installed.
  442. fn_mods_check_installed() {
  443. # Count installed mods.
  444. fn_mods_count_installed
  445. # If no mods are found.
  446. if [ "${installedmodscount}" -eq 0 ]; then
  447. echo -e ""
  448. fn_print_failure_nl "No installed mods or addons were found"
  449. echo -e " * Install mods using LinuxGSM first with: ./${selfname} mods-install"
  450. fn_script_log_error "No installed mods or addons were found."
  451. core_exit.sh
  452. fi
  453. }
  454. # Checks that mod files list exists and isn't empty.
  455. fn_check_mod_files_list() {
  456. # File list must exist and be valid before any operation on it.
  457. if [ -f "${modsdir}/${modcommand}-files.txt" ]; then
  458. # How many lines is the file list.
  459. modsfilelistsize=$(wc -l < "${modsdir}/${modcommand}-files.txt")
  460. # If file list is empty.
  461. if [ "${modsfilelistsize}" -eq 0 ]; then
  462. fn_print_failure "${modcommand}-files.txt is empty"
  463. echo -e "* Unable to remove ${modprettyname}"
  464. fn_script_log_fail "${modcommand}-files.txt is empty: Unable to remove ${modprettyname}."
  465. core_exit.sh
  466. fi
  467. else
  468. fn_print_failure "${modsdir}/${modcommand}-files.txt does not exist"
  469. fn_script_log_fail "${modsdir}/${modcommand}-files.txt does not exist: Unable to remove ${modprettyname}."
  470. core_exit.sh
  471. fi
  472. }
  473. fn_mod_exist() {
  474. modreq=$1
  475. # requires one parameter, the mod
  476. if [ -f "${modsdir}/${modreq}-files.txt" ]; then
  477. # how many lines is the file list
  478. modsfilelistsize=$(wc -l < "${modsdir}/${modreq}-files.txt")
  479. # if file list is empty
  480. if [ "${modsfilelistsize}" -eq 0 ]; then
  481. fn_mod_required_fail_exist "${modreq}"
  482. fi
  483. else
  484. fn_mod_required_fail_exist "${modreq}"
  485. fi
  486. }
  487. fn_mod_required_fail_exist() {
  488. modreq=$1
  489. # requires one parameter, the mod
  490. fn_script_log_fail "${modreq}-files.txt is empty: unable to find ${modreq} installed"
  491. echo -en "* Unable to find '${modreq}' which is required prior to installing this mod..."
  492. fn_print_fail_eol_nl
  493. core_exit.sh
  494. }
  495. fn_mod_liblist_gam_filenames() {
  496. # clear variables just in case
  497. moddll=""
  498. modso=""
  499. moddylib=""
  500. # default libraries
  501. case ${gamename} in
  502. "Counter-Strike 1.6")
  503. moddll="mp.dll"
  504. modso="cs.so"
  505. moddylib="cs.dylib"
  506. ;;
  507. "Day of Defeat")
  508. moddll="dod.dll"
  509. modso="dod.so"
  510. moddylib="dod.dylib"
  511. ;;
  512. "Team Fortress Classic")
  513. moddll="tfc.dll"
  514. modso="tfc.so"
  515. moddylib="tfc.dylib"
  516. ;;
  517. "Natural Selection")
  518. moddll="ns.dll"
  519. modso="ns_i386.so"
  520. moddylib=""
  521. ;;
  522. "The Specialists")
  523. moddll="mp.dll"
  524. modso="ts_i386.so"
  525. moddylib=""
  526. ;;
  527. "Half-Life: Deathmatch")
  528. moddll="hl.dll"
  529. modso="hl.so"
  530. moddylib="hl.dylib"
  531. ;;
  532. esac
  533. }
  534. # modifiers for liblist.gam to add/remote metamod binaries
  535. fn_mod_install_liblist_gam_file() {
  536. fn_mod_liblist_gam_filenames
  537. if [ -f "${modinstalldir}/liblist.gam" ]; then
  538. # modify the liblist.gam file to initialize Metamod
  539. logentry="sed replace (dlls\\${moddll}) ${modinstalldir}/liblist.gam"
  540. echo -en "modifying gamedll in liblist.gam..."
  541. rpldll="s/dlls\\\\${moddll}/addons\/metamod\/dlls\/metamod.dll/g"
  542. sed -i $rpldll "${modinstalldir}/liblist.gam"
  543. grep -q "addons/metamod/dlls/metamod.dll" "${modinstalldir}/liblist.gam"
  544. exitcode=$?
  545. # if replacement back didn't happen, error out.
  546. if [ "${exitcode}" -ne 0 ]; then
  547. fn_script_log_fail "${logentry}"
  548. fn_print_fail_eol_nl
  549. else
  550. fn_script_log_pass "${logentry}"
  551. fn_print_ok_eol_nl
  552. fi
  553. # modify the liblist.gam file to initialize metamod
  554. logentry="sed replace (dlls\\${modso}) ${modinstalldir}/liblist.gam"
  555. echo -en "modifying gamedll_linux in liblist.gam..."
  556. rplso="s/dlls\/${modso}/addons\/metamod\/dlls\/metamod.so/g"
  557. sed -i $rplso "${modinstalldir}/liblist.gam"
  558. grep -q "addons/metamod/dlls/metamod.so" "${modinstalldir}/liblist.gam"
  559. exitcode=$?
  560. # if replacement back didn't happen, error out
  561. if [ "${exitcode}" -ne 0 ]; then
  562. fn_script_log_fail "${logentry}"
  563. fn_print_fail_eol_nl
  564. else
  565. fn_script_log_pass "${logentry}"
  566. fn_print_ok_eol_nl
  567. fi
  568. # mac os needs to be checked not all mods support mac os
  569. if [ -n "${moddylib}" ]; then
  570. # modify the liblist.gam file to initialize metamod
  571. logentry="sed replace (dlls\\${moddylib}) ${modinstalldir}/liblist.gam"
  572. echo -en "modifying gamedll_osx in liblist.gam..."
  573. rpldylib="s/dlls\/${moddylib}/addons\/metamod\/dlls\/metamod.dylib/g"
  574. sed -i $rpldylib "${modinstalldir}/liblist.gam"
  575. grep -q "addons/metamod/dlls/metamod.dylib" "${modinstalldir}/liblist.gam"
  576. exitcode=$?
  577. # if replacement back didn't happen, error out.
  578. if [ "${exitcode}" -ne 0 ]; then
  579. fn_script_log_fail "${logentry}"
  580. fn_print_fail_eol_nl
  581. else
  582. fn_script_log_pass "${logentry}"
  583. fn_print_ok_eol_nl
  584. fi
  585. fi
  586. fi
  587. }
  588. fn_mod_remove_liblist_gam_file() {
  589. fn_mod_liblist_gam_filenames
  590. if [ -f "${modinstalldir}/liblist.gam" ]; then
  591. # modify the liblist.gam file back to defaults
  592. logentry="sed replace (addons/metamod/dlls/metamod.dll) ${modinstalldir}/liblist.gam"
  593. echo -en "modifying gamedll in liblist.gam..."
  594. rpldll="s/addons\/metamod\/dlls\/metamod.dll/dlls\\\\${moddll}/g"
  595. sed -i $rpldll "${modinstalldir}/liblist.gam"
  596. grep -q "${moddll}" "${modinstalldir}/liblist.gam"
  597. exitcode=$?
  598. # if replacement back didn't happen, error out.
  599. if [ "${exitcode}" -ne 0 ]; then
  600. fn_script_log_fail "${logentry}"
  601. fn_print_fail_eol_nl
  602. else
  603. fn_script_log_pass "${logentry}"
  604. fn_print_ok_eol_nl
  605. fi
  606. # modify the liblist.gam file back to defaults
  607. logentry="sed replace (addons/metamod/dlls/metamod.so) ${modinstalldir}/liblist.gam"
  608. echo -en "modifying gamedll_linux in liblist.gam..."
  609. rplso="s/addons\/metamod\/dlls\/metamod.so/dlls\/${modso}/g"
  610. sed -i $rplso "${modinstalldir}/liblist.gam"
  611. grep -q "${modso}" "${modinstalldir}/liblist.gam"
  612. exitcode=$?
  613. # if replacement back didn't happen, error out
  614. if [ "${exitcode}" -ne 0 ]; then
  615. fn_script_log_fail "${logentry}"
  616. fn_print_fail_eol_nl
  617. else
  618. fn_script_log_pass "${logentry}"
  619. fn_print_ok_eol_nl
  620. fi
  621. # mac os needs to be checked not all mods support mac os
  622. if [ -n "${moddylib}" ]; then
  623. # modify the liblist.gam file back to defaults
  624. logentry="sed replace (addons/metamod/dlls/metamod.dylib) ${modinstalldir}/liblist.gam"
  625. echo -en "modifying gamedll_osx in liblist.gam..."
  626. rpldylib="s/addons\/metamod\/dlls\/metamod.dylib/dlls\/${moddylib}/g"
  627. sed -i $rpldylib "${modinstalldir}/liblist.gam"
  628. grep -q "${moddylib}" "${modinstalldir}/liblist.gam"
  629. # if replacement back didn't happen, error out.
  630. exitcode=$?
  631. if [ "${exitcode}" -ne 0 ]; then
  632. fn_script_log_fail "${logentry}"
  633. fn_print_fail_eol_nl
  634. else
  635. fn_script_log_pass "${logentry}"
  636. fn_print_ok_eol_nl
  637. fi
  638. fi
  639. fi
  640. }
  641. fn_mod_install_amxmodx_file() {
  642. # does plugins.ini exist?
  643. if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
  644. # since it does exist, is the entry already in plugins.ini
  645. logentry="line (linux addons/amxmodx/dlls/amxmodx_mm_i386.so) inserted into ${modinstalldir}/addons/metamod/plugins.ini"
  646. echo -en "adding amxmodx_mm_i386.so in plugins.ini..."
  647. if ! grep -q "amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"; then
  648. # file exists but the entry does not, let's add it
  649. if ! echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" >> "${modinstalldir}/addons/metamod/plugins.ini"; then
  650. fn_script_log_fail "${logentry}"
  651. fn_print_fail_eol_nl
  652. else
  653. fn_script_log_pass "${logentry}"
  654. fn_print_ok_eol_nl
  655. fi
  656. fi
  657. else
  658. # create new file and add the mod to it
  659. if ! echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" > "${modinstalldir}/addons/metamod/plugins.ini"; then
  660. fn_script_log_fail "${logentry}"
  661. fn_print_fail_eol_nl
  662. core_exit.sh
  663. else
  664. fn_script_log_pass "${logentry}"
  665. fn_print_ok_eol_nl
  666. fi
  667. fi
  668. }
  669. fn_mod_remove_amxmodx_file() {
  670. if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
  671. # since it does exist, is the entry already in plugins.ini
  672. logentry="line (linux addons/amxmodx/dlls/amxmodx_mm_i386.so) removed from ${modinstalldir}/addons/metamod/plugins.ini"
  673. echo -en "removing amxmodx_mm_i386.so in plugins.ini..."
  674. # is it found? If so remove it and clean up
  675. if grep -q "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" "${modinstalldir}/addons/metamod/plugins.ini"; then
  676. # delete the line we inserted
  677. sed -i '/linux addons\/amxmodx\/dlls\/amxmodx_mm_i386.so/d' "${modinstalldir}/addons/metamod/plugins.ini"
  678. # remove empty lines
  679. sed -i '/^$/d' "${modinstalldir}/addons/metamod/plugins.ini"
  680. exitcode=$?
  681. if [ "${exitcode}" -ne 0 ]; then
  682. fn_script_log_fail "${logentry}"
  683. fn_print_fail_eol_nl
  684. else
  685. fn_script_log_pass "${logentry}"
  686. fn_print_ok_eol_nl
  687. fi
  688. # if file is empty, remove it.
  689. if [ -f "${modinstalldir}/addons/metamod/plugins.ini" ]; then
  690. rm -f "${modinstalldir}/addons/metamod/plugins.ini"
  691. fn_script_log_pass "file removed ${modinstalldir}/addons/metamod/plugins.ini because it was empty"
  692. fi
  693. fi
  694. fi
  695. }
  696. ## Database initialisation.
  697. mods_list.sh
  698. fn_mods_available