core_functions.sh 7.0 KB

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