core_getopt.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. #!/bin/bash
  2. # LGSM core_getopt.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: getopt arguments.
  6. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  7. fn_getopt_generic(){
  8. case "${getopt}" in
  9. st|start)
  10. command_start.sh;;
  11. sp|stop)
  12. command_stop.sh;;
  13. r|restart)
  14. command_restart.sh;;
  15. u|update)
  16. command_update.sh;;
  17. fu|force-update|update-restart)
  18. forceupdate=1;
  19. command_update.sh;;
  20. uf|update-functions)
  21. command_update_functions.sh;;
  22. v|validate)
  23. command_validate.sh;;
  24. m|monitor)
  25. command_monitor.sh;;
  26. ta|test-alert)
  27. command_test_alert.sh;;
  28. dt|details)
  29. command_details.sh;;
  30. b|backup)
  31. command_backup.sh;;
  32. c|console)
  33. command_console.sh;;
  34. d|debug)
  35. command_debug.sh;;
  36. dev|dev-debug)
  37. command_dev_debug.sh;;
  38. i|install)
  39. command_install.sh;;
  40. ai|auto-install)
  41. fn_autoinstall;;
  42. dd|depsdetect)
  43. command_dev_detect_deps.sh;;
  44. *)
  45. if [ -n "${getopt}" ]; then
  46. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  47. exitcode=2
  48. fi
  49. echo "Usage: $0 [option]"
  50. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  51. echo "https://gameservermanagers.com/${selfname}"
  52. echo -e ""
  53. echo -e "${lightyellow}Commands${default}"
  54. {
  55. echo -e "${blue}start\t${default}st |Start the server."
  56. echo -e "${blue}stop\t${default}sp |Stop the server."
  57. echo -e "${blue}restart\t${default}r |Restart the server."
  58. echo -e "${blue}update\t${default}u |Checks and applies updates from SteamCMD."
  59. echo -e "${blue}force-update\t${default}fu |Bypasses the check and applies updates from SteamCMD."
  60. echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
  61. echo -e "${blue}validate\t${default}v |Validate server files with SteamCMD."
  62. echo -e "${blue}monitor\t${default}m |Checks that the server is running."
  63. echo -e "${blue}test-alert\t${default}ta |Sends test alert."
  64. echo -e "${blue}details\t${default}dt |Displays useful infomation about the server."
  65. echo -e "${blue}backup\t${default}b |Create archive of the server."
  66. echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server."
  67. echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal."
  68. echo -e "${blue}install\t${default}i |Install the server."
  69. echo -e "${blue}auto-install\t${default}ai |Install the server, without prompts."
  70. } | column -s $'\t' -t
  71. esac
  72. }
  73. fn_getopt_teamspeak3(){
  74. case "${getopt}" in
  75. st|start)
  76. command_start.sh;;
  77. sp|stop)
  78. command_stop.sh;;
  79. r|restart)
  80. command_restart.sh;;
  81. u|update)
  82. command_update.sh;;
  83. uf|update-functions)
  84. command_update_functions.sh;;
  85. m|monitor)
  86. command_monitor.sh;;
  87. et|test-alert)
  88. command_test_alert.sh;;
  89. dt|details)
  90. command_details.sh;;
  91. b|backup)
  92. command_backup.sh;;
  93. pw|change-password)
  94. command_ts3_server_pass.sh;;
  95. dev|dev-debug)
  96. command_dev_debug.sh;;
  97. i|install)
  98. command_install.sh;;
  99. ai|auto-install)
  100. fn_autoinstall;;
  101. dd|depsdetect)
  102. command_dev_detect_deps.sh;;
  103. *)
  104. if [ -n "${getopt}" ]; then
  105. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  106. exitcode=2
  107. fi
  108. echo "Usage: $0 [option]"
  109. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  110. echo "https://gameservermanagers.com/${selfname}"
  111. echo -e ""
  112. echo -e "${lightyellow}Commands${default}"
  113. {
  114. echo -e "${blue}start\t${default}st |Start the server."
  115. echo -e "${blue}stop\t${default}sp |Stop the server."
  116. echo -e "${blue}restart\t${default}r |Restart the server."
  117. echo -e "${blue}update\t${default}u |Checks and applies updates from SteamCMD."
  118. echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
  119. echo -e "${blue}monitor\t${default}m |Checks that the server is running."
  120. echo -e "${blue}test-alert\t${default}ta |Sends test alert."
  121. echo -e "${blue}details\t${default}dt |Displays useful infomation about the server."
  122. echo -e "${blue}change-password\t${default}pw |Changes TS3 serveradmin password."
  123. echo -e "${blue}backup\t${default}b |Create archive of the server."
  124. echo -e "${blue}install\t${default}i |Install the server."
  125. echo -e "${blue}auto-install\t${default}ai |Install the server, without prompts."
  126. } | column -s $'\t' -t
  127. esac
  128. }
  129. fn_getopt_mumble(){
  130. case "${getopt}" in
  131. st|start)
  132. command_start.sh;;
  133. sp|stop)
  134. command_stop.sh;;
  135. r|restart)
  136. command_restart.sh;;
  137. u|update)
  138. command_update.sh;;
  139. uf|update-functions)
  140. command_update_functions.sh;;
  141. m|monitor)
  142. command_monitor.sh;;
  143. et|test-alert)
  144. command_test_alert.sh;;
  145. dt|details)
  146. command_details.sh;;
  147. b|backup)
  148. command_backup.sh;;
  149. pw|change-password)
  150. command_ts3_server_pass.sh;;
  151. dev|dev-debug)
  152. command_dev_debug.sh;;
  153. i|install)
  154. command_install.sh;;
  155. dd|depsdetect)
  156. command_dev_detect_deps.sh;;
  157. *)
  158. if [ -n "${getopt}" ]; then
  159. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  160. exitcode=2
  161. fi
  162. echo "Usage: $0 [option]"
  163. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  164. echo "https://gameservermanagers.com/${selfname}"
  165. echo -e ""
  166. echo -e "${lightyellow}Commands${default}"
  167. {
  168. echo -e "${blue}start\t${default}st |Start the server."
  169. echo -e "${blue}stop\t${default}sp |Stop the server."
  170. echo -e "${blue}restart\t${default}r |Restart the server."
  171. echo -e "${blue}update\t${default}u |Checks and applies updates from SteamCMD."
  172. echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
  173. echo -e "${blue}monitor\t${default}m |Checks that the server is running."
  174. echo -e "${blue}test-alert\t${default}ta |Sends test alert."
  175. echo -e "${blue}details\t${default}dt |Displays useful infomation about the server."
  176. echo -e "${blue}change-password\t${default}pw |Changes TS3 serveradmin password."
  177. echo -e "${blue}backup\t${default}b |Create archive of the server."
  178. echo -e "${blue}install\t${default}i |Install the server."
  179. } | column -s $'\t' -t
  180. esac
  181. }
  182. fn_getopt_gmodserver(){
  183. case "${getopt}" in
  184. st|start)
  185. command_start.sh;;
  186. sp|stop)
  187. command_stop.sh;;
  188. r|restart)
  189. command_restart.sh;;
  190. u|update)
  191. command_update.sh;;
  192. fu|force-update|update-restart)
  193. forceupdate=1;
  194. update_check.sh;;
  195. uf|update-functions)
  196. command_update_functions.sh;;
  197. v|validate)
  198. command_validate.sh;;
  199. m|monitor)
  200. command_monitor.sh;;
  201. et|test-alert)
  202. command_test_alert.sh;;
  203. dt|details)
  204. command_details.sh;;
  205. b|backup)
  206. command_backup.sh;;
  207. c|console)
  208. command_console.sh;;
  209. d|debug)
  210. command_debug.sh;;
  211. dev|dev-debug)
  212. command_dev_debug.sh;;
  213. i|install)
  214. command_install.sh;;
  215. ai|auto-install)
  216. fn_autoinstall;;
  217. dd|depsdetect)
  218. command_dev_detect_deps.sh;;
  219. fd|fastdl)
  220. command_fastdl.sh;;
  221. *)
  222. if [ -n "${getopt}" ]; then
  223. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  224. exitcode=2
  225. fi
  226. echo "Usage: $0 [option]"
  227. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  228. echo "https://gameservermanagers.com/${selfname}"
  229. echo -e ""
  230. echo -e "${lightyellow}Commands${default}"
  231. {
  232. echo -e "${blue}start\t${default}st |Start the server."
  233. echo -e "${blue}stop\t${default}sp |Stop the server."
  234. echo -e "${blue}restart\t${default}r |Restart the server."
  235. echo -e "${blue}update\t${default}Checks and applies updates from SteamCMD."
  236. echo -e "${blue}force-update\t${default}fu |Bypasses the check and applies updates from SteamCMD."
  237. echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
  238. echo -e "${blue}validate\t${default}v |Validate server files with SteamCMD."
  239. echo -e "${blue}monitor\t${default}m |Checks that the server is running."
  240. echo -e "${blue}test-alert\t${default}ta |Sends test alert."
  241. echo -e "${blue}details\t${default}dt |Displays useful infomation about the server."
  242. echo -e "${blue}backup\t${default}b |Create archive of the server."
  243. echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server."
  244. echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal."
  245. echo -e "${blue}install\t${default}i |Install the server."
  246. echo -e "${blue}auto-install\t${default}ai |Install the server, without prompts."
  247. echo -e "${blue}fastdl\t${default}fd |Generates or update a FastDL folder for your server."
  248. } | column -s $'\t' -t
  249. esac
  250. }
  251. fn_getopt_unreal(){
  252. case "${getopt}" in
  253. st|start)
  254. command_start.sh;;
  255. sp|stop)
  256. command_stop.sh;;
  257. r|restart)
  258. command_restart.sh;;
  259. uf|update-functions)
  260. command_update_functions.sh;;
  261. m|monitor)
  262. command_monitor.sh;;
  263. et|test-alert)
  264. command_test_alert.sh;;
  265. dt|details)
  266. command_details.sh;;
  267. b|backup)
  268. command_backup.sh;;
  269. c|console)
  270. command_console.sh;;
  271. d|debug)
  272. command_debug.sh;;
  273. dev|dev-debug)
  274. command_dev_debug.sh;;
  275. i|install)
  276. command_install.sh;;
  277. ai|auto-install)
  278. fn_autoinstall;;
  279. mc|map-compressor)
  280. compress_ut99_maps.sh;;
  281. dd|depsdetect)
  282. command_dev_detect_deps.sh;;
  283. *)
  284. if [ -n "${getopt}" ]; then
  285. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  286. exitcode=2
  287. fi
  288. echo "Usage: $0 [option]"
  289. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  290. echo "https://gameservermanagers.com/${selfname}"
  291. echo -e ""
  292. echo -e "${lightyellow}Commands${default}"
  293. {
  294. echo -e "${blue}start\t${default}st |Start the server."
  295. echo -e "${blue}stop\t${default}sp |Stop the server."
  296. echo -e "${blue}restart\t${default}r |Restart the server."
  297. echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
  298. echo -e "${blue}monitor\t${default}m |Checks that the server is running."
  299. echo -e "${blue}test-alert\t${default}ta |Sends test alert."
  300. echo -e "${blue}details\t${default}dt |Displays useful infomation about the server."
  301. echo -e "${blue}backup\t${default}b |Create archive of the server."
  302. echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server."
  303. echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal."
  304. echo -e "${blue}install\t${default}i |Install the server."
  305. echo -e "${blue}auto-install\t${default}ai |Install the server, without prompts."
  306. echo -e "${blue}map-compressor\t${default}mc |Compresses all ${gamename} server maps."
  307. } | column -s $'\t' -t
  308. esac
  309. }
  310. fn_getopt_unreal2(){
  311. case "${getopt}" in
  312. st|start)
  313. command_start.sh;;
  314. sp|stop)
  315. command_stop.sh;;
  316. r|restart)
  317. command_restart.sh;;
  318. u|update)
  319. command_update.sh;;
  320. fu|force-update|update-restart)
  321. forceupdate=1;
  322. update_check.sh;;
  323. uf|update-functions)
  324. command_update_functions.sh;;
  325. v|validate)
  326. command_validate.sh;;
  327. m|monitor)
  328. command_monitor.sh;;
  329. et|test-alert)
  330. command_test_alert.sh;;
  331. dt|details)
  332. command_details.sh;;
  333. b|backup)
  334. command_backup.sh;;
  335. c|console)
  336. command_console.sh;;
  337. d|debug)
  338. command_debug.sh;;
  339. dev|dev-debug)
  340. command_dev_debug.sh;;
  341. i|install)
  342. command_install.sh;;
  343. ai|auto-install)
  344. fn_autoinstall;;
  345. dd|depsdetect)
  346. command_dev_detect_deps.sh;;
  347. mc|map-compressor)
  348. compress_unreal2_maps.sh;;
  349. *)
  350. if [ -n "${getopt}" ]; then
  351. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  352. exitcode=2
  353. fi
  354. echo "Usage: $0 [option]"
  355. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  356. echo "https://gameservermanagers.com/${selfname}"
  357. echo -e ""
  358. echo -e "${lightyellow}Commands${default}"
  359. {
  360. echo -e "${blue}start\t${default}st |Start the server."
  361. echo -e "${blue}stop\t${default}sp |Stop the server."
  362. echo -e "${blue}restart\t${default}r |Restart the server."
  363. echo -e "${blue}update\t${default}Checks and applies updates from SteamCMD."
  364. echo -e "${blue}force-update\t${default}fu |Bypasses the check and applies updates from SteamCMD."
  365. echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
  366. echo -e "${blue}validate\t${default}v |Validate server files with SteamCMD."
  367. echo -e "${blue}monitor\t${default}m |Checks that the server is running."
  368. echo -e "${blue}test-alert\t${default}ta |Sends test alert."
  369. echo -e "${blue}details\t${default}dt |Displays useful infomation about the server."
  370. echo -e "${blue}backup\t${default}b |Create archive of the server."
  371. echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server."
  372. echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal."
  373. echo -e "${blue}install\t${default}i |Install the server."
  374. echo -e "${blue}auto-install\t${default}ai |Install the server, without prompts."
  375. echo -e "${blue}map-compressor\t${default}mc |Compresses all ${gamename} server maps."
  376. } | column -s $'\t' -t
  377. esac
  378. }
  379. fn_getopt_ut2k4(){
  380. case "${getopt}" in
  381. st|start)
  382. command_start.sh;;
  383. sp|stop)
  384. command_stop.sh;;
  385. r|restart)
  386. command_restart.sh;;
  387. uf|update-functions)
  388. command_update_functions.sh;;
  389. m|monitor)
  390. command_monitor.sh;;
  391. et|test-alert)
  392. command_test_alert.sh;;
  393. dt|details)
  394. command_details.sh;;
  395. b|backup)
  396. command_backup.sh;;
  397. c|console)
  398. command_console.sh;;
  399. d|debug)
  400. command_debug.sh;;
  401. dev|dev-debug)
  402. command_dev_debug.sh;;
  403. i|install)
  404. command_install.sh;;
  405. ai|auto-install)
  406. fn_autoinstall;;
  407. cd|server-cd-key)
  408. install_ut2k4_key.sh;;
  409. mc|map-compressor)
  410. compress_unreal2_maps.sh;;
  411. dd|depsdetect)
  412. command_dev_detect_deps.sh;;
  413. *)
  414. if [ -n "${getopt}" ]; then
  415. echo -e "${red}Unknown command${default}: $0 ${getopt}"
  416. exitcode=2
  417. fi
  418. echo "Usage: $0 [option]"
  419. echo "${gamename} - Linux Game Server Manager - Version ${version}"
  420. echo "https://gameservermanagers.com/${selfname}"
  421. echo -e ""
  422. echo -e "${lightyellow}Commands${default}"
  423. {
  424. echo -e "${blue}start\t${default}st |Start the server."
  425. echo -e "${blue}stop\t${default}sp |Stop the server."
  426. echo -e "${blue}restart\t${default}r |Restart the server."
  427. echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
  428. echo -e "${blue}monitor\t${default}m |Checks that the server is running."
  429. echo -e "${blue}test-alert\t${default}ta |Sends test alert."
  430. echo -e "${blue}details\t${default}dt |Displays useful infomation about the server."
  431. echo -e "${blue}backup\t${default}b |Create archive of the server."
  432. echo -e "${blue}console\t${default}c |Console allows you to access the live view of a server."
  433. echo -e "${blue}debug\t${default}d |See the output of the server directly to your terminal."
  434. echo -e "${blue}install\t${default}i |Install the server."
  435. echo -e "${blue}auto-install\t${default}ai |Install the server, without prompts."
  436. echo -e "${blue}server-cd-key\t${default}cd |Add your server cd key"
  437. echo -e "${blue}map-compressor\t${default}mc |Compresses all ${gamename} server maps."
  438. } | column -s $'\t' -t
  439. esac
  440. }
  441. if [ "${gamename}" == "Mumble" ]; then
  442. fn_getopt_mumble
  443. elif [ "${gamename}" == "Teamspeak 3" ]; then
  444. fn_getopt_teamspeak3
  445. elif [ "${gamename}" == "Garry's Mod" ]; then
  446. fn_getopt_gmodserver
  447. elif [ "${engine}" == "unreal2" ]; then
  448. if [ "${gamename}" == "Unreal Tournament 2004" ]; then
  449. fn_getopt_ut2k4
  450. else
  451. fn_getopt_unreal2
  452. fi
  453. elif [ "${engine}" == "unreal" ]; then
  454. fn_getopt_unreal
  455. else
  456. fn_getopt_generic
  457. fi
  458. core_exit.sh