core_functions.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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_getopt.sh(){
  71. functionfile="${FUNCNAME}"
  72. fn_fetch_core_dl
  73. }
  74. core_messages.sh(){
  75. functionfile="${FUNCNAME}"
  76. fn_fetch_core_dl
  77. }
  78. core_dl.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. if [ -d "${scriptlogdir}" ]; then
  135. fn_scriptlog "${servername}"
  136. fi
  137. command_stop.sh
  138. command_start.sh
  139. }
  140. # Checks
  141. check.sh(){
  142. functionfile="${FUNCNAME}"
  143. fn_fetch_function
  144. }
  145. check_config.sh(){
  146. functionfile="${FUNCNAME}"
  147. fn_fetch_function
  148. }
  149. check_deps.sh(){
  150. functionfile="${FUNCNAME}"
  151. fn_fetch_function
  152. }
  153. check_glibc.sh(){
  154. functionfile="${FUNCNAME}"
  155. fn_fetch_function
  156. }
  157. check_ip.sh(){
  158. functionfile="${FUNCNAME}"
  159. fn_fetch_function
  160. }
  161. check_logs.sh(){
  162. functionfile="${FUNCNAME}"
  163. fn_fetch_function
  164. }
  165. check_permissions.sh(){
  166. functionfile="${FUNCNAME}"
  167. fn_fetch_function
  168. }
  169. check_root.sh(){
  170. functionfile="${FUNCNAME}"
  171. fn_fetch_function
  172. }
  173. check_status.sh(){
  174. functionfile="${FUNCNAME}"
  175. fn_fetch_function
  176. }
  177. check_steamcmd.sh(){
  178. functionfile="${FUNCNAME}"
  179. fn_fetch_function
  180. }
  181. check_system_dir.sh(){
  182. functionfile="${FUNCNAME}"
  183. fn_fetch_function
  184. }
  185. check_tmux.sh(){
  186. functionfile="${FUNCNAME}"
  187. fn_fetch_function
  188. }
  189. # Compress
  190. compress_unreal2_maps.sh(){
  191. functionfile="${FUNCNAME}"
  192. fn_fetch_function
  193. }
  194. compress_ut99_maps.sh(){
  195. functionfile="${FUNCNAME}"
  196. fn_fetch_function
  197. }
  198. # Dev
  199. command_dev_debug.sh(){
  200. functionfile="${FUNCNAME}"
  201. fn_fetch_function
  202. }
  203. command_dev_detect_deps.sh(){
  204. functionfile="${FUNCNAME}"
  205. fn_fetch_function
  206. }
  207. # Fix
  208. fix.sh(){
  209. functionfile="${FUNCNAME}"
  210. fn_fetch_function
  211. }
  212. fix_arma3.sh(){
  213. functionfile="${FUNCNAME}"
  214. fn_fetch_function
  215. }
  216. fix_csgo.sh(){
  217. functionfile="${FUNCNAME}"
  218. fn_fetch_function
  219. }
  220. fix_dst.sh(){
  221. functionfile="${FUNCNAME}"
  222. fn_fetch_function
  223. }
  224. fix_ins.sh(){
  225. functionfile="${FUNCNAME}"
  226. fn_fetch_function
  227. }
  228. fix_steamcmd.sh(){
  229. functionfile="${FUNCNAME}"
  230. fn_fetch_function
  231. }
  232. fix_glibc.sh(){
  233. functionfile="${FUNCNAME}"
  234. fn_fetch_function
  235. }
  236. fix_ro.sh(){
  237. functionfile="${FUNCNAME}"
  238. fn_fetch_function
  239. }
  240. fix_kf.sh(){
  241. functionfile="${FUNCNAME}"
  242. fn_fetch_function
  243. }
  244. fix_ut2k4.sh(){
  245. functionfile="${FUNCNAME}"
  246. fn_fetch_function
  247. }
  248. # Info
  249. info_config.sh(){
  250. functionfile="${FUNCNAME}"
  251. fn_fetch_function
  252. }
  253. info_distro.sh(){
  254. functionfile="${FUNCNAME}"
  255. fn_fetch_function
  256. }
  257. info_glibc.sh(){
  258. functionfile="${FUNCNAME}"
  259. fn_fetch_function
  260. }
  261. info_parms.sh(){
  262. functionfile="${FUNCNAME}"
  263. fn_fetch_function
  264. }
  265. # Alert
  266. alert.sh(){
  267. functionfile="${FUNCNAME}"
  268. fn_fetch_function
  269. }
  270. alert_email.sh(){
  271. functionfile="${FUNCNAME}"
  272. fn_fetch_function
  273. }
  274. alert_pushbullet.sh(){
  275. functionfile="${FUNCNAME}"
  276. fn_fetch_function
  277. }
  278. # Logs
  279. logs.sh(){
  280. functionfile="${FUNCNAME}"
  281. fn_fetch_function
  282. }
  283. # Monitor
  284. monitor_gsquery.sh(){
  285. functionfile="${FUNCNAME}"
  286. fn_fetch_function
  287. }
  288. # Update
  289. update_check.sh(){
  290. functionfile="${FUNCNAME}"
  291. fn_fetch_function
  292. }
  293. command_update_functions.sh(){
  294. functionfile="${FUNCNAME}"
  295. fn_fetch_function
  296. }
  297. update_dl.sh(){
  298. functionfile="${FUNCNAME}"
  299. fn_fetch_function
  300. }
  301. fn_update_functions.sh(){
  302. functionfile="${FUNCNAME}"
  303. fn_fetch_function
  304. }
  305. #
  306. ## Installer functions
  307. #
  308. fn_autoinstall(){
  309. autoinstall=1
  310. command_install.sh
  311. }
  312. install_complete.sh(){
  313. functionfile="${FUNCNAME}"
  314. fn_fetch_function
  315. }
  316. install_config.sh(){
  317. functionfile="${FUNCNAME}"
  318. fn_fetch_function
  319. }
  320. install_gsquery.sh(){
  321. functionfile="${FUNCNAME}"
  322. fn_fetch_function
  323. }
  324. install_gslt.sh(){
  325. functionfile="${FUNCNAME}"
  326. fn_fetch_function
  327. }
  328. install_header.sh(){
  329. functionfile="${FUNCNAME}"
  330. fn_fetch_function
  331. }
  332. install_logs.sh(){
  333. functionfile="${FUNCNAME}"
  334. fn_fetch_function
  335. }
  336. install_retry.sh(){
  337. functionfile="${FUNCNAME}"
  338. fn_fetch_function
  339. }
  340. install_server_dir.sh(){
  341. functionfile="${FUNCNAME}"
  342. fn_fetch_function
  343. }
  344. install_server_files.sh(){
  345. functionfile="${FUNCNAME}"
  346. fn_fetch_function
  347. }
  348. install_steamcmd.sh(){
  349. functionfile="${FUNCNAME}"
  350. fn_fetch_function
  351. }
  352. install_ts3.sh(){
  353. functionfile="${FUNCNAME}"
  354. fn_fetch_function
  355. }
  356. install_ts3db.sh(){
  357. functionfile="${FUNCNAME}"
  358. fn_fetch_function
  359. }
  360. install_ut2k4.sh(){
  361. functionfile="${FUNCNAME}"
  362. fn_fetch_function
  363. }
  364. install_dl_ut2k4.sh(){
  365. functionfile="${FUNCNAME}"
  366. fn_fetch_function
  367. }
  368. install_ut2k4_key.sh(){
  369. functionfile="${FUNCNAME}"
  370. fn_fetch_function
  371. }
  372. fix_ut99.sh(){
  373. functionfile="${FUNCNAME}"
  374. fn_fetch_function
  375. }
  376. # Calls on-screen messages
  377. core_messages.sh
  378. #Calls file downloader
  379. core_dl.sh