core_functions.sh 8.3 KB

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