Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / automounter.aug
1 (*
2 Module: Automounter
3   Parses automounter file based maps
4
5 Author: Dominic Cleal <dcleal@redhat.com>
6
7 About: Reference
8   See autofs(5)
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    To be documented
15
16 About: Configuration files
17    This lens applies to /etc/auto.*, auto_*, excluding known scripts.
18
19 About: Examples
20    The <Test_Automounter> file contains various examples and tests.
21 *)
22
23 module Automounter =
24 autoload xfm
25
26 (************************************************************************
27  * Group:                 USEFUL PRIMITIVES
28  *************************************************************************)
29
30 (* View: eol *)
31 let eol = Util.eol
32
33 (* View: empty *)
34 let empty   = Util.empty
35
36 (* View: comment *)
37 let comment = Util.comment
38
39 (* View: path *)
40 let path = /[^-+#: \t\n][^#: \t\n]*/
41
42 (* View: hostname *)
43 let hostname = /[^-:#\(\), \n\t][^:#\(\), \n\t]*/
44
45 (* An option label can't contain comma, comment, equals, or space *)
46 let optlabel = /[^,#:\(\)= \n\t]+/
47 let spec    = /[^,#:\(\)= \n\t][^ \n\t]*/
48
49 (* View: weight *)
50 let weight = Rx.integer
51
52 (* View: map_name *)
53 let map_name = /[^: \t\n]+/
54
55 (* View: entry_multimount_sep
56    Separator for multimount entries, permits line spanning with "\" *)
57 let entry_multimount_sep = del /[ \t]+(\\\\[ \t]*\n[ \t]+)?/ " "
58
59 (************************************************************************
60  * Group:                 ENTRIES
61  *************************************************************************)
62
63 (* View: entry_key
64    Key for a map entry *)
65 let entry_mkey = store path
66
67 (* View: entry_path
68    Path component of an entry location *)
69 let entry_path = [ label "path" . store path ]
70
71 (* View: entry_host
72    Host component with optional weight of an entry location *)
73 let entry_host = [ label "host" . store hostname
74                    . ( Util.del_str "(" . [ label "weight"
75                        . store weight ] . Util.del_str ")" )? ]
76
77 (* View: comma_sep_list
78    Parses options for filesystems *)
79 let comma_sep_list (l:string) =
80   let value = [ label "value" . Util.del_str "=" . store Rx.neg1 ] in
81     let lns = [ label l . store optlabel . value? ] in
82        Build.opt_list lns Sep.comma
83
84 (* View: entry_options *)
85 let entry_options = Util.del_str "-" . comma_sep_list "opt" . Util.del_ws_tab
86
87 (* View: entry_location
88    A single location with one or more hosts, and one path *)
89 let entry_location = ( entry_host . ( Sep.comma . entry_host )* )?
90                        . Sep.colon . entry_path
91
92 (* View: entry_locations 
93    Multiple locations (each with one or more hosts), separated by spaces *)
94 let entry_locations = [ label "location" . counter "location"
95                         . [ seq "location" . entry_location ]
96                         . ( [ Util.del_ws_spc . seq "location" . entry_location ] )* ]
97
98 (* View: entry_multimount
99    Parses one of many mountpoints given for a multimount line *)
100 let entry_multimount = entry_mkey . Util.del_ws_tab . entry_options? . entry_locations
101
102 (* View: entry_multimounts
103    Parses multiple mountpoints given on an entry line *)
104 let entry_multimounts = [ label "mount" . counter "mount"
105                           . [ seq "mount" . entry_multimount ]
106                           . ( [ entry_multimount_sep . seq "mount" . entry_multimount ] )* ]
107
108 (* View: entry
109    A single map entry from start to finish, including multi-mounts *)
110 let entry = [ seq "entry" . entry_mkey . Util.del_ws_tab . entry_options?
111               . ( entry_locations | entry_multimounts ) . Util.eol ]
112
113 (* View: include
114    An include line starting with a "+" and a map name *)
115 let include = [ seq "entry" . store "+" . Util.del_opt_ws ""
116                 . [ label "map" . store map_name ] . Util.eol ]
117
118 (* View: lns *)
119 let lns = ( empty | comment | entry | include ) *
120
121 (* Variable: filter
122    Exclude scripts/executable maps from here *)
123 let filter = incl "/etc/auto.*"
124            . incl "/etc/auto_*"
125            . excl "/etc/auto.master"
126            . excl "/etc/auto_master"
127            . excl "/etc/auto.net"
128            . excl "/etc/auto.smb"
129            . Util.stdexcl
130
131 let xfm = transform lns filter