Skip to content

Commit af9183f

Browse files
committed
[update] : Moved message display processing to msg.sh
1 parent c01b2da commit af9183f

File tree

3 files changed

+196
-256
lines changed

3 files changed

+196
-256
lines changed

allarch.sh

Lines changed: 17 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -38,157 +38,46 @@ fi
3838

3939
umask 0022
4040

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-
9341
# Show an INFO message
9442
# $1: message string
9543
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' '[allarch.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 "${@}"
11448
}
11549

116-
11750
# Show an Warning message
11851
# $1: message string
11952
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' '[allarch.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 "${@}"
13857
}
13958

140-
14159
# Show an debug message
14260
# $1: message string
14361
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' '[allarch.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 "${@}"
16367
fi
16468
}
16569

166-
16770
# Show an ERROR message then exit with status
16871
# $1: message string
16972
# $2: exit code number (with 0 does not exit)
17073
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' '[allarch.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}"
18478
if [[ -n "${2:-}" ]]; then
18579
exit ${2}
18680
fi
187-
if [[ "${bash_debug}" = true ]]; then
188-
set -xv
189-
else
190-
set +xv
191-
fi
19281
}
19382

19483

build.sh

Lines changed: 17 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -38,157 +38,46 @@ fi
3838

3939
umask 0022
4040

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-
9341
# Show an INFO message
9442
# $1: message string
9543
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 "${@}"
11448
}
11549

116-
11750
# Show an Warning message
11851
# $1: message string
11952
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 "${@}"
13857
}
13958

140-
14159
# Show an debug message
14260
# $1: message string
14361
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 "${@}"
16367
fi
16468
}
16569

166-
16770
# Show an ERROR message then exit with status
16871
# $1: message string
16972
# $2: exit code number (with 0 does not exit)
17073
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}"
18478
if [[ -n "${2:-}" ]]; then
18579
exit ${2}
18680
fi
187-
if [[ "${bash_debug}" = true ]]; then
188-
set -xv
189-
else
190-
set +xv
191-
fi
19281
}
19382

19483

0 commit comments

Comments
 (0)