Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / logrotate.aug
1 (* Logrotate module for Augeas                *)
2 (* Author: Raphael Pinson <raphink@gmail.com> *)
3 (* Patches from:                              *)
4 (*   Sean Millichamp <sean@bruenor.org>       *)
5 (*                                            *)
6 (* Supported :                                *)
7 (*   - defaults                               *)
8 (*   - rules                                  *)
9 (*   - (pre|post)rotate entries               *)
10 (*                                            *)
11 (* Todo :                                     *)
12 (*                                            *)
13
14 module Logrotate =
15    autoload xfm
16
17    let sep_spc = Sep.space
18    let sep_val = del /[ \t]*=[ \t]*|[ \t]+/ " "
19    let eol = Util.eol
20    let num = Rx.relinteger
21    let word = /[^,#= \n\t{}]+/
22    let filename = Quote.do_quote_opt (store /\/[^"',#= \n\t{}]+/)
23    let size = num . /[kMG]?/
24
25    let indent = del Rx.opt_space "\t"
26
27    (* define omments and empty lines *)
28    let comment = Util.comment
29    let empty   = Util.empty
30
31
32    (* Useful functions *)
33
34    let list_item = [ sep_spc . key /[^\/+,# \n\t{}]+/ ]
35    let select_to_eol (kw:string) (select:regexp) = [ label kw . store select ]
36    let value_to_eol (kw:string) (value:regexp)  = Build.key_value kw sep_val (store value)
37    let flag_to_eol (kw:string) = Build.flag kw
38    let list_to_eol (kw:string) = [ key kw . list_item+ ]
39
40
41    (* Defaults *)
42
43    let create =
44      let mode = sep_spc . [ label "mode" . store num ] in
45      let owner = sep_spc . [ label "owner" . store word ] in
46      let group = sep_spc . [ label "group" . store word ] in
47      [ key "create" .
48          ( mode | mode . owner | mode . owner . group )? ]
49
50    let su =
51      let owner = sep_spc . [ label "owner" . store word ] in
52      let group = sep_spc . [ label "group" . store word ] in
53      [ key "su" .
54          ( owner | owner . group )? ]
55
56    let tabooext = [ key "tabooext" . ( sep_spc . store /\+/ )? . list_item+ ]
57
58    let attrs = select_to_eol "schedule" /(hourly|daily|weekly|monthly|yearly)/
59                 | value_to_eol "rotate" num
60         | create
61         | flag_to_eol "nocreate"
62         | su
63         | value_to_eol "include" word
64         | select_to_eol "missingok" /(no)?missingok/
65         | select_to_eol "compress" /(no)?compress/
66         | select_to_eol "delaycompress" /(no)?delaycompress/
67         | select_to_eol "ifempty" /(not)?ifempty/
68         | select_to_eol "sharedscripts" /(no)?sharedscripts/
69         | value_to_eol "size" size
70         | tabooext
71         | value_to_eol "olddir" word
72         | flag_to_eol "noolddir"
73         | value_to_eol "mail" word
74         | flag_to_eol "mailfirst"
75         | flag_to_eol "maillast"
76         | flag_to_eol "nomail"
77         | value_to_eol "errors" word
78         | value_to_eol "extension" word
79         | select_to_eol "dateext" /(no)?dateext/
80         | value_to_eol "dateformat" word
81         | flag_to_eol "dateyesterday"
82         | value_to_eol "compresscmd" word
83         | value_to_eol "uncompresscmd" word
84         | value_to_eol "compressext" word
85         | list_to_eol "compressoptions"
86         | select_to_eol "copy" /(no)?copy/
87         | select_to_eol "copytruncate" /(no)?copytruncate/
88         | value_to_eol "maxage" num
89         | value_to_eol "minsize" size
90         | value_to_eol "maxsize" size
91         | select_to_eol "shred" /(no)?shred/
92         | value_to_eol "shredcycles" num
93         | value_to_eol "start" num
94
95    (* Define hooks *)
96
97
98    let hook_lines =
99      let line_re = /.*/ - /[ \t]*endscript[ \t]*/ in
100        store ( line_re . ("\n" . line_re)* )? . Util.del_str "\n"
101
102    let hooks =
103      let hook_names = /(pre|post)rotate|(first|last)action/ in
104      [ key hook_names . eol .
105        hook_lines? .
106        del /[ \t]*endscript/ "\tendscript" ]
107
108    (* Define rule *)
109
110    let body = Build.block_newlines
111                  (indent . (attrs | hooks) . eol)
112                  Util.comment
113
114    let rule =
115      let filename_entry = [ label "file" . filename ] in
116      let filename_sep = del /[ \t\n]+/ " " in
117      let filenames = Build.opt_list filename_entry filename_sep in
118      [ label "rule" . Util.indent . filenames . body . eol ]
119
120    let lns = ( comment | empty | (attrs . eol) | rule )*
121
122    let filter = incl "/etc/logrotate.d/*"
123               . incl "/etc/logrotate.conf"
124           . Util.stdexcl
125
126    let xfm = transform lns filter