core_functions.sh 7.4 KB

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