GitHubのミラーです
https://github.com/FascodeNet/LFBS
修订版 | 590e140e0b0216fdb56ecb06b5a333eb4e82c558 (tree) |
---|---|
时间 | 2020-11-21 09:39:18 |
作者 | kokkiemouse <39451248+kokkiemouse@user...> |
Commiter | GitHub |
Merge pull request #6 from Hayao0819/master
多くの細かな修正とechocolorの廃止、locale.shの追加
@@ -60,47 +60,41 @@ _msg_common() { | ||
60 | 60 | _current_time="$(date +%s)" |
61 | 61 | _time="$(("${_current_time}"-"${start_time}"))" |
62 | 62 | |
63 | - if [[ "${_time}" -ge 3600 ]]; then | |
64 | - echo "[$(date -d @${_time} +%H:%M.%S)]$("${script_path}/echo_color" -t 6 "[LFBS Core]")" | |
65 | - elif [[ "${_time}" -ge 60 ]]; then | |
66 | - echo "[00:$(date -d @${_time} +%M.%S)]$("${script_path}/echo_color" -t 6 "[LFBS Core]")" | |
63 | + #if [[ "${_time}" -ge 3600 ]]; then | |
64 | + if (( "${_time}" >= 3600 )); then | |
65 | + echo -n "[$(date -d @${_time} +%H:%M.%S)] " | |
66 | + #elif [[ "${_time}" -ge 60 ]]; then | |
67 | + elif (( "${_time}" >= 60 )); then | |
68 | + echo -n "[00:$(date -d @${_time} +%M.%S)] " | |
67 | 69 | else |
68 | - echo "[00:00.$(date -d @${_time} +%S)] $("${script_path}/echo_color" -t 6 "[LFBS Core]")" | |
70 | + echo -n "[00:00.$(date -d @${_time} +%S)] " | |
69 | 71 | fi |
70 | - else | |
71 | - "${script_path}/echo_color" -t 6 "[LFBS Core]" | |
72 | 72 | fi |
73 | 73 | } |
74 | 74 | |
75 | 75 | # Show an INFO message |
76 | 76 | # _msg_info <message> |
77 | 77 | _msg_info() { |
78 | - local _msg | |
79 | - _msg="${@}" | |
80 | - echo "$(_msg_common) $("${script_path}/echo_color" -t 2 "Info:") ${_msg}" | |
78 | + _msg_common | |
79 | + "${script_path}/tools/msg.sh" -a "LFBS Core" -l "Info:" -s "6" info "${@}" | |
81 | 80 | } |
82 | 81 | |
83 | 82 | # Show an debug message |
84 | 83 | # _msg_debug <message> |
85 | 84 | _msg_debug() { |
85 | + _msg_common | |
86 | 86 | if [[ "${debug}" = true ]]; then |
87 | - local _msg | |
88 | - _msg="${@}" | |
89 | - echo "$(_msg_common) $("${script_path}/echo_color" -t 3 "Debug:") ${_msg}" | |
87 | + "${script_path}/tools/msg.sh" -a "LFBS Core" -l "Debug:" -s "6" debug "${@}" | |
90 | 88 | fi |
91 | 89 | } |
92 | 90 | |
93 | 91 | # Show an ERROR message then exit with status |
94 | 92 | # _msg_error <message> <exit code> |
95 | 93 | _msg_error() { |
96 | - local _msg | |
97 | - local _error | |
98 | - _msg="${1}" | |
99 | - _error=${2} | |
100 | - echo "$(_msg_common) $("${script_path}/echo_color" -t 1 "Error:") ${_msg}" | |
101 | - | |
102 | - if [[ ! ${_error} = 0 ]]; then | |
103 | - exit ${_error} | |
94 | + _msg_common | |
95 | + "${script_path}/tools/msg.sh" -a "LFBS Core" -l "Error:" -s "6" error "${@}" | |
96 | + if [[ -n "${2:-}" ]]; then | |
97 | + exit ${2} | |
104 | 98 | fi |
105 | 99 | } |
106 | 100 |
@@ -143,7 +137,6 @@ run_cmd() { | ||
143 | 137 | local mount |
144 | 138 | |
145 | 139 | for mount in "dev" "dev/pts" "proc" "sys" ; do |
146 | - #for mount in "dev" "dev/pts" "proc" "sys" ; do | |
147 | 140 | mount --bind /${mount} "${work_dir}/airootfs/${mount}" |
148 | 141 | done |
149 | 142 |
@@ -169,9 +162,8 @@ _dnf_install() { | ||
169 | 162 | # If the file does not exist, skip it. |
170 | 163 | # remove <file> <file> ... |
171 | 164 | remove() { |
172 | - local _list | |
165 | + local _list=($(echo "$@")) | |
173 | 166 | local _file |
174 | - _list=($(echo "$@")) | |
175 | 167 | |
176 | 168 | for _file in "${_list[@]}"; do |
177 | 169 | _msg_debug "Removeing ${_file}" |
@@ -184,6 +176,13 @@ remove() { | ||
184 | 176 | done |
185 | 177 | } |
186 | 178 | |
179 | +# Usage: echo_blank <number> | |
180 | +# 指定されたぶんの半角空白文字を出力します | |
181 | +echo_blank(){ | |
182 | + local _blank | |
183 | + for _local in $(seq 1 "${1}"); do echo -ne " "; done | |
184 | +} | |
185 | + | |
187 | 186 | # Show help |
188 | 187 | _usage () { |
189 | 188 | echo "usage ${0} [options] [channel]" |
@@ -197,56 +196,45 @@ _usage () { | ||
197 | 196 | echo " Default: ${locale_name}" |
198 | 197 | echo " -m | --mirror <url> Set apt mirror server." |
199 | 198 | echo " Default: ${mirror}" |
200 | - echo " -o | --out <out_dir> Set the output directory" | |
199 | + echo " -o | --out <dir> Set the output directory" | |
201 | 200 | echo " Default: ${out_dir}" |
202 | - echo " -w | --work <work_dir> Set the working directory" | |
201 | + echo " -w | --work <dir> Set the working directory" | |
203 | 202 | echo " Default: ${work_dir}" |
204 | - echo " -c | --cache <cache_dir> Set the cache directory" | |
203 | + echo " -c | --cache <dir> Set the cache directory" | |
205 | 204 | echo " Default: ${cache_dir}" |
206 | 205 | echo |
207 | - echo " -d | --debug " | |
206 | + echo " -d | --debug Enable debug messages" | |
207 | + echo " -x | --bash-debug Enable bash debug mode(set -xv)" | |
208 | 208 | echo " -h | --help This help message and exit" |
209 | 209 | echo |
210 | 210 | echo "You can switch between installed packages, files included in images, etc. by channel." |
211 | 211 | echo |
212 | + | |
213 | + local blank="23" _arch _list _dirname _channel | |
214 | + | |
212 | 215 | echo " Language for each architecture:" |
213 | 216 | for _list in ${script_path}/system/locale-* ; do |
214 | 217 | _arch="${_list#${script_path}/system/locale-}" |
215 | 218 | echo -n " ${_arch}" |
216 | - for i in $( seq 1 $(( ${blank} - 4 - ${#_arch} )) ); do | |
217 | - echo -ne " " | |
218 | - done | |
219 | - _locale_name_list=$(cat ${_list} | grep -h -v ^'#' | awk '{print $1}') | |
220 | - for _lang in ${_locale_name_list[@]};do | |
221 | - echo -n "${_lang} " | |
222 | - done | |
223 | - echo | |
219 | + echo_blank "$(( ${blank} - ${#_arch} ))" | |
220 | + "${script_path}/tools/locale.sh" -a "${_arch}" show | |
224 | 221 | done |
225 | - echo " Channel:" | |
226 | - | |
227 | - local _channel | |
228 | - local channel_list | |
229 | - local description | |
230 | 222 | |
223 | + echo -e "\n Channel:" | |
224 | + local _channel channel_list description | |
231 | 225 | for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do |
232 | 226 | if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then |
233 | 227 | channel_list+=( "${_channel}" ) |
234 | 228 | fi |
235 | 229 | done |
236 | - | |
237 | 230 | for _channel in ${channel_list[@]}; do |
238 | 231 | if [[ -f "${channels_dir}/${_channel}/description.txt" ]]; then |
239 | 232 | description=$(cat "${channels_dir}/${_channel}/description.txt") |
240 | 233 | else |
241 | 234 | description="This channel does not have a description.txt." |
242 | 235 | fi |
243 | - | |
244 | 236 | echo -ne " ${_channel}" |
245 | - | |
246 | - for i in $( seq 1 $(( 23 - ${#_channel} )) ); do | |
247 | - echo -ne " " | |
248 | - done | |
249 | - | |
237 | + echo_blank "$(( ${blank} - ${#_channel} ))" | |
250 | 238 | echo -ne "${description}\n" |
251 | 239 | done |
252 | 240 | } |
@@ -279,35 +267,7 @@ make_basefs() { | ||
279 | 267 | |
280 | 268 | # Parse files |
281 | 269 | parse_files() { |
282 | - #-- ロケールを解析、設定 --# | |
283 | - local _get_locale_line_number _locale_config_file _locale_name_list _locale_line_number _locale_config_line | |
284 | - | |
285 | - # 選択されたロケールの設定が描かれた行番号を取得 | |
286 | - _locale_config_file="${script_path}/system/locale-${arch}" | |
287 | - _locale_name_list=($(cat "${_locale_config_file}" | grep -h -v ^'#' | awk '{print $1}')) | |
288 | - _get_locale_line_number() { | |
289 | - local _lang _count=0 | |
290 | - for _lang in ${_locale_name_list[@]}; do | |
291 | - _count=$(( _count + 1 )) | |
292 | - if [[ "${_lang}" == "${locale_name}" ]]; then echo "${_count}"; return 0; fi | |
293 | - done | |
294 | - echo -n "failed" | |
295 | - } | |
296 | - _locale_line_number="$(_get_locale_line_number)" | |
297 | - | |
298 | - # 不正なロケール名なら終了する | |
299 | - [[ "${_locale_line_number}" == "failed" ]] && _msg_error "${locale_name} is not a valid language." "1" | |
300 | - | |
301 | - # ロケール設定ファイルから該当の行を抽出 | |
302 | - _locale_config_line=($(cat "${_locale_config_file}" | grep -h -v ^'#' | grep -v ^$ | head -n "${_locale_line_number}" | tail -n 1)) | |
303 | - | |
304 | - # 抽出された行に書かれた設定をそれぞれの変数に代入 | |
305 | - # ここで定義された変数のみがグローバル変数 | |
306 | - locale_name="${_locale_config_line[0]}" | |
307 | - locale_gen_name="${_locale_config_line[1]}" | |
308 | - locale_version="${_locale_config_line[2]}" | |
309 | - locale_time="${_locale_config_line[3]}" | |
310 | - locale_fullname="${_locale_config_line[4]}" | |
270 | + eval $(bash "${script_path}/tools/locale.sh" -s -a "${arch}" get "${locale_name}") | |
311 | 271 | } |
312 | 272 | |
313 | 273 | prepare_build() { |
@@ -392,7 +352,6 @@ make_config() { | ||
392 | 352 | # -t : Set plymouth theme. |
393 | 353 | # -u <username> : Set live user name. |
394 | 354 | # -x : Enable bash debug mode. |
395 | - # -r : Enable rebuild. | |
396 | 355 | # -z <locale_time> : Set the time zone. |
397 | 356 | # -l <locale_name> : Set language. |
398 | 357 | # |
@@ -536,11 +495,9 @@ make_checksum() { | ||
536 | 495 | umount_chroot_airootfs |
537 | 496 | } |
538 | 497 | |
539 | -# 引数解析() | |
540 | -# 参考記事:https://0e0.pw/ci83 https://0e0.pw/VJlg | |
541 | - | |
542 | -_opt_short="w:l:o:hba:-:m:c:d" | |
543 | -_opt_long="help,arch:,codename:,debug,help,lang,mirror:,out:,work,cache-only,bootsplash" | |
498 | +# 引数解析 参考記事:https://0e0.pw/ci83 https://0e0.pw/VJlg | |
499 | +_opt_short="w:l:o:hba:-:m:c:dx" | |
500 | +_opt_long="help,arch:,codename:,debug,help,lang,mirror:,out:,work,cache-only,bootsplash,bash-debug" | |
544 | 501 | OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}") |
545 | 502 | |
546 | 503 | if [[ ${?} != 0 ]]; then |
@@ -591,6 +548,10 @@ while :; do | ||
591 | 548 | cache_only=true |
592 | 549 | shift 1 |
593 | 550 | ;; |
551 | + -x | --bash-debug) | |
552 | + set -xv | |
553 | + shift 1 | |
554 | + ;; | |
594 | 555 | --) |
595 | 556 | shift |
596 | 557 | break |
@@ -601,11 +562,11 @@ while :; do | ||
601 | 562 | ;; |
602 | 563 | esac |
603 | 564 | done |
604 | -if [[ -f /etc/arch-release ]]; then | |
565 | +if [[ -f "/etc/arch-release" ]]; then | |
605 | 566 | grub2_standalone_cmd=grub-mkstandalone |
606 | 567 | fi |
607 | 568 | bootfiles_dir="${work_dir}/bootfiles" |
608 | -trap umount_chroot_airootfs 0 2 15 | |
569 | +trap 'umount_chroot_airootfs' 0 2 15 | |
609 | 570 | |
610 | 571 | if [[ -n "${1}" ]]; then |
611 | 572 | channel_name="${1}" |
@@ -1,34 +0,0 @@ | ||
1 | -#!/usr/bin/env bash | |
2 | -# SPDX-License-Identifier: GPL-3.0 | |
3 | -# | |
4 | -# mk-linux419 | |
5 | -# Twitter: @fascoder_4 | |
6 | -# Email : m.k419sabuaka@gmail.com | |
7 | -# | |
8 | -# (c) 2019-2020 Fascode Network. | |
9 | -# | |
10 | -# echo_color | |
11 | -# | |
12 | - | |
13 | -while getopts 't:b:d:' arg; do | |
14 | - case ${arg} in | |
15 | - t) textcolor="${OPTARG}" ;; | |
16 | - b) backcolor="${OPTARG}" ;; | |
17 | - d) deco="${OPTARG}" ;; | |
18 | - *) echo "Invalid argument '${OPTARG}'" ;; | |
19 | - esac | |
20 | -done | |
21 | - | |
22 | -shift $((OPTIND - 1)) | |
23 | - | |
24 | -if [[ -n "${deco}" ]]; then | |
25 | - case ${deco} in | |
26 | - 0) decotypes="sgr 0" ;; | |
27 | - 1) decotypes="bold" ;; | |
28 | - 4) decotypes="smul" ;; | |
29 | - 5) decotypes="blink" ;; | |
30 | - *) echo "Invalid argument '${deco}'" ;; | |
31 | - esac | |
32 | -fi | |
33 | - | |
34 | -echo "$([[ -n "${textcolor}" ]] && tput setaf "${textcolor}")$([[ -n "${backcolor}" ]] && tput setab "${backcolor}")$([[ -n "${decotypes}" ]] && tput "${decotypes}")${*}$(tput sgr0)" | |
\ No newline at end of file |
@@ -0,0 +1,169 @@ | ||
1 | +#!/usr/bin/env bash | |
2 | + | |
3 | +set -e | |
4 | + | |
5 | +script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )" | |
6 | +mode="" | |
7 | +arch="" | |
8 | +channel="" | |
9 | +locale="" | |
10 | +script=false | |
11 | + | |
12 | +_help() { | |
13 | + echo "usage ${0} [options] [command]" | |
14 | + echo | |
15 | + echo "Scripts that perform locale-related processing " | |
16 | + echo | |
17 | + echo " General command:" | |
18 | + echo " check [name] Determine if the locale is available" | |
19 | + echo " show Shows a list of available locales" | |
20 | + echo " get [name] Prints the specified locale settings" | |
21 | + echo " help This help message" | |
22 | + echo | |
23 | + echo " General options:" | |
24 | + echo " -a | --arch [arch] Specify the architecture" | |
25 | + echo " -c | --channel Specify the channel" | |
26 | + echo " -h | --help This help message" | |
27 | +} | |
28 | + | |
29 | +# Usage: getclm <number> | |
30 | +# 標準入力から値を受けとり、引数で指定された列を抽出します。 | |
31 | +getclm() { | |
32 | + echo "$(cat -)" | cut -d " " -f "${1}" | |
33 | +} | |
34 | + | |
35 | +# Message functions | |
36 | +msg_error() { | |
37 | + "${script_path}/tools/msg.sh" -s 6 -a "locale.sh" error "${1}" | |
38 | +} | |
39 | + | |
40 | +gen_locale_list() { | |
41 | + if [[ -z "${arch}" ]]; then | |
42 | + msg_error "No architecture specified." | |
43 | + exit 1 | |
44 | + fi | |
45 | + local _locale | |
46 | + for _locale in $(grep -h -v ^'#' "${script_path}/system/locale-${arch}" | getclm 1); do | |
47 | + localelist+=("${_locale}") | |
48 | + done | |
49 | +} | |
50 | + | |
51 | +check() { | |
52 | + gen_locale_list | |
53 | + if [[ ! "${#}" = "1" ]]; then | |
54 | + _help | |
55 | + exit 1 | |
56 | + fi | |
57 | + if [[ $(printf '%s\n' "${localelist[@]}" | grep -qx "${1}"; echo -n ${?} ) -eq 0 ]]; then | |
58 | + echo "correct" | |
59 | + exit 0 | |
60 | + else | |
61 | + echo "incorrect" | |
62 | + exit 1 | |
63 | + fi | |
64 | +} | |
65 | + | |
66 | +show() { | |
67 | + gen_locale_list | |
68 | + if (( "${#localelist[*]}" > 0)); then | |
69 | + echo "${localelist[*]}" | |
70 | + fi | |
71 | +} | |
72 | + | |
73 | +get() { | |
74 | + gen_locale_list | |
75 | + if [[ ! "${#}" = "1" ]]; then | |
76 | + _help | |
77 | + exit 1 | |
78 | + fi | |
79 | + | |
80 | + #-- ロケールを解析、設定 --# | |
81 | + local _get_locale_line_number _locale_config_file _locale_name_list _locale_line_number _locale_config_line | |
82 | + | |
83 | + # 選択されたロケールの設定が描かれた行番号を取得 | |
84 | + _locale_config_file="${script_path}/system/locale-${arch}" | |
85 | + _locale_name_list=($(cat "${_locale_config_file}" | grep -h -v ^'#' | awk '{print $1}')) | |
86 | + _get_locale_line_number() { | |
87 | + local _lang _count=0 | |
88 | + for _lang in ${_locale_name_list[@]}; do | |
89 | + _count=$(( _count + 1 )) | |
90 | + if [[ "${_lang}" = "${1}" ]]; then echo "${_count}"; return 0; fi | |
91 | + done | |
92 | + echo -n "failed" | |
93 | + } | |
94 | + _locale_line_number="$(_get_locale_line_number ${@})" | |
95 | + | |
96 | + # 不正なロケール名なら終了する | |
97 | + if [[ "${_locale_line_number}" = "failed" ]]; then | |
98 | + msg_error "${1} is not a valid language." | |
99 | + if [[ "${script}" = true ]]; then | |
100 | + echo "exit 1" | |
101 | + fi | |
102 | + exit 1 | |
103 | + fi | |
104 | + | |
105 | + # ロケール設定ファイルから該当の行を抽出 | |
106 | + _locale_config_line=($(cat "${_locale_config_file}" | grep -h -v ^'#' | grep -v ^$ | head -n "${_locale_line_number}" | tail -n 1)) | |
107 | + | |
108 | + # 抽出された行に書かれた設定をそれぞれの変数に代入 | |
109 | + # ここで定義された変数のみがグローバル変数 | |
110 | + cat << EOF | |
111 | +locale_name="${_locale_config_line[0]}" | |
112 | +locale_gen_name="${_locale_config_line[1]}" | |
113 | +locale_version="${_locale_config_line[2]}" | |
114 | +locale_time="${_locale_config_line[3]}" | |
115 | +locale_fullname="${_locale_config_line[4]}" | |
116 | +EOF | |
117 | +} | |
118 | + | |
119 | +# Parse options | |
120 | +ARGUMENT="${@}" | |
121 | +_opt_short="a:c:hs" | |
122 | +_opt_long="arch:,channel:,help,script" | |
123 | +OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT}) | |
124 | +[[ ${?} != 0 ]] && exit 1 | |
125 | + | |
126 | +eval set -- "${OPT}" | |
127 | +unset OPT _opt_short _opt_long | |
128 | + | |
129 | +while true; do | |
130 | + case ${1} in | |
131 | + -a | --arch) | |
132 | + arch="${2}" | |
133 | + shift 2 | |
134 | + ;; | |
135 | + -c | --channel) | |
136 | + channel="${2}" | |
137 | + shift 2 | |
138 | + ;; | |
139 | + -s | --script) | |
140 | + script=true | |
141 | + shift 1 | |
142 | + ;; | |
143 | + -h | --help) | |
144 | + _help | |
145 | + exit 0 | |
146 | + ;; | |
147 | + --) | |
148 | + shift 1 | |
149 | + break | |
150 | + ;; | |
151 | + | |
152 | + esac | |
153 | +done | |
154 | + | |
155 | +if [[ -z "${1}" ]]; then | |
156 | + _help | |
157 | + exit 1 | |
158 | +else | |
159 | + mode="${1}" | |
160 | + shift 1 | |
161 | +fi | |
162 | + | |
163 | +case "${mode}" in | |
164 | + "check" ) check ${@} ;; | |
165 | + "show" ) show ;; | |
166 | + "get" ) get ${@} ;; | |
167 | + "help" ) _help; exit 0 ;; | |
168 | + * ) _help; exit 1 ;; | |
169 | +esac |