core_messages.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #!/bin/bash
  2. # LGSM core_messages.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Defines on-screen messages such as [ OK ] and how script logs look.
  6. # nl: new line: message is following by a new line
  7. # eol: end of line: message is placed at the end of the current line
  8. if [ "${ansi}" != "off" ]; then
  9. # echo colors
  10. default="\e[0m"
  11. red="\e[31m"
  12. green="\e[32m"
  13. yellow="\e[33m"
  14. lightyellow="\e[93m"
  15. blue="\e[34m"
  16. lightblue="\e[94m"
  17. magenta="\e[35m"
  18. cyan="\e[36m"
  19. # carriage return & erase to end of line
  20. creeol="\r\033[K"
  21. fi
  22. # Log display
  23. ########################
  24. ## Feb 28 14:56:58 ut99-server: Monitor:
  25. fn_script_log(){
  26. if [ -d "${scriptlogdir}" ]; then
  27. if [ -n "${commandname}" ]; then
  28. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ${1}" >> "${scriptlog}"
  29. else
  30. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
  31. fi
  32. fi
  33. }
  34. ## Feb 28 14:56:58 ut99-server: Monitor: PASS:
  35. fn_script_log_pass(){
  36. if [ -d "${scriptlogdir}" ]; then
  37. if [ -n "${commandname}" ]; then
  38. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: PASS: ${1}" >> "${scriptlog}"
  39. else
  40. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: PASS: ${1}" >> "${scriptlog}"
  41. fi
  42. fi
  43. exitcode=0
  44. }
  45. ## Feb 28 14:56:58 ut99-server: Monitor: FATAL:
  46. fn_script_log_fatal(){
  47. if [ -d "${scriptlogdir}" ]; then
  48. if [ -n "${commandname}" ]; then
  49. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: FATAL: ${1}" >> "${scriptlog}"
  50. else
  51. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: FATAL: ${1}" >> "${scriptlog}"
  52. fi
  53. fi
  54. exitcode=1
  55. }
  56. ## Feb 28 14:56:58 ut99-server: Monitor: ERROR:
  57. fn_script_log_error(){
  58. if [ -d "${scriptlogdir}" ]; then
  59. if [ -n "${commandname}" ]; then
  60. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ERROR: ${1}" >> "${scriptlog}"
  61. else
  62. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ERROR: ${1}" >> "${scriptlog}"
  63. fi
  64. fi
  65. exitcode=2
  66. }
  67. ## Feb 28 14:56:58 ut99-server: Monitor: WARN:
  68. fn_script_log_warn(){
  69. if [ -d "${scriptlogdir}" ]; then
  70. if [ -n "${commandname}" ]; then
  71. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: WARN: ${1}" >> "${scriptlog}"
  72. else
  73. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: WARN: ${1}" >> "${scriptlog}"
  74. fi
  75. fi
  76. exitcode=3
  77. }
  78. ## Feb 28 14:56:58 ut99-server: Monitor: INFO:
  79. fn_script_log_info(){
  80. if [ -d "${scriptlogdir}" ]; then
  81. if [ -n "${commandname}" ]; then
  82. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: INFO: ${1}" >> "${scriptlog}"
  83. else
  84. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: INFO: ${1}" >> "${scriptlog}"
  85. fi
  86. fi
  87. }
  88. # On-Screen - Automated functions
  89. ##################################
  90. # [ .... ]
  91. fn_print_dots(){
  92. if [ -n "${commandaction}" ]; then
  93. echo -en "${creeol}[ .... ] ${commandaction} ${servicename}: $@"
  94. else
  95. echo -en "${creeol}[ .... ] $@"
  96. fi
  97. }
  98. fn_print_dots_nl(){
  99. if [ -n "${commandaction}" ]; then
  100. echo -e "${creeol}[ .... ] ${commandaction} ${servicename}: $@"
  101. else
  102. echo -e "${creeol}[ .... ] $@"
  103. fi
  104. sleep 0.5
  105. echo -en "\n"
  106. }
  107. # [ OK ]
  108. fn_print_ok(){
  109. if [ -n "${commandaction}" ]; then
  110. echo -en "${creeol}[${green} OK ${default}] ${commandaction} ${servicename}: $@"
  111. else
  112. echo -en "${creeol}[${green} OK ${default}] $@"
  113. fi
  114. }
  115. fn_print_ok_nl(){
  116. if [ -n "${commandaction}" ]; then
  117. echo -en "${creeol}[${green} OK ${default}] ${commandaction} ${servicename}: $@"
  118. else
  119. echo -en "${creeol}[${green} OK ${default}] $@"
  120. fi
  121. sleep 0.5
  122. echo -en "\n"
  123. }
  124. # [ FAIL ]
  125. fn_print_fail(){
  126. if [ -n "${commandaction}" ]; then
  127. echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $@"
  128. else
  129. echo -en "${creeol}[${red} FAIL ${default}] $@"
  130. fi
  131. }
  132. fn_print_fail_nl(){
  133. if [ -n "${commandaction}" ]; then
  134. echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $@"
  135. else
  136. echo -en "${creeol}[${red} FAIL ${default}] $@"
  137. fi
  138. sleep 0.5
  139. echo -en "\n"
  140. }
  141. # [ ERROR ]
  142. fn_print_error(){
  143. if [ -n "${commandaction}" ]; then
  144. echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${servicename}: $@"
  145. else
  146. echo -en "${creeol}[${red}ERROR ${default}] $@"
  147. fi
  148. }
  149. fn_print_error_nl(){
  150. if [ -n "${commandaction}" ]; then
  151. echo -en "${creeol}[${red}ERROR!${default}] ${commandaction} ${servicename}: $@"
  152. else
  153. echo -en "${creeol}[${red}ERROR!${default}] $@"
  154. fi
  155. sleep 0.5
  156. echo -en "\n"
  157. }
  158. # [ WARN ]
  159. fn_print_warn(){
  160. if [ -n "${commandaction}" ]; then
  161. echo -en "${creeol}[${yellow} WARN ${default}] ${commandaction} ${servicename}: $@"
  162. else
  163. echo -en "${creeol}[${yellow} WARN ${default}] $@"
  164. fi
  165. }
  166. fn_print_warn_nl(){
  167. if [ -n "${commandaction}" ]; then
  168. echo -en "${creeol}[${yellow} WARN ${default}] ${commandaction} ${servicename}: $@"
  169. else
  170. echo -en "${creeol}[${yellow} WARN ${default}] $@"
  171. fi
  172. sleep 0.5
  173. echo -en "\n"
  174. }
  175. # [ INFO ]
  176. fn_print_info(){
  177. if [ -n "${commandaction}" ]; then
  178. echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $@"
  179. else
  180. echo -en "${creeol}[${cyan} INFO ${default}] $@"
  181. fi
  182. }
  183. fn_print_info_nl(){
  184. if [ -n "${commandaction}" ]; then
  185. echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $@"
  186. else
  187. echo -en "${creeol}[${cyan} INFO ${default}] $@"
  188. fi
  189. sleep 0.5
  190. echo -en "\n"
  191. }
  192. # On-Screen - Interactive messages
  193. ##################################
  194. # No More Room in Hell Debug
  195. # =================================
  196. fn_print_header(){
  197. echo -e ""
  198. echo -e "${gamename} ${commandaction}"
  199. echo -e "=================================${default}"
  200. echo -e ""
  201. }
  202. # Complete!
  203. fn_print_complete(){
  204. echo -en "${green}Complete!${default} $@"
  205. }
  206. fn_print_complete_nl(){
  207. echo -e "${green}Complete!${default} $@"
  208. }
  209. # Failure!
  210. fn_print_failure(){
  211. echo -en "${red}Failure!${default} $@"
  212. }
  213. fn_print_failure_nl(){
  214. echo -e "${red}Failure!${default} $@"
  215. }
  216. # Error!
  217. fn_print_error2(){
  218. echo -en "${red}Error!${default} $@"
  219. }
  220. fn_print_error2_nl(){
  221. echo -e "${red}Error!${default} $@"
  222. }
  223. # Warning!
  224. fn_print_warning(){
  225. echo -en "${yellow}Warning!${default} $@"
  226. }
  227. fn_print_warning_nl(){
  228. echo -e "${yellow}Warning!${default} $@"
  229. }
  230. # Information!
  231. fn_print_information(){
  232. echo -en "${cyan}Information!${default} $@"
  233. }
  234. fn_print_information_nl(){
  235. echo -e "${cyan}Information!${default} $@"
  236. }
  237. # On-Screen End of Line
  238. ##################################
  239. # OK
  240. fn_print_ok_eol(){
  241. echo -en "${green}OK${default}"
  242. }
  243. fn_print_ok_eol_nl(){
  244. echo -e "${green}OK${default}"
  245. }
  246. # FAIL
  247. fn_print_fail_eol(){
  248. echo -en "${red}FAIL${default}"
  249. }
  250. fn_print_fail_eol_nl(){
  251. echo -e "${red}FAIL${default}"
  252. }
  253. # WARN
  254. fn_print_warn_eol(){
  255. echo -en "${red}FAIL${default}"
  256. }
  257. fn_print_warn_eol_nl(){
  258. echo -e "${red}FAIL${default}"
  259. }
  260. # INFO
  261. fn_print_info_eol(){
  262. echo -en "${red}FAIL${default}"
  263. }
  264. fn_print_info_eol_nl(){
  265. echo -e "${red}FAIL${default}"
  266. }
  267. # QUERYING
  268. fn_print_querying_eol(){
  269. echo -en "${cyan}QUERYING${default}"
  270. }
  271. fn_print_querying_eol_nl(){
  272. echo -e "${cyan}QUERYING${default}"
  273. }
  274. # CHECKING
  275. fn_print_checking_eol(){
  276. echo -en "${cyan}CHECKING${default}"
  277. }
  278. fn_print_checking_eol_nl(){
  279. echo -e "${cyan}CHECKING${default}"
  280. }
  281. # CANCELED
  282. fn_print_canceled_eol(){
  283. echo -en "${yellow}CANCELED${default}"
  284. }
  285. fn_print_canceled_eol_nl(){
  286. echo -e "${yellow}CANCELED${default}"
  287. }
  288. # REMOVED
  289. fn_print_removed_eol(){
  290. echo -en "${red}REMOVED${default}"
  291. }
  292. fn_print_removed_eol_nl(){
  293. echo -e "${red}REMOVED${default}"
  294. }
  295. # UPDATE
  296. fn_print_update_eol(){
  297. echo -en "${cyan}UPDATE${default}"
  298. }
  299. fn_print_update_eol_nl(){
  300. echo -e "${cyan}UPDATE${default}"
  301. }