Skip to content

Commit a9ec7c6

Browse files
committed
[check-config] No warning in blank argument
If user run current script whthout argument, the script will search config in default dir list, but output following message: | # script/check-config.sh | warning: /proc/config.gz seems not a kernel config, searching other paths for kernel config ... ^^^^^^^^^^^^^^^ | info: reading kernel config from /boot/config-4.7.0_HEAD_523d939ef98fd712632d93a5a2b588e477a7565e_ ... | ... We can make output better by restruct the code struct: 1: Specify nothing Show info, and search default dir 2: Specify a config file Use it directly 3: Specify a wrong config file Show warning, and search default dir 4: Specify a dir Info, and search specified dir Test: | # script/check-config.sh | info: no config specified, searching for kernel config ... | info: reading kernel config from /boot/config-4.7.0_HEAD_523d939ef98fd712632d93a5a2b588e477a7565e_ ... | | # script/check-config.sh /linux/.config | info: reading kernel config from /linux/.config ... | | # script/check-config.sh /linux/.configgg | warning: /linux/.configgg seems not a kernel config, searching other paths for kernel config ... | info: reading kernel config from /boot/config-4.7.0_HEAD_523d939ef98fd712632d93a5a2b588e477a7565e_ ... | | # script/check-config.sh /linux | info: input is a directory, searching for kernel config in this directory... | info: reading kernel config from /linux/.config ... | Signed-off-by: Zhao Lei <[email protected]>
1 parent 6683e16 commit a9ec7c6

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

script/check-config.sh

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ possibleConfigFiles=(
1616
'.config'
1717
)
1818

19-
if [ $# -gt 0 ]; then
20-
CONFIG="$1"
21-
else
22-
: ${CONFIG:="${possibleConfigs[0]}"}
23-
fi
24-
2519
if ! command -v zgrep &> /dev/null; then
2620
zgrep() {
2721
zcat "$2" | grep "$1"
@@ -115,29 +109,56 @@ check_distro_userns() {
115109
fi
116110
}
117111

118-
if [ ! -f "$CONFIG" ]; then
119-
wrap_warning "warning: $CONFIG seems not a kernel config, searching other paths for kernel config ..."
120-
for tryConfig in "$CONFIG" "${possibleConfigs[@]}"; do
112+
is_config()
113+
{
114+
local config="$1"
115+
116+
# Todo: more check
117+
[[ -f "$config" ]] && return 0
118+
return 1
119+
}
120+
121+
search_config()
122+
{
123+
local target_dir="$1"
124+
[[ "$target_dir" ]] || target_dir=("${possibleConfigs[@]}")
125+
126+
local tryConfig
127+
for tryConfig in "${target_dir[@]}"; do
128+
is_config "$tryConfig" && {
129+
CONFIG="$tryConfig"
130+
return
131+
}
121132
[[ -d "$tryConfig" ]] && {
122133
for tryFile in "${possibleConfigFiles[@]}"; do
123-
[[ -f "$tryConfig/$tryFile" ]] && {
124-
tryConfig+="/$tryFile"
125-
break
134+
is_config "$tryConfig/$tryFile" && {
135+
CONFIG="$tryConfig/$tryFile"
136+
return
126137
}
127138
done
128139
}
129-
[[ -f "$tryConfig" ]] && {
130-
CONFIG="$tryConfig"
131-
break
132-
}
133140
done
134-
if [ ! -f "$CONFIG" ]; then
135-
wrap_warning "error: cannot find kernel config"
136-
wrap_warning " try running this script again, specifying the kernel config:"
137-
wrap_warning " CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config"
138-
exit 1
141+
142+
wrap_warning "error: cannot find kernel config"
143+
wrap_warning " try running this script again, specifying the kernel config:"
144+
wrap_warning " CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config"
145+
exit 1
146+
}
147+
148+
CONFIG="$1"
149+
150+
is_config "$CONFIG" || {
151+
if [[ ! "$CONFIG" ]]; then
152+
wrap_color "info: no config specified, searching for kernel config ..." white
153+
search_config
154+
elif [[ -d "$CONFIG" ]]; then
155+
wrap_color "info: input is a directory, searching for kernel config in this directory..." white
156+
search_config "$CONFIG"
157+
else
158+
wrap_warning "warning: $CONFIG seems not a kernel config, searching other paths for kernel config ..."
159+
search_config
139160
fi
140-
fi
161+
}
141162

142163
wrap_color "info: reading kernel config from $CONFIG ..." white
143164
echo

0 commit comments

Comments
 (0)