5 Author: Raphael Pinson <raphink@gmail.com>
8 This lens tries to keep as close as possible to 'man services' where possible.
10 The definitions from 'man services' are put as commentaries for reference
11 throughout the file. More information can be found in the manual.
14 This file is licensed under the LGPL v2+, like the rest of Augeas.
17 Sample usage of this lens in augtool
19 * Get the name of the service running on port 22 with protocol tcp
20 > match "/files/etc/services/service-name[port = '22'][protocol = 'tcp']"
21 * Remove the tcp entry for "domain" service
22 > rm "/files/etc/services/service-name[. = 'domain'][protocol = 'tcp']"
23 * Add a tcp service named "myservice" on port 55234
24 > ins service-name after /files/etc/services/service-name[last()]
25 > set /files/etc/services/service-name[last()] "myservice"
26 > set "/files/etc/services/service-name[. = 'myservice']/port" "55234"
27 > set "/files/etc/services/service-name[. = 'myservice']/protocol" "tcp"
29 About: Configuration files
30 This lens applies to /etc/services. See <filter>.
37 (************************************************************************
38 * Group: USEFUL PRIMITIVES
39 *************************************************************************)
41 (* Group: Generic primitives *)
44 let eol = del /[ \t]*(#)?[ \t]*\n/ "\n"
45 let indent = Util.indent
46 let comment = Util.comment
47 let comment_or_eol = Util.comment_or_eol
48 let empty = Util.empty
49 let protocol_re = /[a-zA-Z]+/
50 let word_re = /[a-zA-Z0-9_.+*\/:-]+/
53 (* Group: Separators *)
54 let sep_spc = Util.del_ws_spc
57 (************************************************************************
59 *************************************************************************)
62 let port = [ label "port" . store num_re ]
64 (* View: port_range *)
65 let port_range = [ label "start" . store num_re ]
67 . [ label "end" . store num_re ]
70 let protocol = [ label "protocol" . store protocol_re ]
73 let alias = [ label "alias" . store word_re ]
77 * A standard /etc/services record
78 * TODO: make sure a space is added before a comment on new nodes
80 let record = [ label "service-name" . store word_re
81 . sep_spc . (port | port_range)
82 . del "/" "/" . protocol . ( sep_spc . alias )*
86 The services lens is either <empty>, <comment> or <record> *)
87 let lns = ( empty | comment | record )*
91 let filter = (incl "/etc/services")
93 let xfm = transform lns filter