core_functions.sh 7.8 KB

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