Skip to content

Commit 33b8c41

Browse files
committed
[add] : Load modules and presets
1 parent fd2ac7c commit 33b8c41

4 files changed

Lines changed: 68 additions & 2 deletions

File tree

build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -e -E -u -o pipefail
66
script_path="$(cd "$(dirname "$0")" || exit 1; pwd)"
77
template_dir="$script_path/profile_template"
88
channel_dir=""
9+
modules_dir="${script_path}/modules"
910

1011
#-- Load lib --#
1112
# shellcheck source=./lib/parsearg.sh
@@ -16,6 +17,10 @@ source "${script_path}/lib/common.sh"
1617
source "${script_path}/lib/msg.sh"
1718
# shellcheck source=./lib/make_prepare.sh
1819
source "${script_path}/lib/make_prepare.sh"
20+
# shellcheck source=./lib/make_channel.sh
21+
source "${script_path}/lib/make_channel.sh"
22+
# shellcheck source=./lib/make_prepare_modules.sh
23+
source "$script_path/lib/make_prepare_modules.sh"
1924
# shellcheck source=./lib/make_profiledef.sh
2025
source "${script_path}/lib/make_profiledef.sh"
2126
# shellcheck source=./lib/template_parser.sh
@@ -55,6 +60,8 @@ fi
5560

5661
#-- Run functions --#
5762
call_func make_prepare
63+
call_func make_channel
64+
call_func make_prepare_modules
5865
call_func make_default
5966
call_func make_parsed_vars
6067
call_func make_profiledef

lib/make_channel.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
load_config() {
4+
local _file
5+
for _file in "${@}"; do
6+
[[ -e "${_file}" ]] && source "${_file}"
7+
msg_debug "The settings have been overwritten by the ${_file}"
8+
done
9+
return 0
10+
}
11+
12+
make_channel(){
13+
# Load channel config
14+
load_config "${channel_dir}/config.any" "${channel_dir}/config.${arch}"
15+
16+
}

lib/make_prepare.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ make_prepare(){
77
work_dir="$(realpath "$work_dir")"
88
mkdir -p "$work_dir/profile"
99

10-
# build tool
10+
# build template parser
1111
template_parser="${work_dir}/template_parser"
1212
build_template_parser
1313

14+
# build list parser
1415
list_parser="${work_dir}/list_parser"
1516
build_list_parser
1617
}
@@ -19,7 +20,6 @@ make_default(){
1920
if [[ -z "${kernel-""}" ]]; then
2021
kernel="$defaultkernel"
2122
fi
22-
2323
}
2424

2525
make_parsed_vars(){

lib/make_prepare_modules.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
make_prepare_modules(){
4+
# Add additional modules
5+
modules+=("${additional_modules[@]}")
6+
7+
readarray -t modules < <(parser_preset "${modules[@]}")
8+
msg_debug "Loaded modules: ${modules[*]}"
9+
}
10+
11+
# Execute command for each module. It will be executed with {} replaced with the module name.
12+
# for_module <command>
13+
for_module(){
14+
local module
15+
for module in "${modules[@]}"; do
16+
eval "${@//"{}"/${module}}"
17+
done
18+
}
19+
20+
21+
#parse_preset(){
22+
# # Load presets
23+
# local _modules=() module_check
24+
# for_module '[[ -f "${preset_dir}/{}" ]] && readarray -t -O "${#_modules[@]}" _modules < <(grep -h -v ^'#' "${preset_dir}/{}") || _modules+=("{}")'
25+
# modules=("${_modules[@]}")
26+
# unset _modules
27+
#}
28+
29+
# parse_preset <modules>
30+
# 引数にモジュールとプリセットがごっちゃになってる配列を展開して渡すと、モジュールだけを返してくれます
31+
parser_preset(){
32+
local _p _modules=()
33+
for _p in "$@"; do
34+
if [[ -f "${modules_dir}/$_p" ]]; then
35+
msg_debug "Found $_p as preset"
36+
readarray -t -O "${#_modules[@]}" _modules < <(grep -h -v ^'#' "${modules_dir}/${_p}")
37+
else
38+
_modules+=("$_p")
39+
fi
40+
done
41+
printf "%s\n" "${_modules[@]}"
42+
return 0
43+
}

0 commit comments

Comments
 (0)