core_messages.sh 7.1 KB

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