123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #
  2. # Variables to hold exit status semantic
  3. #
  4. TF_ES_OK=0
  5. TF_ES_FAIL=1
  6. TF_ES_BAILOUT=2
  7. TF_ES_ERROR=3
  8. TF_ES_PANIC=4
  9. #
  10. # Color definition variables
  11. #
  12. TF_COLOR_BLACK="\033[0;30m"
  13. TF_COLOR_RED="\033[0;31m"
  14. TF_COLOR_GREEN="\033[0;32m"
  15. TF_COLOR_YELLOW="\033[0;33m"
  16. TF_COLOR_BLUE="\033[0;34m"
  17. TF_COLOR_MAGENTA="\033[0;35m"
  18. TF_COLOR_CYAN="\033[0;36m"
  19. TF_COLOR_WHITE="\033[0;37m"
  20. TF_COLOR_LBLACK="\033[1;30m"
  21. TF_COLOR_LRED="\033[1;31m"
  22. TF_COLOR_LGREEN="\033[1;32m"
  23. TF_COLOR_LYELLOW="\033[1;33m"
  24. TF_COLOR_LBLUE="\033[1;34m"
  25. TF_COLOR_LMAGENTA="\033[1;35m"
  26. TF_COLOR_LCYAN="\033[1;36m"
  27. TF_COLOR_LWHITE="\033[1;37m"
  28. TF_COLOR_NONE="\033[1;0m"
  29. tf_exit_ok() {
  30. #
  31. # Exit with OK status
  32. #
  33. exit $TF_ES_OK
  34. }
  35. tf_exit_fail() {
  36. #
  37. # Warn $1 and exit with status FAIL
  38. #
  39. tf_warn "$@"
  40. exit $TF_ES_FAIL
  41. }
  42. tf_exit_bailout() {
  43. #
  44. # Warn $1 and exit with status FAIL
  45. #
  46. tf_warn "$@"
  47. exit $TF_ES_BAILOUT
  48. }
  49. tf_exit_error() {
  50. #
  51. # Warn $1 and exit with status FAIL
  52. #
  53. tf_warn "$@"
  54. exit $TF_ES_ERROR
  55. }
  56. tf_exit_panic() {
  57. #
  58. # Warn $1 and exit with status FAIL
  59. #
  60. tf_warn "$@"
  61. exit $TF_ES_PANIC
  62. }
  63. tf_debug() {
  64. #
  65. # Emit debug message
  66. #
  67. $TF_DEBUG || return 0
  68. local msg
  69. for msg in "$@";
  70. do
  71. $TF_COLOR && echo -ne "$TF_COLOR_CYAN" >&2
  72. echo "||| $msg" >&2;
  73. $TF_COLOR && echo -ne "$TF_COLOR_NONE" >&2
  74. done
  75. }
  76. tf_think() {
  77. #
  78. # Emit status/progress message
  79. #
  80. $TF_VERBOSE || return 0
  81. local msg
  82. for msg in "$@";
  83. do
  84. $TF_COLOR && echo -ne "$TF_COLOR_LBLACK" >&2
  85. echo "$pfx$msg$sfx" >&2;
  86. $TF_COLOR && echo -ne "$TF_COLOR_NONE" >&2
  87. done
  88. }
  89. tf_warn() {
  90. #
  91. # Emit warning
  92. #
  93. local msg
  94. for msg in "$@";
  95. do
  96. $TF_COLOR && echo -ne "$TF_COLOR_LRED" >&2
  97. echo "$msg" >&2;
  98. $TF_COLOR && echo -ne "$TF_COLOR_NONE" >&2
  99. done
  100. }