|
38 | 38 |
|
39 | 39 | umask 0022 |
40 | 40 |
|
41 | | -# Color echo |
42 | | -# usage: echo_color -b <backcolor> -t <textcolor> -d <decoration> [Text] |
43 | | -# |
44 | | -# Text Color |
45 | | -# 30 => Black |
46 | | -# 31 => Red |
47 | | -# 32 => Green |
48 | | -# 33 => Yellow |
49 | | -# 34 => Blue |
50 | | -# 35 => Magenta |
51 | | -# 36 => Cyan |
52 | | -# 37 => White |
53 | | -# |
54 | | -# Background color |
55 | | -# 40 => Black |
56 | | -# 41 => Red |
57 | | -# 42 => Green |
58 | | -# 43 => Yellow |
59 | | -# 44 => Blue |
60 | | -# 45 => Magenta |
61 | | -# 46 => Cyan |
62 | | -# 47 => White |
63 | | -# |
64 | | -# Text decoration |
65 | | -# You can specify multiple decorations with ;. |
66 | | -# 0 => All attributs off (ノーマル) |
67 | | -# 1 => Bold on (太字) |
68 | | -# 4 => Underscore (下線) |
69 | | -# 5 => Blink on (点滅) |
70 | | -# 7 => Reverse video on (色反転) |
71 | | -# 8 => Concealed on |
72 | | - |
73 | | -echo_color() { |
74 | | - local backcolor textcolor decotypes echo_opts arg OPTIND OPT |
75 | | - echo_opts="-e" |
76 | | - while getopts 'b:t:d:n' arg; do |
77 | | - case "${arg}" in |
78 | | - b) backcolor="${OPTARG}" ;; |
79 | | - t) textcolor="${OPTARG}" ;; |
80 | | - d) decotypes="${OPTARG}" ;; |
81 | | - n) echo_opts="-n -e" ;; |
82 | | - esac |
83 | | - done |
84 | | - shift "$((OPTIND - 1))" |
85 | | - if [[ "${nocolor}" = false ]]; then |
86 | | - echo ${echo_opts} "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${*}\e[m" |
87 | | - else |
88 | | - echo ${echo_opts} "${@}" |
89 | | - fi |
90 | | -} |
91 | | - |
92 | | - |
93 | 41 | # Show an INFO message |
94 | 42 | # $1: message string |
95 | 43 | msg_info() { |
96 | | - if [[ "${msgdebug}" = false ]]; then |
97 | | - set +xv |
98 | | - else |
99 | | - set -xv |
100 | | - fi |
101 | | - local echo_opts="-e" arg OPTIND OPT |
102 | | - while getopts 'n' arg; do |
103 | | - case "${arg}" in |
104 | | - n) echo_opts="${echo_opts} -n" ;; |
105 | | - esac |
106 | | - done |
107 | | - shift "$((OPTIND - 1))" |
108 | | - echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '32' 'Info') ${*}" |
109 | | - if [[ "${bash_debug}" = true ]]; then |
110 | | - set -xv |
111 | | - else |
112 | | - set +xv |
113 | | - fi |
| 44 | + local _msg_opts="-a build.sh" |
| 45 | + [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x" |
| 46 | + [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n" |
| 47 | + "${script_path}/tools/msg.sh" ${_msg_opts} info "${@}" |
114 | 48 | } |
115 | 49 |
|
116 | | - |
117 | 50 | # Show an Warning message |
118 | 51 | # $1: message string |
119 | 52 | msg_warn() { |
120 | | - if [[ "${msgdebug}" = false ]]; then |
121 | | - set +xv |
122 | | - else |
123 | | - set -xv |
124 | | - fi |
125 | | - local echo_opts="-e" arg OPTIND OPT |
126 | | - while getopts 'n' arg; do |
127 | | - case "${arg}" in |
128 | | - n) echo_opts="${echo_opts} -n" ;; |
129 | | - esac |
130 | | - done |
131 | | - shift "$((OPTIND - 1))" |
132 | | - echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '33' 'Warning') ${*}" >&2 |
133 | | - if [[ "${bash_debug}" = true ]]; then |
134 | | - set -xv |
135 | | - else |
136 | | - set +xv |
137 | | - fi |
| 53 | + local _msg_opts="-a build.sh" |
| 54 | + [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x" |
| 55 | + [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n" |
| 56 | + "${script_path}/tools/msg.sh" ${_msg_opts} warn "${@}" |
138 | 57 | } |
139 | 58 |
|
140 | | - |
141 | 59 | # Show an debug message |
142 | 60 | # $1: message string |
143 | 61 | msg_debug() { |
144 | | - if [[ "${msgdebug}" = false ]]; then |
145 | | - set +xv |
146 | | - else |
147 | | - set -xv |
148 | | - fi |
149 | | - local echo_opts="-e" arg OPTIND OPT |
150 | | - while getopts 'n' arg; do |
151 | | - case "${arg}" in |
152 | | - n) echo_opts="${echo_opts} -n" ;; |
153 | | - esac |
154 | | - done |
155 | | - shift "$((OPTIND - 1))" |
156 | | - if [[ ${debug} = true ]]; then |
157 | | - echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '35' 'Debug') ${*}" |
158 | | - fi |
159 | | - if [[ "${bash_debug}" = true ]]; then |
160 | | - set -xv |
161 | | - else |
162 | | - set +xv |
| 62 | + if [[ "${debug}" = true ]]; then |
| 63 | + local _msg_opts="-a build.sh" |
| 64 | + [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x" |
| 65 | + [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n" |
| 66 | + "${script_path}/tools/msg.sh" ${_msg_opts} info "${@}" |
163 | 67 | fi |
164 | 68 | } |
165 | 69 |
|
166 | | - |
167 | 70 | # Show an ERROR message then exit with status |
168 | 71 | # $1: message string |
169 | 72 | # $2: exit code number (with 0 does not exit) |
170 | 73 | msg_error() { |
171 | | - if [[ "${msgdebug}" = false ]]; then |
172 | | - set +xv |
173 | | - else |
174 | | - set -xv |
175 | | - fi |
176 | | - local echo_opts="-e" arg OPTIND OPT |
177 | | - while getopts 'n' arg; do |
178 | | - case "${arg}" in |
179 | | - n) echo_opts="${echo_opts} -n" ;; |
180 | | - esac |
181 | | - done |
182 | | - shift "$((OPTIND - 1))" |
183 | | - echo ${echo_opts} "$( echo_color -t '36' '[build.sh]') $( echo_color -t '31' 'Error') ${1}" >&2 |
| 74 | + local _msg_opts="-a build.sh" |
| 75 | + [[ "${msgdebug}" = true ]] && _msg_opts="${_msg_opts} -x" |
| 76 | + [[ "${nocolor}" = true ]] && _msg_opts="${_msg_opts} -n" |
| 77 | + "${script_path}/tools/msg.sh" ${_msg_opts} error "${1}" |
184 | 78 | if [[ -n "${2:-}" ]]; then |
185 | 79 | exit ${2} |
186 | 80 | fi |
187 | | - if [[ "${bash_debug}" = true ]]; then |
188 | | - set -xv |
189 | | - else |
190 | | - set +xv |
191 | | - fi |
192 | 81 | } |
193 | 82 |
|
194 | 83 |
|
|
0 commit comments