3 Parses grub configuration
5 Author: David Lutterkort <lutter@redhat.com>
8 This file is licenced under the LGPL v2+, like the rest of Augeas.
17 (* This only covers the most basic grub directives. Needs to be *)
18 (* expanded to cover more (and more esoteric) directives *)
19 (* It is good enough to handle the grub.conf on my Fedora 8 box *)
22 (************************************************************************
23 * Group: USEFUL PRIMITIVES
24 *************************************************************************)
26 (* View: value_to_eol *)
27 let value_to_eol = store /[^= \t\n][^\n]*[^= \t\n]|[^= \t\n]/
32 (* View: del_to_eol *)
33 let del_to_eol = del /[^ \t\n]*/ ""
36 let spc = Util.del_ws_spc
39 let opt_ws = Util.del_opt_ws ""
42 let dels (s:string) = Util.del_str s
48 let switch (n:regexp) = dels "--" . key n
50 (* View: switch_arg *)
51 let switch_arg (n:regexp) = switch n . eq . store Rx.no_spaces
54 let value_sep (dflt:string) = del /[ \t]*[ \t=][ \t]*/ dflt
56 (* View: comment_re *)
57 let comment_re = /([^ \t\n].*[^ \t\n]|[^ \t\n])/
58 - /# ## (Start|End) Default Options ##/
62 [ Util.indent . label "#comment" . del /#[ \t]*/ "# "
63 . store comment_re . eol ]
66 let empty = Util.empty
68 (************************************************************************
69 * Group: USEFUL FUNCTIONS
70 *************************************************************************)
73 let command (kw:regexp) (indent:string) =
74 Util.del_opt_ws indent . key kw
77 let kw_arg (kw:regexp) (indent:string) (dflt_sep:string) =
78 [ command kw indent . value_sep dflt_sep . value_to_eol . eol ]
80 (* View: kw_boot_arg *)
81 let kw_boot_arg (kw:regexp) = kw_arg kw "\t" " "
83 (* View: kw_menu_arg *)
84 let kw_menu_arg (kw:regexp) = kw_arg kw "" " "
86 (* View: password_arg *)
87 let password_arg = [ key "password" .
88 (spc . [ switch "md5" ])? .
89 (spc . [ switch "encrypted" ])? .
90 spc . store (/[^ \t\n]+/ - /--[^ \t\n]+/) .
91 (spc . [ label "file" . store /[^ \t\n]+/ ])? .
95 let kw_pres (kw:string) = [ opt_ws . key kw . del_to_eol . eol ]
97 (************************************************************************
99 *************************************************************************)
102 * This is a shell-only directive in upstream grub; the grub versions
103 * in at least Fedora/RHEL use this to find devices for UEFI boot *)
105 [ command "device" "" . Sep.space . store /\([A-Za-z0-9_.-]+\)/ . spc .
106 [ label "file" . value_to_eol ] . Util.eol ]
110 (* Should we nail it down to exactly the color names that *)
111 (* grub supports ? *)
112 let color_name = store /[A-Za-z-]+/ in
114 [ label "foreground" . color_name] .
116 [ label "background" . color_name ] in
117 [ opt_ws . key "color" .
118 spc . [ label "normal" . color_spec ] .
119 (spc . [ label "highlight" . color_spec ])? .
124 [ command "serial" "" .
125 [ spc . switch_arg /unit|port|speed|word|parity|stop|device/ ]* .
130 [ command "terminal" "" .
131 ([ spc . switch /dumb|no-echo|no-edit|silent/ ]
132 |[ spc . switch_arg /timeout|lines/ ])* .
133 [ spc . key /console|serial|hercules/ ]* . eol ]
136 let setkey = [ command "setkey" "" .
137 ( spc . [ label "to" . store Rx.no_spaces ] .
138 spc . [ label "from" . store Rx.no_spaces ] )? .
141 (* View: menu_setting *)
142 let menu_setting = kw_menu_arg "default"
143 | kw_menu_arg "fallback"
144 | kw_pres "hiddenmenu"
145 | kw_menu_arg "timeout"
146 | kw_menu_arg "splashimage"
147 | kw_menu_arg "gfxmenu"
148 | kw_menu_arg "foreground"
149 | kw_menu_arg "background"
150 | kw_menu_arg "verbose"
159 let title = del /title[ \t=]+/ "title " . value_to_eol . eol
161 (* View: multiboot_arg
162 * Permits a second form for Solaris multiboot kernels that
163 * take a path (with a slash) as their first arg, e.g.
164 * /boot/multiboot kernel/unix another=arg *)
165 let multiboot_arg = [ label "@path" .
166 store (Rx.word . "/" . Rx.no_spaces) ]
169 Parse the file name and args on a kernel or module line. *)
171 let arg = /[A-Za-z0-9_.$-]+/ - /type|no-mem-option/ in
172 store /(\([a-z0-9,]+\))?\/[^ \t\n]*/ .
173 (spc . multiboot_arg)? .
174 (spc . [ key arg . (eq. store /([^ \t\n])*/)?])* . eol
177 Solaris extension adds module$ and kernel$ for variable interpolation *)
179 [ command /module\$?/ "\t" . spc . kernel_args ]
183 [ command "map" "\t" . spc .
184 [ label "from" . store /[()A-za-z0-9]+/ ] . spc .
185 [ label "to" . store /[()A-za-z0-9]+/ ] . eol ]
189 [ command /kernel\$?/ "\t" .
191 ([switch "type" . eq . store /[a-z]+/]
192 |[switch "no-mem-option"]))* .
195 (* View: chainloader *)
197 [ command "chainloader" "\t" .
198 [ spc . switch "force" ]? . spc . store Rx.no_spaces . eol ]
200 (* View: savedefault *)
202 [ command "savedefault" "\t" . (spc . store Rx.integer)? . eol ]
204 (* View: configfile *)
206 [ command "configfile" "\t" . spc . store Rx.no_spaces . eol ]
208 (* View: boot_setting
211 let boot_arg_re = "root" | "initrd" | "rootnoverify" | "uuid"
212 | "findroot" | "bootfs" (* Solaris extensions *)
213 in kw_boot_arg boot_arg_re
216 | kw_pres "quiet" (* Seems to be a Ubuntu extension *)
222 | kw_pres "makeactive"
226 let line = ((boot_setting|comment)* . boot_setting)? in
227 [ label "title" . title . line ]
229 (************************************************************************
230 * Group: DEBIAN-SPECIFIC SECTIONS
231 *************************************************************************)
233 (* View: debian_header
234 Header for a <debian>-specific section *)
235 let debian_header = "## ## Start Default Options ##\n"
237 (* View: debian_footer
238 Footer for a <debian>-specific section *)
239 let debian_footer = "## ## End Default Options ##\n"
241 (* View: debian_comment_re *)
242 let debian_comment_re = /([^ \t\n].*[^ \t\n]|[^ \t\n])/
243 - "## End Default Options ##"
245 (* View: debian_comment
246 A comment entry inside a <debian>-specific section *)
248 [ Util.indent . label "#comment" . del /##[ \t]*/ "## "
249 . store debian_comment_re . eol ]
251 (* View: debian_setting_re *)
252 let debian_setting_re = "kopt"
263 | "updatedefaultentry"
267 (* View: debian_entry *)
268 let debian_entry = [ Util.del_str "#" . Util.indent
269 . key debian_setting_re . del /[ \t]*=/ "="
270 . value_to_eol? . eol ]
273 A debian-specific section, made of <debian_entry> lines *)
274 let debian = [ label "debian"
275 . del debian_header debian_header
276 . (debian_comment|empty|debian_entry)*
277 . del debian_footer debian_footer ]
279 (************************************************************************
280 * Group: LENS AND FILTER
281 *************************************************************************)
284 let lns = (comment | empty | menu_setting | boot | debian)*
287 let filter = incl "/boot/grub/grub.conf"
288 . incl "/boot/grub/menu.lst"
289 . incl "/etc/grub.conf"
291 let xfm = transform lns filter