core_messages.sh 6.6 KB

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