core_messages.sh 6.8 KB

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