core_functions.sh 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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_mods_install.sh(){
  159. functionfile="${FUNCNAME}"
  160. fn_fetch_function
  161. }
  162. command_mods_update.sh(){
  163. functionfile="${FUNCNAME}"
  164. fn_fetch_function
  165. }
  166. command_mods_remove.sh(){
  167. functionfile="${FUNCNAME}"
  168. fn_fetch_function
  169. }
  170. command_fastdl.sh(){
  171. functionfile="${FUNCNAME}"
  172. fn_fetch_function
  173. }
  174. command_ts3_server_pass.sh(){
  175. functionfile="${FUNCNAME}"
  176. fn_fetch_function
  177. }
  178. command_restart.sh(){
  179. functionfile="${FUNCNAME}"
  180. fn_fetch_function
  181. }
  182. # Checks
  183. check.sh(){
  184. functionfile="${FUNCNAME}"
  185. fn_fetch_function
  186. }
  187. check_config.sh(){
  188. functionfile="${FUNCNAME}"
  189. fn_fetch_function
  190. }
  191. check_deps.sh(){
  192. functionfile="${FUNCNAME}"
  193. fn_fetch_function
  194. }
  195. check_executable.sh(){
  196. functionfile="${FUNCNAME}"
  197. fn_fetch_function
  198. }
  199. check_glibc.sh(){
  200. functionfile="${FUNCNAME}"
  201. fn_fetch_function
  202. }
  203. check_ip.sh(){
  204. functionfile="${FUNCNAME}"
  205. fn_fetch_function
  206. }
  207. check_logs.sh(){
  208. functionfile="${FUNCNAME}"
  209. fn_fetch_function
  210. }
  211. check_permissions.sh(){
  212. functionfile="${FUNCNAME}"
  213. fn_fetch_function
  214. }
  215. check_root.sh(){
  216. functionfile="${FUNCNAME}"
  217. fn_fetch_function
  218. }
  219. check_status.sh(){
  220. functionfile="${FUNCNAME}"
  221. fn_fetch_function
  222. }
  223. check_steamcmd.sh(){
  224. functionfile="${FUNCNAME}"
  225. fn_fetch_function
  226. }
  227. check_system_dir.sh(){
  228. functionfile="${FUNCNAME}"
  229. fn_fetch_function
  230. }
  231. check_system_requirements.sh(){
  232. functionfile="${FUNCNAME}"
  233. fn_fetch_function
  234. }
  235. check_tmuxception.sh(){
  236. functionfile="${FUNCNAME}"
  237. fn_fetch_function
  238. }
  239. # Compress
  240. compress_unreal2_maps.sh(){
  241. functionfile="${FUNCNAME}"
  242. fn_fetch_function
  243. }
  244. compress_ut99_maps.sh(){
  245. functionfile="${FUNCNAME}"
  246. fn_fetch_function
  247. }
  248. # Mods
  249. mods_list.sh(){
  250. functionfile="${FUNCNAME}"
  251. fn_fetch_function
  252. }
  253. mods_core.sh(){
  254. functionfile="${FUNCNAME}"
  255. fn_fetch_function
  256. }
  257. # Dev
  258. command_dev_debug.sh(){
  259. functionfile="${FUNCNAME}"
  260. fn_fetch_function
  261. }
  262. command_dev_detect_deps.sh(){
  263. functionfile="${FUNCNAME}"
  264. fn_fetch_function
  265. }
  266. command_dev_detect_glibc.sh(){
  267. functionfile="${FUNCNAME}"
  268. fn_fetch_function
  269. }
  270. command_dev_detect_ldd.sh(){
  271. functionfile="${FUNCNAME}"
  272. fn_fetch_function
  273. }
  274. # Fix
  275. fix.sh(){
  276. functionfile="${FUNCNAME}"
  277. fn_fetch_function
  278. }
  279. fix_arma3.sh(){
  280. functionfile="${FUNCNAME}"
  281. fn_fetch_function
  282. }
  283. fix_csgo.sh(){
  284. functionfile="${FUNCNAME}"
  285. fn_fetch_function
  286. }
  287. fix_dst.sh(){
  288. functionfile="${FUNCNAME}"
  289. fn_fetch_function
  290. }
  291. fix_ges.sh(){
  292. functionfile="${FUNCNAME}"
  293. fn_fetch_function
  294. }
  295. fix_ins.sh(){
  296. functionfile="${FUNCNAME}"
  297. fn_fetch_function
  298. }
  299. fix_steamcmd.sh(){
  300. functionfile="${FUNCNAME}"
  301. fn_fetch_function
  302. }
  303. fix_glibc.sh(){
  304. functionfile="${FUNCNAME}"
  305. fn_fetch_function
  306. }
  307. fix_ro.sh(){
  308. functionfile="${FUNCNAME}"
  309. fn_fetch_function
  310. }
  311. fix_kf.sh(){
  312. functionfile="${FUNCNAME}"
  313. fn_fetch_function
  314. }
  315. fix_ut2k4.sh(){
  316. functionfile="${FUNCNAME}"
  317. fn_fetch_function
  318. }
  319. fix_ut.sh(){
  320. functionfile="${FUNCNAME}"
  321. fn_fetch_function
  322. }
  323. fix_rust.sh(){
  324. functionfile="${FUNCNAME}"
  325. fn_fetch_function
  326. }
  327. # Info
  328. info_config.sh(){
  329. functionfile="${FUNCNAME}"
  330. fn_fetch_function
  331. }
  332. info_distro.sh(){
  333. functionfile="${FUNCNAME}"
  334. fn_fetch_function
  335. }
  336. info_glibc.sh(){
  337. functionfile="${FUNCNAME}"
  338. fn_fetch_function
  339. }
  340. info_parms.sh(){
  341. functionfile="${FUNCNAME}"
  342. fn_fetch_function
  343. }
  344. # Alert
  345. alert.sh(){
  346. functionfile="${FUNCNAME}"
  347. fn_fetch_function
  348. }
  349. alert_email.sh(){
  350. functionfile="${FUNCNAME}"
  351. fn_fetch_function
  352. }
  353. alert_pushbullet.sh(){
  354. functionfile="${FUNCNAME}"
  355. fn_fetch_function
  356. }
  357. # Logs
  358. logs.sh(){
  359. functionfile="${FUNCNAME}"
  360. fn_fetch_function
  361. }
  362. # Monitor
  363. monitor_gsquery.sh(){
  364. functionfile="${FUNCNAME}"
  365. fn_fetch_function
  366. }
  367. # Update
  368. command_update_functions.sh(){
  369. functionfile="${FUNCNAME}"
  370. fn_fetch_function
  371. }
  372. command_update.sh(){
  373. functionfile="${FUNCNAME}"
  374. fn_fetch_function
  375. }
  376. update_ts3.sh(){
  377. functionfile="${FUNCNAME}"
  378. fn_fetch_function
  379. }
  380. update_minecraft.sh(){
  381. functionfile="${FUNCNAME}"
  382. fn_fetch_function
  383. }
  384. update_mumble.sh(){
  385. functionfile="${FUNCNAME}"
  386. fn_fetch_function
  387. }
  388. update_factorio.sh(){
  389. functionfile="${FUNCNAME}"
  390. fn_fetch_function
  391. }
  392. update_steamcmd.sh(){
  393. functionfile="${FUNCNAME}"
  394. fn_fetch_function
  395. }
  396. fn_update_functions.sh(){
  397. functionfile="${FUNCNAME}"
  398. fn_fetch_function
  399. }
  400. #
  401. ## Installer functions
  402. #
  403. fn_autoinstall(){
  404. autoinstall=1
  405. command_install.sh
  406. }
  407. install_complete.sh(){
  408. functionfile="${FUNCNAME}"
  409. fn_fetch_function
  410. }
  411. install_config.sh(){
  412. functionfile="${FUNCNAME}"
  413. fn_fetch_function
  414. }
  415. install_factorio_save.sh(){
  416. functionfile="${FUNCNAME}"
  417. fn_fetch_function
  418. }
  419. install_dst_token.sh(){
  420. functionfile="${FUNCNAME}"
  421. fn_fetch_function
  422. }
  423. install_gsquery.sh(){
  424. functionfile="${FUNCNAME}"
  425. fn_fetch_function
  426. }
  427. install_gslt.sh(){
  428. functionfile="${FUNCNAME}"
  429. fn_fetch_function
  430. }
  431. install_header.sh(){
  432. functionfile="${FUNCNAME}"
  433. fn_fetch_function
  434. }
  435. install_logs.sh(){
  436. functionfile="${FUNCNAME}"
  437. fn_fetch_function
  438. }
  439. install_minecraft_eula.sh(){
  440. functionfile="${FUNCNAME}"
  441. fn_fetch_function
  442. }
  443. install_unreal_tournament_eula.sh(){
  444. functionfile="${FUNCNAME}"
  445. fn_fetch_function
  446. }
  447. install_retry.sh(){
  448. functionfile="${FUNCNAME}"
  449. fn_fetch_function
  450. }
  451. install_server_dir.sh(){
  452. functionfile="${FUNCNAME}"
  453. fn_fetch_function
  454. }
  455. install_server_files.sh(){
  456. functionfile="${FUNCNAME}"
  457. fn_fetch_function
  458. }
  459. install_steamcmd.sh(){
  460. functionfile="${FUNCNAME}"
  461. fn_fetch_function
  462. }
  463. install_ts3.sh(){
  464. functionfile="${FUNCNAME}"
  465. fn_fetch_function
  466. }
  467. install_ts3db.sh(){
  468. functionfile="${FUNCNAME}"
  469. fn_fetch_function
  470. }
  471. install_ut2k4.sh(){
  472. functionfile="${FUNCNAME}"
  473. fn_fetch_function
  474. }
  475. install_dl_ut2k4.sh(){
  476. functionfile="${FUNCNAME}"
  477. fn_fetch_function
  478. }
  479. install_ut2k4_key.sh(){
  480. functionfile="${FUNCNAME}"
  481. fn_fetch_function
  482. }
  483. # Calls the global Ctrl-C trap
  484. core_trap.sh
  485. # Calls on-screen messages
  486. core_messages.sh
  487. #Calls file downloader
  488. core_dl.sh