core_messages.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. #!/bin/bash
  2. # LinuxGSM core_messages.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: s-eam
  5. # Website: https://linuxgsm.com
  6. # Description: Defines on-screen messages such as [ OK ] and how script logs look.
  7. # nl: new line: message is following by a new line.
  8. # eol: end of line: message is placed at the end of the current line.
  9. fn_ansi_loader(){
  10. if [ "${ansi}" != "off" ]; then
  11. # echo colors
  12. default="\e[0m"
  13. black="\e[30m"
  14. red="\e[31m"
  15. lightred="\e[91m"
  16. green="\e[32m"
  17. lightgreen="\e[92m"
  18. yellow="\e[33m"
  19. lightyellow="\e[93m"
  20. blue="\e[34m"
  21. lightblue="\e[94m"
  22. magenta="\e[35m"
  23. lightmagenta="\e[95m"
  24. cyan="\e[36m"
  25. lightcyan="\e[96m"
  26. darkgrey="\e[90m"
  27. lightgrey="\e[37m"
  28. white="\e[97m"
  29. fi
  30. # carriage return & erase to end of line.
  31. creeol="\r\033[K"
  32. }
  33. fn_sleep_time(){
  34. if [ "${sleeptime}" != "0" ]||[ "${travistest}" != "1" ]; then
  35. if [ -z "${sleeptime}" ]; then
  36. sleeptime=0.5
  37. fi
  38. sleep "${sleeptime}"
  39. fi
  40. }
  41. # Log display
  42. ########################
  43. ## Feb 28 14:56:58 ut99-server: Monitor:
  44. fn_script_log(){
  45. if [ -d "${lgsmlogdir}" ]; then
  46. if [ -n "${commandname}" ]; then
  47. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ${commandname}: ${1}" >> "${lgsmlog}"
  48. else
  49. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ${1}" >> "${lgsmlog}"
  50. fi
  51. fi
  52. }
  53. ## Feb 28 14:56:58 ut99-server: Monitor: PASS:
  54. fn_script_log_pass(){
  55. if [ -d "${lgsmlogdir}" ]; then
  56. if [ -n "${commandname}" ]; then
  57. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ${commandname}: PASS: ${1}" >> "${lgsmlog}"
  58. else
  59. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: PASS: ${1}" >> "${lgsmlog}"
  60. fi
  61. fi
  62. exitcode=0
  63. }
  64. ## Feb 28 14:56:58 ut99-server: Monitor: FATAL:
  65. fn_script_log_fatal(){
  66. if [ -d "${lgsmlogdir}" ]; then
  67. if [ -n "${commandname}" ]; then
  68. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ${commandname}: FATAL: ${1}" >> "${lgsmlog}"
  69. else
  70. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: FATAL: ${1}" >> "${lgsmlog}"
  71. fi
  72. fi
  73. exitcode=1
  74. }
  75. ## Feb 28 14:56:58 ut99-server: Monitor: ERROR:
  76. fn_script_log_error(){
  77. if [ -d "${lgsmlogdir}" ]; then
  78. if [ -n "${commandname}" ]; then
  79. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ${commandname}: ERROR: ${1}" >> "${lgsmlog}"
  80. else
  81. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ERROR: ${1}" >> "${lgsmlog}"
  82. fi
  83. fi
  84. exitcode=2
  85. }
  86. ## Feb 28 14:56:58 ut99-server: Monitor: WARN:
  87. fn_script_log_warn(){
  88. if [ -d "${lgsmlogdir}" ]; then
  89. if [ -n "${commandname}" ]; then
  90. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ${commandname}: WARN: ${1}" >> "${lgsmlog}"
  91. else
  92. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: WARN: ${1}" >> "${lgsmlog}"
  93. fi
  94. fi
  95. exitcode=3
  96. }
  97. ## Feb 28 14:56:58 ut99-server: Monitor: INFO:
  98. fn_script_log_info(){
  99. if [ -d "${lgsmlogdir}" ]; then
  100. if [ -n "${commandname}" ]; then
  101. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: ${commandname}: INFO: ${1}" >> "${lgsmlog}"
  102. else
  103. echo -e "$(date '+%b %d %H:%M:%S.%3N') ${servicename}: INFO: ${1}" >> "${lgsmlog}"
  104. fi
  105. fi
  106. }
  107. # On-Screen - Automated functions
  108. ##################################
  109. # [ .... ]
  110. fn_print_dots(){
  111. if [ -n "${commandaction}" ]; then
  112. echo -en "${creeol}[ .... ] ${commandaction} ${servicename}: $@"
  113. else
  114. echo -en "${creeol}[ .... ] $@"
  115. fi
  116. fn_sleep_time
  117. }
  118. fn_print_dots_nl(){
  119. if [ -n "${commandaction}" ]; then
  120. echo -e "${creeol}[ .... ] ${commandaction} ${servicename}: $@"
  121. else
  122. echo -e "${creeol}[ .... ] $@"
  123. fi
  124. fn_sleep_time
  125. echo -en "\n"
  126. }
  127. # [ OK ]
  128. fn_print_ok(){
  129. if [ -n "${commandaction}" ]; then
  130. echo -en "${creeol}[${green} OK ${default}] ${commandaction} ${servicename}: $@"
  131. else
  132. echo -en "${creeol}[${green} OK ${default}] $@"
  133. fi
  134. fn_sleep_time
  135. }
  136. fn_print_ok_nl(){
  137. if [ -n "${commandaction}" ]; then
  138. echo -en "${creeol}[${green} OK ${default}] ${commandaction} ${servicename}: $@"
  139. else
  140. echo -en "${creeol}[${green} OK ${default}] $@"
  141. fi
  142. fn_sleep_time
  143. echo -en "\n"
  144. }
  145. # [ FAIL ]
  146. fn_print_fail(){
  147. if [ -n "${commandaction}" ]; then
  148. echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $@"
  149. else
  150. echo -en "${creeol}[${red} FAIL ${default}] $@"
  151. fi
  152. fn_sleep_time
  153. }
  154. fn_print_fail_nl(){
  155. if [ -n "${commandaction}" ]; then
  156. echo -en "${creeol}[${red} FAIL ${default}] ${commandaction} ${servicename}: $@"
  157. else
  158. echo -en "${creeol}[${red} FAIL ${default}] $@"
  159. fi
  160. fn_sleep_time
  161. echo -en "\n"
  162. }
  163. # [ ERROR ]
  164. fn_print_error(){
  165. if [ -n "${commandaction}" ]; then
  166. echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${servicename}: $@"
  167. else
  168. echo -en "${creeol}[${red}ERROR ${default}] $@"
  169. fi
  170. fn_sleep_time
  171. }
  172. fn_print_error_nl(){
  173. if [ -n "${commandaction}" ]; then
  174. echo -en "${creeol}[${red}ERROR ${default}] ${commandaction} ${servicename}: $@"
  175. else
  176. echo -en "${creeol}[${red}ERROR ${default}] $@"
  177. fi
  178. fn_sleep_time
  179. echo -en "\n"
  180. }
  181. # [ WARN ]
  182. fn_print_warn(){
  183. if [ -n "${commandaction}" ]; then
  184. echo -en "${creeol}[${lightyellow} WARN ${default}] ${commandaction} ${servicename}: $@"
  185. else
  186. echo -en "${creeol}[${lightyellow} WARN ${default}] $@"
  187. fi
  188. fn_sleep_time
  189. }
  190. fn_print_warn_nl(){
  191. if [ -n "${commandaction}" ]; then
  192. echo -en "${creeol}[${lightyellow} WARN ${default}] ${commandaction} ${servicename}: $@"
  193. else
  194. echo -en "${creeol}[${lightyellow} WARN ${default}] $@"
  195. fi
  196. fn_sleep_time
  197. echo -en "\n"
  198. }
  199. # [ INFO ]
  200. fn_print_info(){
  201. if [ -n "${commandaction}" ]; then
  202. echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $@"
  203. else
  204. echo -en "${creeol}[${cyan} INFO ${default}] $@"
  205. fi
  206. fn_sleep_time
  207. }
  208. fn_print_info_nl(){
  209. if [ -n "${commandaction}" ]; then
  210. echo -en "${creeol}[${cyan} INFO ${default}] ${commandaction} ${servicename}: $@"
  211. else
  212. echo -en "${creeol}[${cyan} INFO ${default}] $@"
  213. fi
  214. fn_sleep_time
  215. echo -en "\n"
  216. }
  217. # On-Screen - Interactive messages
  218. ##################################
  219. # No More Room in Hell Debug
  220. # =================================
  221. fn_print_header(){
  222. echo -e ""
  223. echo -e "${lightyellow}${gamename} ${commandaction}${default}"
  224. echo -e "=================================${default}"
  225. }
  226. # Complete!
  227. fn_print_complete(){
  228. echo -en "${green}Complete!${default} $@"
  229. fn_sleep_time
  230. }
  231. fn_print_complete_nl(){
  232. echo -e "${green}Complete!${default} $@"
  233. fn_sleep_time
  234. }
  235. # Failure!
  236. fn_print_failure(){
  237. echo -en "${red}Failure!${default} $@"
  238. fn_sleep_time
  239. }
  240. fn_print_failure_nl(){
  241. echo -e "${red}Failure!${default} $@"
  242. fn_sleep_time
  243. }
  244. # Error!
  245. fn_print_error2(){
  246. echo -en "${red}Error!${default} $@"
  247. fn_sleep_time
  248. }
  249. fn_print_error2_nl(){
  250. echo -e "${red}Error!${default} $@"
  251. fn_sleep_time
  252. }
  253. # Warning!
  254. fn_print_warning(){
  255. echo -en "${lightyellow}Warning!${default} $@"
  256. fn_sleep_time
  257. }
  258. fn_print_warning_nl(){
  259. echo -e "${lightyellow}Warning!${default} $@"
  260. fn_sleep_time
  261. }
  262. # Information!
  263. fn_print_information(){
  264. echo -en "${cyan}Information!${default} $@"
  265. fn_sleep_time
  266. }
  267. fn_print_information_nl(){
  268. echo -e "${cyan}Information!${default} $@"
  269. fn_sleep_time
  270. }
  271. # Y/N Prompt
  272. fn_prompt_yn(){
  273. local prompt="$1"
  274. local initial="$2"
  275. if [ "${initial}" == "Y" ]; then
  276. prompt+=" [Y/n] "
  277. elif [ "${initial}" == "N" ]; then
  278. prompt+=" [y/N] "
  279. else
  280. prompt+=" [y/n] "
  281. fi
  282. while true; do
  283. read -e -i "${initial}" -p "${prompt}" -r yn
  284. case "${yn}" in
  285. [Yy]|[Yy][Ee][Ss]) return 0 ;;
  286. [Nn]|[Nn][Oo]) return 1 ;;
  287. *) echo -e "Please answer yes or no." ;;
  288. esac
  289. done
  290. }
  291. # On-Screen End of Line
  292. ##################################
  293. # OK
  294. fn_print_ok_eol(){
  295. echo -en "${green}OK${default}"
  296. }
  297. fn_print_ok_eol_nl(){
  298. echo -e "${green}OK${default}"
  299. }
  300. # FAIL
  301. fn_print_fail_eol(){
  302. echo -en "${red}FAIL${default}"
  303. }
  304. fn_print_fail_eol_nl(){
  305. echo -e "${red}FAIL${default}"
  306. }
  307. # ERROR
  308. fn_print_error_eol(){
  309. echo -en "${red}ERROR${default}"
  310. }
  311. # WARN
  312. fn_print_warn_eol(){
  313. echo -en "${lightyellow}WARN${default}"
  314. }
  315. fn_print_warn_eol_nl(){
  316. echo -e "${lightyellow}WARN${default}"
  317. }
  318. # INFO
  319. fn_print_info_eol(){
  320. echo -en "${red}INFO${default}"
  321. }
  322. fn_print_info_eol_nl(){
  323. echo -e "${red}INFO${default}"
  324. }
  325. # QUERYING
  326. fn_print_querying_eol(){
  327. echo -en "${cyan}QUERYING${default}"
  328. }
  329. fn_print_querying_eol_nl(){
  330. echo -e "${cyan}QUERYING${default}"
  331. }
  332. # CHECKING
  333. fn_print_checking_eol(){
  334. echo -en "${cyan}CHECKING${default}"
  335. }
  336. fn_print_checking_eol_nl(){
  337. echo -e "${cyan}CHECKING${default}"
  338. }
  339. # DELAY
  340. fn_print_delay_eol(){
  341. echo -en "${green}DELAY${default}"
  342. }
  343. fn_print_delay_eol_nl(){
  344. echo -e "${green}DELAY${default}"
  345. }
  346. # CANCELED
  347. fn_print_canceled_eol(){
  348. echo -en "${yellow}CANCELED${default}"
  349. }
  350. fn_print_canceled_eol_nl(){
  351. echo -e "${yellow}CANCELED${default}"
  352. }
  353. # REMOVED
  354. fn_print_removed_eol(){
  355. echo -en "${red}REMOVED${default}"
  356. }
  357. fn_print_removed_eol_nl(){
  358. echo -e "${red}REMOVED${default}"
  359. }
  360. # UPDATE
  361. fn_print_update_eol(){
  362. echo -en "${cyan}UPDATE${default}"
  363. }
  364. fn_print_update_eol_nl(){
  365. echo -e "${cyan}UPDATE${default}"
  366. }
  367. fn_print_ascii_logo(){
  368. echo -e ""
  369. echo -e " mdMMMMbm"
  370. echo -e " mMMMMMMMMMMm"
  371. echo -e " mMMMMMMMMMMMMm"
  372. echo -e " mMMMMMMMMMMMMMMm"
  373. echo -e " hMMMV^VMMV^VMMMh"
  374. echo -e " MMMMM MM MMMMM"
  375. echo -e " hMMs vv sMMh"
  376. echo -e " hMMM: :MMMh"
  377. echo -e " .hMMMh hMMMh."
  378. echo -e " -dMMMh ${lightgrey}__${default} hMMMd-"
  379. echo -e " :mMMMs ${lightgrey}||${default} sMMMm:"
  380. echo -e " :MMMM+ ${lightgrey}||${default} ${red}_${default} +NMMN:"
  381. echo -e " .mMMM+ ${lightgrey}========${default} +MMMm."
  382. echo -e " yMMMy ${darkgrey}##############${default} yMMMy"
  383. echo -e " mMMM: ${darkgrey}##############${default} :MMMm"
  384. echo -e " mMM ${lightyellow}nn${default} ${lightyellow}nn${default} ${lightyellow}nn${default} ${lightyellow}nn${default} MMm"
  385. echo -e " o ${lightyellow}nNNNNNNNn${default} ${lightyellow}nNNNNNNNn${default} o"
  386. echo -e " ${lightyellow}nNNNNNNNNNn${default} ${lightyellow}nNNNNNNNNNn${default}"
  387. echo -e " ${lightyellow}nNNNNNNNNNNN${default} ${lightyellow}NNNNNNNNNNNn${default}"
  388. echo -e " ${lightyellow}+NNNNNNNNN:${default} ${lightyellow}:NNNNNNNNN+${default}"
  389. echo -e " ${lightyellow}nNNNNNNN${default} /\ ${lightyellow}NNNNNNNn${default}"
  390. echo -e " ${lightyellow}nnnnn${default} db ${lightyellow}nnnnn${default}"
  391. echo -e ""
  392. echo -e "${lightyellow}888${default} ${lightyellow}d8b${default} ${default}.d8888b. .d8888b. 888b d888"
  393. echo -e "${lightyellow}888 Y8P ${default}d88P Y88b d88P Y88b 8888b d8888"
  394. echo -e "${lightyellow}888${default} ${default}888${default} 888 Y88b. 88888b.d88888"
  395. echo -e "${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}88888b.${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} 888 Y888b. 888Y88888P888"
  396. echo -e "${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}88b${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}Y8bd8P${default} 888 88888 Y88b. 888 Y888P 888"
  397. echo -e "${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}X88K${default} 888 888 888 888 Y8P 888"
  398. echo -e "${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}Y88b${default} ${lightyellow}88Y${default} ${lightyellow}.d8pq8b.${default} Y88b d88P Y88b d88P 888 * 888"
  399. echo -e "${lightyellow}LinuxGSM${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}888${default} ${lightyellow}Y8888Y${default} ${lightyellow}888${default} ${lightyellow}888${default} Y2012P88 Y8888P 888 888"
  400. echo -e ""
  401. }