@@ -10,13 +10,12 @@ possibleConfigs=(
1010 " /usr/src/linux-$( uname -r) /.config"
1111 ' /usr/src/linux/.config'
1212)
13-
14- if [ $# -gt 0 ]; then
15- CONFIG=" $1 "
16- else
17- : ${CONFIG:= " ${possibleConfigs[0]} " }
18- fi
19-
13+ possibleConfigFiles=(
14+ ' config.gz'
15+ " config-$( uname -r) "
16+ ' .config'
17+ )
18+
2019if ! command -v zgrep & > /dev/null; then
2120 zgrep () {
2221 zcat " $2 " | grep " $1 "
@@ -110,21 +109,56 @@ check_distro_userns() {
110109 fi
111110}
112111
113- if [ ! -e " $CONFIG " ]; then
114- wrap_warning " warning: $CONFIG does not exist, searching other paths for kernel config ..."
115- for tryConfig in " ${possibleConfigs[@]} " ; do
116- if [ -e " $tryConfig " ]; then
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 " && {
117129 CONFIG=" $tryConfig "
118- break
119- fi
130+ return
131+ }
132+ [[ -d " $tryConfig " ]] && {
133+ for tryFile in " ${possibleConfigFiles[@]} " ; do
134+ is_config " $tryConfig /$tryFile " && {
135+ CONFIG=" $tryConfig /$tryFile "
136+ return
137+ }
138+ done
139+ }
120140 done
121- if [ ! -e " $CONFIG " ]; then
122- wrap_warning " error: cannot find kernel config"
123- wrap_warning " try running this script again, specifying the kernel config:"
124- wrap_warning " CONFIG=/path/to/kernel/.config $0 or $0 /path/to/kernel/.config"
125- 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
126160 fi
127- fi
161+ }
128162
129163wrap_color " info: reading kernel config from $CONFIG ..." white
130164echo
0 commit comments