| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- #!/bin/bash
- # LGSM core_messages.sh function
- # Author: Daniel Gibbs
- # Website: https://gameservermanagers.com
- # Description: Defines on-screen messages such as [ OK ] and how script logs look.
- # nl: new line: message is following by a new line
- # eol: end of line: message is placed at the end of the current line
- if [ "${ansi}" != "off" ]; then
- # echo colors
- default="\e[0m"
- red="\e[31m"
- green="\e[32m"
- yellow="\e[33m"
- lightyellow="\e[93m"
- blue="\e[34m"
- lightblue="\e[94m"
- magenta="\e[35m"
- cyan="\e[36m"
- # carriage return & erase to end of line
- creeol="\r\033[K"
- fi
- # Log display
- ########################
- ## Feb 28 14:56:58 ut99-server: Monitor:
- fn_script_log(){
- if [ -d "${scriptlogdir}" ]; then
- if [ -n "${commandname}" ]; then
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ${1}" >> "${scriptlog}"
- else
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
- fi
- fi
- }
- ## Feb 28 14:56:58 ut99-server: Monitor: PASS:
- fn_script_log_pass(){
- if [ -d "${scriptlogdir}" ]; then
- if [ -n "${commandname}" ]; then
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: PASS: ${1}" >> "${scriptlog}"
- else
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: PASS: ${1}" >> "${scriptlog}"
- fi
- fi
- exitcode=0
- }
- ## Feb 28 14:56:58 ut99-server: Monitor: FATAL:
- fn_script_log_fatal(){
- if [ -d "${scriptlogdir}" ]; then
- if [ -n "${commandname}" ]; then
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: FATAL: ${1}" >> "${scriptlog}"
- else
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: FATAL: ${1}" >> "${scriptlog}"
- fi
- fi
- exitcode=1
- }
- ## Feb 28 14:56:58 ut99-server: Monitor: ERROR:
- fn_script_log_error(){
- if [ -d "${scriptlogdir}" ]; then
- if [ -n "${commandname}" ]; then
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: ERROR: ${1}" >> "${scriptlog}"
- else
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ERROR: ${1}" >> "${scriptlog}"
- fi
- fi
- exitcode=2
- }
- ## Feb 28 14:56:58 ut99-server: Monitor: WARN:
- fn_script_log_warn(){
- if [ -d "${scriptlogdir}" ]; then
- if [ -n "${commandname}" ]; then
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: WARN: ${1}" >> "${scriptlog}"
- else
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: WARN: ${1}" >> "${scriptlog}"
- fi
- fi
- exitcode=3
- }
- ## Feb 28 14:56:58 ut99-server: Monitor: INFO:
- fn_script_log_info(){
- if [ -d "${scriptlogdir}" ]; then
- if [ -n "${commandname}" ]; then
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${commandname}: INFO: ${1}" >> "${scriptlog}"
- else
- echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: INFO: ${1}" >> "${scriptlog}"
- fi
- fi
- }
- # On-Screen - Automated functions
- ##################################
- # [ .... ]
- fn_print_dots(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[ .... ] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[ .... ] $@"
- fi
- }
- fn_print_dots_nl(){
- if [ -n "${commandaction}" ]; then
- echo -e "${creeol}[ .... ] ${commandaction} ${servicename}: $@"
- else
- echo -e "${creeol}[ .... ] $@"
- fi
- sleep 0.5
- echo -en "\n"
- }
- # [ OK ]
- fn_print_ok(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${green} OK ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${green} OK ${default}] $@"
- fi
- }
- fn_print_ok_nl(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${green} OK ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${green} OK ${default}] $@"
- fi
- sleep 0.5
- echo -en "\n"
- }
- # [ FAIL ]
- fn_print_fail(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${red} FAIL ${default}] $@"
- fi
- }
- fn_print_fail_nl(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${red} FAIL ${default}] $@"
- fi
- sleep 0.5
- echo -en "\n"
- }
- # [ ERROR ]
- fn_print_error(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${red}ERROR ${default}] $@"
- fi
- }
- fn_print_error_nl(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${red}ERROR!${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${red}ERROR!${default}] $@"
- fi
- sleep 0.5
- echo -en "\n"
- }
- # [ WARN ]
- fn_print_warn(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${yellow} WARN ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${yellow} WARN ${default}] $@"
- fi
- }
- fn_print_warn_nl(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${yellow} WARN ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${yellow} WARN ${default}] $@"
- fi
- sleep 0.5
- echo -en "\n"
- }
- # [ INFO ]
- fn_print_info(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${cyan} INFO ${default}] $@"
- fi
- }
- fn_print_info_nl(){
- if [ -n "${commandaction}" ]; then
- echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $@"
- else
- echo -en "${creeol}[${cyan} INFO ${default}] $@"
- fi
- sleep 0.5
- echo -en "\n"
- }
- # On-Screen - Interactive messages
- ##################################
- # No More Room in Hell Debug
- # =================================
- fn_print_header(){
- echo -e ""
- echo -e "${gamename} ${commandaction}"
- echo -e "=================================${default}"
- echo -e ""
- }
- # Complete!
- fn_print_complete(){
- echo -en "${green}Complete!${default} $@"
- }
- fn_print_complete_nl(){
- echo -e "${green}Complete!${default} $@"
- }
- # Failure!
- fn_print_failure(){
- echo -en "${red}Failure!${default} $@"
- }
- fn_print_failure_nl(){
- echo -e "${red}Failure!${default} $@"
- }
- # Error!
- fn_print_error2(){
- echo -en "${red}Error!${default} $@"
- }
- fn_print_error2_nl(){
- echo -e "${red}Error!${default} $@"
- }
- # Warning!
- fn_print_warning(){
- echo -en "${yellow}Warning!${default} $@"
- }
- fn_print_warning_nl(){
- echo -e "${yellow}Warning!${default} $@"
- }
- # Information!
- fn_print_information(){
- echo -en "${cyan}Information!${default} $@"
- }
- fn_print_information_nl(){
- echo -e "${cyan}Information!${default} $@"
- }
- # On-Screen End of Line
- ##################################
- # OK
- fn_print_ok_eol(){
- echo -en "${green}OK${default}"
- }
- fn_print_ok_eol_nl(){
- echo -e "${green}OK${default}"
- }
- # FAIL
- fn_print_fail_eol(){
- echo -en "${red}FAIL${default}"
- }
- fn_print_fail_eol_nl(){
- echo -e "${red}FAIL${default}"
- }
- # WARN
- fn_print_warn_eol(){
- echo -en "${red}FAIL${default}"
- }
- fn_print_warn_eol_nl(){
- echo -e "${red}FAIL${default}"
- }
- # INFO
- fn_print_info_eol(){
- echo -en "${red}FAIL${default}"
- }
- fn_print_info_eol_nl(){
- echo -e "${red}FAIL${default}"
- }
- # QUERYING
- fn_print_querying_eol(){
- echo -en "${cyan}QUERYING${default}"
- }
- fn_print_querying_eol_nl(){
- echo -e "${cyan}QUERYING${default}"
- }
- # CHECKING
- fn_print_checking_eol(){
- echo -en "${cyan}CHECKING${default}"
- }
- fn_print_checking_eol_nl(){
- echo -e "${cyan}CHECKING${default}"
- }
- # CANCELED
- fn_print_canceled_eol(){
- echo -en "${yellow}CANCELED${default}"
- }
- fn_print_canceled_eol_nl(){
- echo -e "${yellow}CANCELED${default}"
- }
- # REMOVED
- fn_print_removed_eol(){
- echo -en "${red}REMOVED${default}"
- }
- fn_print_removed_eol_nl(){
- echo -e "${red}REMOVED${default}"
- }
- # UPDATE
- fn_print_update_eol(){
- echo -en "${cyan}UPDATE${default}"
- }
- fn_print_update_eol_nl(){
- echo -e "${cyan}UPDATE${default}"
- }
|