core_functions.sh 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. #!/bin/bash
  2. # LGSM core_functions.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Defines all functions to allow download and execution of functions using fn_fetch_function.
  6. # This function is called first before any other function. Without this file other functions will not load.
  7. # Fixes for legacy code
  8. if [ "${gamename}" == "ARK: Survivial Evolved" ]; then
  9. gamename="ARK: Survival Evolved"
  10. elif [ "${gamename}" == "Teamspeak 3" ]; then
  11. gamename="TeamSpeak 3"
  12. elif [ "${gamename}" == "Counter Strike: Global Offensive" ]; then
  13. gamename="Counter-Strike: Global Offensive"
  14. elif [ "${gamename}" == "Counter Strike: Source" ]; then
  15. gamename="Counter-Strike: Source"
  16. elif [ "${gamename}" == "Quake Live" ]; then
  17. engine="idtech3_ql"
  18. fi
  19. if [ "${emailnotification}" == "on" ]; then
  20. emailalert="on"
  21. fi
  22. ## Code/functions for legacy servers
  23. fn_functions(){
  24. functionfile="${FUNCNAME}"
  25. fn_fetch_function
  26. }
  27. fn_getopt(){
  28. functionfile="${FUNCNAME}"
  29. fn_fetch_function
  30. }
  31. ## In case older versions are missing these vars
  32. if [ -z "${lgsmdir}" ]||[ -z "${functionsdir}" ]||[ -z "${libdir}" ]||[ -z "${tmpdir}" ]; then
  33. lgsmdir="${rootdir}/lgsm"
  34. functionsdir="${lgsmdir}/functions"
  35. libdir="${lgsmdir}/lib"
  36. tmpdir="${lgsmdir}/tmp"
  37. fi
  38. ## fn_fetch_core_dl placed here to allow legacy servers to still download core functions
  39. fn_fetch_core_dl(){
  40. github_file_url_dir="lgsm/functions"
  41. github_file_url_name="${functionfile}"
  42. filedir="${functionsdir}"
  43. filename="${github_file_url_name}"
  44. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  45. # If the file is missing, then download
  46. if [ ! -f "${filedir}/${filename}" ]; then
  47. if [ ! -d "${filedir}" ]; then
  48. mkdir -p "${filedir}"
  49. fi
  50. echo -e " fetching ${filename}...\c"
  51. # Check curl exists and use available path
  52. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  53. for curlcmd in ${curlpaths}
  54. do
  55. if [ -x "${curlcmd}" ]; then
  56. break
  57. fi
  58. done
  59. # If curl exists download file
  60. if [ "$(basename ${curlcmd})" == "curl" ]; then
  61. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  62. if [ $? -ne 0 ]; then
  63. echo -e "${red}FAIL${default}\n"
  64. echo "${curlfetch}"
  65. echo -e "${githuburl}\n"
  66. exit 1
  67. else
  68. echo -e "${green}OK${default}"
  69. fi
  70. else
  71. echo -e "${red}FAIL${default}\n"
  72. echo "Curl is not installed!"
  73. echo -e ""
  74. exit 1
  75. fi
  76. chmod +x "${filedir}/${filename}"
  77. fi
  78. source "${filedir}/${filename}"
  79. }
  80. # Creates tmp dir if missing
  81. if [ ! -d "${tmpdir}" ]; then
  82. mkdir -p "${tmpdir}"
  83. fi
  84. # Core
  85. core_dl.sh(){
  86. # Functions are defined in core_functions.sh.
  87. functionfile="${FUNCNAME}"
  88. fn_fetch_core_dl
  89. }
  90. core_exit.sh(){
  91. functionfile="${FUNCNAME}"
  92. fn_fetch_core_dl
  93. }
  94. core_getopt.sh(){
  95. functionfile="${FUNCNAME}"
  96. fn_fetch_core_dl
  97. }
  98. core_trap.sh(){
  99. functionfile="${FUNCNAME}"
  100. fn_fetch_core_dl
  101. }
  102. core_messages.sh(){
  103. functionfile="${FUNCNAME}"
  104. fn_fetch_core_dl
  105. }
  106. # Commands
  107. command_console.sh(){
  108. functionfile="${FUNCNAME}"
  109. fn_fetch_function
  110. }
  111. command_debug.sh(){
  112. functionfile="${FUNCNAME}"
  113. fn_fetch_function
  114. }
  115. command_postdetails.sh(){
  116. functionfile="${FUNCNAME}"
  117. tempffname="${functionfile}"
  118. # First, grab the command_postdetails.sh file
  119. fn_fetch_function
  120. # But then next, command_details.sh needs to also be pulled
  121. # because command_postdetails.sh sources its functions -CedarLUG
  122. functionfile="command_details.sh"
  123. fn_fetch_function
  124. functionfile="${tempffname}"
  125. }
  126. command_details.sh(){
  127. functionfile="${FUNCNAME}"
  128. fn_fetch_function
  129. }
  130. command_test_alert.sh(){
  131. functionfile="${FUNCNAME}"
  132. fn_fetch_function
  133. }
  134. command_backup.sh(){
  135. functionfile="${FUNCNAME}"
  136. fn_fetch_function
  137. }
  138. command_monitor.sh(){
  139. functionfile="${FUNCNAME}"
  140. fn_fetch_function
  141. }
  142. command_start.sh(){
  143. functionfile="${FUNCNAME}"
  144. fn_fetch_function
  145. }
  146. command_stop.sh(){
  147. functionfile="${FUNCNAME}"
  148. fn_fetch_function
  149. }
  150. command_validate.sh(){
  151. functionfile="${FUNCNAME}"
  152. fn_fetch_function
  153. }
  154. command_install.sh(){
  155. functionfile="${FUNCNAME}"
  156. fn_fetch_function
  157. }
  158. command_install_resources_mta.sh(){
  159. functionfile="${FUNCNAME}"
  160. fn_fetch_function
  161. }
  162. command_mods_install.sh(){
  163. functionfile="${FUNCNAME}"
  164. fn_fetch_function
  165. }
  166. command_mods_update.sh(){
  167. functionfile="${FUNCNAME}"
  168. fn_fetch_function
  169. }
  170. command_mods_remove.sh(){
  171. functionfile="${FUNCNAME}"
  172. fn_fetch_function
  173. }
  174. command_fastdl.sh(){
  175. functionfile="${FUNCNAME}"
  176. fn_fetch_function
  177. }
  178. command_ts3_server_pass.sh(){
  179. functionfile="${FUNCNAME}"
  180. fn_fetch_function
  181. }
  182. command_restart.sh(){
  183. functionfile="${FUNCNAME}"
  184. fn_fetch_function
  185. }
  186. # Checks
  187. check.sh(){
  188. functionfile="${FUNCNAME}"
  189. fn_fetch_function
  190. }
  191. check_config.sh(){
  192. functionfile="${FUNCNAME}"
  193. fn_fetch_function
  194. }
  195. check_deps.sh(){
  196. functionfile="${FUNCNAME}"
  197. fn_fetch_function
  198. }
  199. check_executable.sh(){
  200. functionfile="${FUNCNAME}"
  201. fn_fetch_function
  202. }
  203. check_glibc.sh(){
  204. functionfile="${FUNCNAME}"
  205. fn_fetch_function
  206. }
  207. check_ip.sh(){
  208. functionfile="${FUNCNAME}"
  209. fn_fetch_function
  210. }
  211. check_logs.sh(){
  212. functionfile="${FUNCNAME}"
  213. fn_fetch_function
  214. }
  215. check_permissions.sh(){
  216. functionfile="${FUNCNAME}"
  217. fn_fetch_function
  218. }
  219. check_root.sh(){
  220. functionfile="${FUNCNAME}"
  221. fn_fetch_function
  222. }
  223. check_status.sh(){
  224. functionfile="${FUNCNAME}"
  225. fn_fetch_function
  226. }
  227. check_steamcmd.sh(){
  228. functionfile="${FUNCNAME}"
  229. fn_fetch_function
  230. }
  231. check_system_dir.sh(){
  232. functionfile="${FUNCNAME}"
  233. fn_fetch_function
  234. }
  235. check_system_requirements.sh(){
  236. functionfile="${FUNCNAME}"
  237. fn_fetch_function
  238. }
  239. check_tmuxception.sh(){
  240. functionfile="${FUNCNAME}"
  241. fn_fetch_function
  242. }
  243. # Compress
  244. compress_unreal2_maps.sh(){
  245. functionfile="${FUNCNAME}"
  246. fn_fetch_function
  247. }
  248. compress_ut99_maps.sh(){
  249. functionfile="${FUNCNAME}"
  250. fn_fetch_function
  251. }
  252. # Mods
  253. mods_list.sh(){
  254. functionfile="${FUNCNAME}"
  255. fn_fetch_function
  256. }
  257. mods_core.sh(){
  258. functionfile="${FUNCNAME}"
  259. fn_fetch_function
  260. }
  261. # Dev
  262. command_dev_debug.sh(){
  263. functionfile="${FUNCNAME}"
  264. fn_fetch_function
  265. }
  266. command_dev_detect_deps.sh(){
  267. functionfile="${FUNCNAME}"
  268. fn_fetch_function
  269. }
  270. command_dev_detect_glibc.sh(){
  271. functionfile="${FUNCNAME}"
  272. fn_fetch_function
  273. }
  274. command_dev_detect_ldd.sh(){
  275. functionfile="${FUNCNAME}"
  276. fn_fetch_function
  277. }
  278. # Fix
  279. fix.sh(){
  280. functionfile="${FUNCNAME}"
  281. fn_fetch_function
  282. }
  283. fix_arma3.sh(){
  284. functionfile="${FUNCNAME}"
  285. fn_fetch_function
  286. }
  287. fix_csgo.sh(){
  288. functionfile="${FUNCNAME}"
  289. fn_fetch_function
  290. }
  291. fix_dst.sh(){
  292. functionfile="${FUNCNAME}"
  293. fn_fetch_function
  294. }
  295. fix_ges.sh(){
  296. functionfile="${FUNCNAME}"
  297. fn_fetch_function
  298. }
  299. fix_ins.sh(){
  300. functionfile="${FUNCNAME}"
  301. fn_fetch_function
  302. }
  303. fix_steamcmd.sh(){
  304. functionfile="${FUNCNAME}"
  305. fn_fetch_function
  306. }
  307. fix_glibc.sh(){
  308. functionfile="${FUNCNAME}"
  309. fn_fetch_function
  310. }
  311. fix_ro.sh(){
  312. functionfile="${FUNCNAME}"
  313. fn_fetch_function
  314. }
  315. fix_kf.sh(){
  316. functionfile="${FUNCNAME}"
  317. fn_fetch_function
  318. }
  319. fix_ut2k4.sh(){
  320. functionfile="${FUNCNAME}"
  321. fn_fetch_function
  322. }
  323. fix_ut.sh(){
  324. functionfile="${FUNCNAME}"
  325. fn_fetch_function
  326. }
  327. fix_rust.sh(){
  328. functionfile="${FUNCNAME}"
  329. fn_fetch_function
  330. }
  331. fix_mta.sh(){
  332. functionfile="${FUNCNAME}"
  333. fn_fetch_function
  334. }
  335. # Info
  336. info_config.sh(){
  337. functionfile="${FUNCNAME}"
  338. fn_fetch_function
  339. }
  340. info_distro.sh(){
  341. functionfile="${FUNCNAME}"
  342. fn_fetch_function
  343. }
  344. info_glibc.sh(){
  345. functionfile="${FUNCNAME}"
  346. fn_fetch_function
  347. }
  348. info_parms.sh(){
  349. functionfile="${FUNCNAME}"
  350. fn_fetch_function
  351. }
  352. # Alert
  353. alert.sh(){
  354. functionfile="${FUNCNAME}"
  355. fn_fetch_function
  356. }
  357. alert_email.sh(){
  358. functionfile="${FUNCNAME}"
  359. fn_fetch_function
  360. }
  361. alert_pushbullet.sh(){
  362. functionfile="${FUNCNAME}"
  363. fn_fetch_function
  364. }
  365. # Logs
  366. logs.sh(){
  367. functionfile="${FUNCNAME}"
  368. fn_fetch_function
  369. }
  370. # Monitor
  371. monitor_gsquery.sh(){
  372. functionfile="${FUNCNAME}"
  373. fn_fetch_function
  374. }
  375. # Update
  376. command_update_functions.sh(){
  377. functionfile="${FUNCNAME}"
  378. fn_fetch_function
  379. }
  380. command_update.sh(){
  381. functionfile="${FUNCNAME}"
  382. fn_fetch_function
  383. }
  384. update_ts3.sh(){
  385. functionfile="${FUNCNAME}"
  386. fn_fetch_function
  387. }
  388. update_minecraft.sh(){
  389. functionfile="${FUNCNAME}"
  390. fn_fetch_function
  391. }
  392. update_mumble.sh(){
  393. functionfile="${FUNCNAME}"
  394. fn_fetch_function
  395. }
  396. update_mta.sh(){
  397. functionfile="${FUNCNAME}"
  398. fn_fetch_function
  399. }
  400. update_factorio.sh(){
  401. functionfile="${FUNCNAME}"
  402. fn_fetch_function
  403. }
  404. update_steamcmd.sh(){
  405. functionfile="${FUNCNAME}"
  406. fn_fetch_function
  407. }
  408. fn_update_functions.sh(){
  409. functionfile="${FUNCNAME}"
  410. fn_fetch_function
  411. }
  412. #
  413. ## Installer functions
  414. #
  415. fn_autoinstall(){
  416. autoinstall=1
  417. command_install.sh
  418. }
  419. install_complete.sh(){
  420. functionfile="${FUNCNAME}"
  421. fn_fetch_function
  422. }
  423. install_config.sh(){
  424. functionfile="${FUNCNAME}"
  425. fn_fetch_function
  426. }
  427. install_factorio_save.sh(){
  428. functionfile="${FUNCNAME}"
  429. fn_fetch_function
  430. }
  431. install_dst_token.sh(){
  432. functionfile="${FUNCNAME}"
  433. fn_fetch_function
  434. }
  435. install_gsquery.sh(){
  436. functionfile="${FUNCNAME}"
  437. fn_fetch_function
  438. }
  439. install_gslt.sh(){
  440. functionfile="${FUNCNAME}"
  441. fn_fetch_function
  442. }
  443. install_header.sh(){
  444. functionfile="${FUNCNAME}"
  445. fn_fetch_function
  446. }
  447. install_logs.sh(){
  448. functionfile="${FUNCNAME}"
  449. fn_fetch_function
  450. }
  451. install_minecraft_eula.sh(){
  452. functionfile="${FUNCNAME}"
  453. fn_fetch_function
  454. }
  455. install_unreal_tournament_eula.sh(){
  456. functionfile="${FUNCNAME}"
  457. fn_fetch_function
  458. }
  459. install_retry.sh(){
  460. functionfile="${FUNCNAME}"
  461. fn_fetch_function
  462. }
  463. install_server_dir.sh(){
  464. functionfile="${FUNCNAME}"
  465. fn_fetch_function
  466. }
  467. install_server_files.sh(){
  468. functionfile="${FUNCNAME}"
  469. fn_fetch_function
  470. }
  471. install_steamcmd.sh(){
  472. functionfile="${FUNCNAME}"
  473. fn_fetch_function
  474. }
  475. install_ts3.sh(){
  476. functionfile="${FUNCNAME}"
  477. fn_fetch_function
  478. }
  479. install_ts3db.sh(){
  480. functionfile="${FUNCNAME}"
  481. fn_fetch_function
  482. }
  483. install_ut2k4.sh(){
  484. functionfile="${FUNCNAME}"
  485. fn_fetch_function
  486. }
  487. install_dl_ut2k4.sh(){
  488. functionfile="${FUNCNAME}"
  489. fn_fetch_function
  490. }
  491. install_ut2k4_key.sh(){
  492. functionfile="${FUNCNAME}"
  493. fn_fetch_function
  494. }
  495. # Calls the global Ctrl-C trap
  496. core_trap.sh
  497. # Calls on-screen messages
  498. core_messages.sh
  499. #Calls file downloader
  500. core_dl.sh