• R/O
  • HTTP
  • SSH
  • HTTPS

LFBS: 提交

GitHubのミラーです
https://github.com/FascodeNet/LFBS


Commit MetaInfo

修订版590e140e0b0216fdb56ecb06b5a333eb4e82c558 (tree)
时间2020-11-21 09:39:18
作者kokkiemouse <39451248+kokkiemouse@user...>
CommiterGitHub

Log Message

Merge pull request #6 from Hayao0819/master

多くの細かな修正とechocolorの廃止、locale.shの追加

更改概述

差异

--- a/build.sh
+++ b/build.sh
@@ -60,47 +60,41 @@ _msg_common() {
6060 _current_time="$(date +%s)"
6161 _time="$(("${_current_time}"-"${start_time}"))"
6262
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)] "
6769 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)] "
6971 fi
70- else
71- "${script_path}/echo_color" -t 6 "[LFBS Core]"
7272 fi
7373 }
7474
7575 # Show an INFO message
7676 # _msg_info <message>
7777 _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 "${@}"
8180 }
8281
8382 # Show an debug message
8483 # _msg_debug <message>
8584 _msg_debug() {
85+ _msg_common
8686 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 "${@}"
9088 fi
9189 }
9290
9391 # Show an ERROR message then exit with status
9492 # _msg_error <message> <exit code>
9593 _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}
10498 fi
10599 }
106100
@@ -143,7 +137,6 @@ run_cmd() {
143137 local mount
144138
145139 for mount in "dev" "dev/pts" "proc" "sys" ; do
146- #for mount in "dev" "dev/pts" "proc" "sys" ; do
147140 mount --bind /${mount} "${work_dir}/airootfs/${mount}"
148141 done
149142
@@ -169,9 +162,8 @@ _dnf_install() {
169162 # If the file does not exist, skip it.
170163 # remove <file> <file> ...
171164 remove() {
172- local _list
165+ local _list=($(echo "$@"))
173166 local _file
174- _list=($(echo "$@"))
175167
176168 for _file in "${_list[@]}"; do
177169 _msg_debug "Removeing ${_file}"
@@ -184,6 +176,13 @@ remove() {
184176 done
185177 }
186178
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+
187186 # Show help
188187 _usage () {
189188 echo "usage ${0} [options] [channel]"
@@ -197,56 +196,45 @@ _usage () {
197196 echo " Default: ${locale_name}"
198197 echo " -m | --mirror <url> Set apt mirror server."
199198 echo " Default: ${mirror}"
200- echo " -o | --out <out_dir> Set the output directory"
199+ echo " -o | --out <dir> Set the output directory"
201200 echo " Default: ${out_dir}"
202- echo " -w | --work <work_dir> Set the working directory"
201+ echo " -w | --work <dir> Set the working directory"
203202 echo " Default: ${work_dir}"
204- echo " -c | --cache <cache_dir> Set the cache directory"
203+ echo " -c | --cache <dir> Set the cache directory"
205204 echo " Default: ${cache_dir}"
206205 echo
207- echo " -d | --debug "
206+ echo " -d | --debug Enable debug messages"
207+ echo " -x | --bash-debug Enable bash debug mode(set -xv)"
208208 echo " -h | --help This help message and exit"
209209 echo
210210 echo "You can switch between installed packages, files included in images, etc. by channel."
211211 echo
212+
213+ local blank="23" _arch _list _dirname _channel
214+
212215 echo " Language for each architecture:"
213216 for _list in ${script_path}/system/locale-* ; do
214217 _arch="${_list#${script_path}/system/locale-}"
215218 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
224221 done
225- echo " Channel:"
226-
227- local _channel
228- local channel_list
229- local description
230222
223+ echo -e "\n Channel:"
224+ local _channel channel_list description
231225 for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
232226 if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
233227 channel_list+=( "${_channel}" )
234228 fi
235229 done
236-
237230 for _channel in ${channel_list[@]}; do
238231 if [[ -f "${channels_dir}/${_channel}/description.txt" ]]; then
239232 description=$(cat "${channels_dir}/${_channel}/description.txt")
240233 else
241234 description="This channel does not have a description.txt."
242235 fi
243-
244236 echo -ne " ${_channel}"
245-
246- for i in $( seq 1 $(( 23 - ${#_channel} )) ); do
247- echo -ne " "
248- done
249-
237+ echo_blank "$(( ${blank} - ${#_channel} ))"
250238 echo -ne "${description}\n"
251239 done
252240 }
@@ -279,35 +267,7 @@ make_basefs() {
279267
280268 # Parse files
281269 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}")
311271 }
312272
313273 prepare_build() {
@@ -392,7 +352,6 @@ make_config() {
392352 # -t : Set plymouth theme.
393353 # -u <username> : Set live user name.
394354 # -x : Enable bash debug mode.
395- # -r : Enable rebuild.
396355 # -z <locale_time> : Set the time zone.
397356 # -l <locale_name> : Set language.
398357 #
@@ -536,11 +495,9 @@ make_checksum() {
536495 umount_chroot_airootfs
537496 }
538497
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"
544501 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
545502
546503 if [[ ${?} != 0 ]]; then
@@ -591,6 +548,10 @@ while :; do
591548 cache_only=true
592549 shift 1
593550 ;;
551+ -x | --bash-debug)
552+ set -xv
553+ shift 1
554+ ;;
594555 --)
595556 shift
596557 break
@@ -601,11 +562,11 @@ while :; do
601562 ;;
602563 esac
603564 done
604-if [[ -f /etc/arch-release ]]; then
565+if [[ -f "/etc/arch-release" ]]; then
605566 grub2_standalone_cmd=grub-mkstandalone
606567 fi
607568 bootfiles_dir="${work_dir}/bootfiles"
608-trap umount_chroot_airootfs 0 2 15
569+trap 'umount_chroot_airootfs' 0 2 15
609570
610571 if [[ -n "${1}" ]]; then
611572 channel_name="${1}"
--- a/echo_color
+++ /dev/null
@@ -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
--- /dev/null
+++ b/tools/locale.sh
@@ -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
Show on old repository browser