core_functions.sh 8.7 KB

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