core_functions.sh 7.2 KB

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