core_functions.sh 9.0 KB

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