core_functions.sh 9.4 KB

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