core_functions.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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_trap.sh(){
  79. functionfile="${FUNCNAME}"
  80. fn_fetch_core_dl
  81. }
  82. core_messages.sh(){
  83. functionfile="${FUNCNAME}"
  84. fn_fetch_core_dl
  85. }
  86. # Command
  87. command_console.sh(){
  88. functionfile="${FUNCNAME}"
  89. fn_fetch_function
  90. }
  91. command_debug.sh(){
  92. functionfile="${FUNCNAME}"
  93. fn_fetch_function
  94. }
  95. command_details.sh(){
  96. functionfile="${FUNCNAME}"
  97. fn_fetch_function
  98. }
  99. command_test_alert.sh(){
  100. functionfile="${FUNCNAME}"
  101. fn_fetch_function
  102. }
  103. command_backup.sh(){
  104. functionfile="${FUNCNAME}"
  105. fn_fetch_function
  106. }
  107. command_monitor.sh(){
  108. functionfile="${FUNCNAME}"
  109. fn_fetch_function
  110. }
  111. command_start.sh(){
  112. functionfile="${FUNCNAME}"
  113. fn_fetch_function
  114. }
  115. command_stop.sh(){
  116. functionfile="${FUNCNAME}"
  117. fn_fetch_function
  118. }
  119. command_validate.sh(){
  120. functionfile="${FUNCNAME}"
  121. fn_fetch_function
  122. }
  123. command_install.sh(){
  124. functionfile="${FUNCNAME}"
  125. fn_fetch_function
  126. }
  127. command_fastdl.sh(){
  128. functionfile="${FUNCNAME}"
  129. fn_fetch_function
  130. }
  131. command_ts3_server_pass.sh(){
  132. functionfile="${FUNCNAME}"
  133. fn_fetch_function
  134. }
  135. command_restart.sh(){
  136. functionfile="${FUNCNAME}"
  137. fn_fetch_function
  138. }
  139. # Checks
  140. check.sh(){
  141. functionfile="${FUNCNAME}"
  142. fn_fetch_function
  143. }
  144. check_config.sh(){
  145. functionfile="${FUNCNAME}"
  146. fn_fetch_function
  147. }
  148. check_deps.sh(){
  149. functionfile="${FUNCNAME}"
  150. fn_fetch_function
  151. }
  152. check_glibc.sh(){
  153. functionfile="${FUNCNAME}"
  154. fn_fetch_function
  155. }
  156. check_ip.sh(){
  157. functionfile="${FUNCNAME}"
  158. fn_fetch_function
  159. }
  160. check_logs.sh(){
  161. functionfile="${FUNCNAME}"
  162. fn_fetch_function
  163. }
  164. check_permissions.sh(){
  165. functionfile="${FUNCNAME}"
  166. fn_fetch_function
  167. }
  168. check_root.sh(){
  169. functionfile="${FUNCNAME}"
  170. fn_fetch_function
  171. }
  172. check_status.sh(){
  173. functionfile="${FUNCNAME}"
  174. fn_fetch_function
  175. }
  176. check_steamcmd.sh(){
  177. functionfile="${FUNCNAME}"
  178. fn_fetch_function
  179. }
  180. check_system_dir.sh(){
  181. functionfile="${FUNCNAME}"
  182. fn_fetch_function
  183. }
  184. check_tmux.sh(){
  185. functionfile="${FUNCNAME}"
  186. fn_fetch_function
  187. }
  188. # Compress
  189. compress_unreal2_maps.sh(){
  190. functionfile="${FUNCNAME}"
  191. fn_fetch_function
  192. }
  193. compress_ut99_maps.sh(){
  194. functionfile="${FUNCNAME}"
  195. fn_fetch_function
  196. }
  197. # Dev
  198. command_dev_debug.sh(){
  199. functionfile="${FUNCNAME}"
  200. fn_fetch_function
  201. }
  202. command_dev_detect_deps.sh(){
  203. functionfile="${FUNCNAME}"
  204. fn_fetch_function
  205. }
  206. # Fix
  207. fix.sh(){
  208. functionfile="${FUNCNAME}"
  209. fn_fetch_function
  210. }
  211. fix_arma3.sh(){
  212. functionfile="${FUNCNAME}"
  213. fn_fetch_function
  214. }
  215. fix_csgo.sh(){
  216. functionfile="${FUNCNAME}"
  217. fn_fetch_function
  218. }
  219. fix_dst.sh(){
  220. functionfile="${FUNCNAME}"
  221. fn_fetch_function
  222. }
  223. fix_ins.sh(){
  224. functionfile="${FUNCNAME}"
  225. fn_fetch_function
  226. }
  227. fix_steamcmd.sh(){
  228. functionfile="${FUNCNAME}"
  229. fn_fetch_function
  230. }
  231. fix_glibc.sh(){
  232. functionfile="${FUNCNAME}"
  233. fn_fetch_function
  234. }
  235. fix_ro.sh(){
  236. functionfile="${FUNCNAME}"
  237. fn_fetch_function
  238. }
  239. fix_kf.sh(){
  240. functionfile="${FUNCNAME}"
  241. fn_fetch_function
  242. }
  243. fix_ut2k4.sh(){
  244. functionfile="${FUNCNAME}"
  245. fn_fetch_function
  246. }
  247. # Info
  248. info_config.sh(){
  249. functionfile="${FUNCNAME}"
  250. fn_fetch_function
  251. }
  252. info_distro.sh(){
  253. functionfile="${FUNCNAME}"
  254. fn_fetch_function
  255. }
  256. info_glibc.sh(){
  257. functionfile="${FUNCNAME}"
  258. fn_fetch_function
  259. }
  260. info_parms.sh(){
  261. functionfile="${FUNCNAME}"
  262. fn_fetch_function
  263. }
  264. # Alert
  265. alert.sh(){
  266. functionfile="${FUNCNAME}"
  267. fn_fetch_function
  268. }
  269. alert_email.sh(){
  270. functionfile="${FUNCNAME}"
  271. fn_fetch_function
  272. }
  273. alert_pushbullet.sh(){
  274. functionfile="${FUNCNAME}"
  275. fn_fetch_function
  276. }
  277. # Logs
  278. logs.sh(){
  279. functionfile="${FUNCNAME}"
  280. fn_fetch_function
  281. }
  282. # Monitor
  283. monitor_gsquery.sh(){
  284. functionfile="${FUNCNAME}"
  285. fn_fetch_function
  286. }
  287. # Update
  288. command_update_functions.sh(){
  289. functionfile="${FUNCNAME}"
  290. fn_fetch_function
  291. }
  292. command_update.sh(){
  293. functionfile="${FUNCNAME}"
  294. fn_fetch_function
  295. }
  296. update_ts3.sh(){
  297. functionfile="${FUNCNAME}"
  298. fn_fetch_function
  299. }
  300. update_steamcmd.sh(){
  301. functionfile="${FUNCNAME}"
  302. fn_fetch_function
  303. }
  304. fn_update_functions.sh(){
  305. functionfile="${FUNCNAME}"
  306. fn_fetch_function
  307. }
  308. #
  309. ## Installer functions
  310. #
  311. fn_autoinstall(){
  312. autoinstall=1
  313. command_install.sh
  314. }
  315. install_complete.sh(){
  316. functionfile="${FUNCNAME}"
  317. fn_fetch_function
  318. }
  319. install_config.sh(){
  320. functionfile="${FUNCNAME}"
  321. fn_fetch_function
  322. }
  323. install_gsquery.sh(){
  324. functionfile="${FUNCNAME}"
  325. fn_fetch_function
  326. }
  327. install_gslt.sh(){
  328. functionfile="${FUNCNAME}"
  329. fn_fetch_function
  330. }
  331. install_header.sh(){
  332. functionfile="${FUNCNAME}"
  333. fn_fetch_function
  334. }
  335. install_logs.sh(){
  336. functionfile="${FUNCNAME}"
  337. fn_fetch_function
  338. }
  339. install_retry.sh(){
  340. functionfile="${FUNCNAME}"
  341. fn_fetch_function
  342. }
  343. install_server_dir.sh(){
  344. functionfile="${FUNCNAME}"
  345. fn_fetch_function
  346. }
  347. install_server_files.sh(){
  348. functionfile="${FUNCNAME}"
  349. fn_fetch_function
  350. }
  351. install_steamcmd.sh(){
  352. functionfile="${FUNCNAME}"
  353. fn_fetch_function
  354. }
  355. install_ts3.sh(){
  356. functionfile="${FUNCNAME}"
  357. fn_fetch_function
  358. }
  359. install_ts3db.sh(){
  360. functionfile="${FUNCNAME}"
  361. fn_fetch_function
  362. }
  363. install_ut2k4.sh(){
  364. functionfile="${FUNCNAME}"
  365. fn_fetch_function
  366. }
  367. install_dl_ut2k4.sh(){
  368. functionfile="${FUNCNAME}"
  369. fn_fetch_function
  370. }
  371. install_ut2k4_key.sh(){
  372. functionfile="${FUNCNAME}"
  373. fn_fetch_function
  374. }
  375. fix_ut99.sh(){
  376. functionfile="${FUNCNAME}"
  377. fn_fetch_function
  378. }
  379. # Calls the global Ctrl-C trap
  380. core_trap.sh
  381. # Calls on-screen messages
  382. core_messages.sh
  383. #Calls file downloader
  384. core_dl.sh