Merge pull request #1023 from zhaoleidd/fix_check_config
Fix check config
This commit is contained in:
commit
7ec24c513f
|
@ -10,13 +10,12 @@ possibleConfigs=(
|
||||||
"/usr/src/linux-$(uname -r)/.config"
|
"/usr/src/linux-$(uname -r)/.config"
|
||||||
'/usr/src/linux/.config'
|
'/usr/src/linux/.config'
|
||||||
)
|
)
|
||||||
|
possibleConfigFiles=(
|
||||||
if [ $# -gt 0 ]; then
|
'config.gz'
|
||||||
CONFIG="$1"
|
"config-$(uname -r)"
|
||||||
else
|
'.config'
|
||||||
: ${CONFIG:="${possibleConfigs[0]}"}
|
)
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v zgrep &> /dev/null; then
|
if ! command -v zgrep &> /dev/null; then
|
||||||
zgrep() {
|
zgrep() {
|
||||||
zcat "$2" | grep "$1"
|
zcat "$2" | grep "$1"
|
||||||
|
@ -110,21 +109,56 @@ check_distro_userns() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ ! -e "$CONFIG" ]; then
|
is_config()
|
||||||
wrap_warning "warning: $CONFIG does not exist, searching other paths for kernel config ..."
|
{
|
||||||
for tryConfig in "${possibleConfigs[@]}"; do
|
local config="$1"
|
||||||
if [ -e "$tryConfig" ]; then
|
|
||||||
|
# Todo: more check
|
||||||
|
[[ -f "$config" ]] && return 0
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
search_config()
|
||||||
|
{
|
||||||
|
local target_dir="$1"
|
||||||
|
[[ "$target_dir" ]] || target_dir=("${possibleConfigs[@]}")
|
||||||
|
|
||||||
|
local tryConfig
|
||||||
|
for tryConfig in "${target_dir[@]}"; do
|
||||||
|
is_config "$tryConfig" && {
|
||||||
CONFIG="$tryConfig"
|
CONFIG="$tryConfig"
|
||||||
break
|
return
|
||||||
fi
|
}
|
||||||
|
[[ -d "$tryConfig" ]] && {
|
||||||
|
for tryFile in "${possibleConfigFiles[@]}"; do
|
||||||
|
is_config "$tryConfig/$tryFile" && {
|
||||||
|
CONFIG="$tryConfig/$tryFile"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
done
|
||||||
|
}
|
||||||
done
|
done
|
||||||
if [ ! -e "$CONFIG" ]; then
|
|
||||||
wrap_warning "error: cannot find kernel config"
|
wrap_warning "error: cannot find kernel config"
|
||||||
wrap_warning " try running this script again, specifying the kernel config:"
|
wrap_warning " try running this script again, specifying the kernel config:"
|
||||||
wrap_warning " CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config"
|
wrap_warning " CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config"
|
||||||
exit 1
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG="$1"
|
||||||
|
|
||||||
|
is_config "$CONFIG" || {
|
||||||
|
if [[ ! "$CONFIG" ]]; then
|
||||||
|
wrap_color "info: no config specified, searching for kernel config ..." white
|
||||||
|
search_config
|
||||||
|
elif [[ -d "$CONFIG" ]]; then
|
||||||
|
wrap_color "info: input is a directory, searching for kernel config in this directory..." white
|
||||||
|
search_config "$CONFIG"
|
||||||
|
else
|
||||||
|
wrap_warning "warning: $CONFIG seems not a kernel config, searching other paths for kernel config ..."
|
||||||
|
search_config
|
||||||
fi
|
fi
|
||||||
fi
|
}
|
||||||
|
|
||||||
wrap_color "info: reading kernel config from $CONFIG ..." white
|
wrap_color "info: reading kernel config from $CONFIG ..." white
|
||||||
echo
|
echo
|
||||||
|
|
Loading…
Reference in New Issue