Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / crypttab.aug
1 (*
2 Module: Crypttab
3   Parses /etc/crypttab from the cryptsetup package.
4
5 Author: Frédéric Lespez <frederic.lespez@free.fr>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man crypttab` where possible.
9
10 About: License
11   This file is licensed under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14   Sample usage of this lens in augtool
15
16     * Create a new entry for an encrypted block devices
17       > ins 01 after /files/etc/crypttab/*[last()]
18       > set /files/etc/crypttab/01/target crypt_sda2
19       > set /files/etc/crypttab/01/device /dev/sda2
20       > set /files/etc/crypttab/01/password /dev/random
21       > set /files/etc/crypttab/01/opt swap
22     * Print the entry applying to the "/dev/sda2" device
23       > print /files/etc/crypttab/01
24     * Remove the entry applying to the "/dev/sda2" device
25       > rm /files/etc/crypttab/*[device="/dev/sda2"]
26
27 About: Configuration files
28   This lens applies to /etc/crypttab. See <filter>.
29 *)
30
31 module Crypttab =
32   autoload xfm
33
34   (************************************************************************
35    * Group:                 USEFUL PRIMITIVES
36    *************************************************************************)
37
38   (* Group: Separators *)
39
40   (* Variable: sep_tab *)
41   let sep_tab = Sep.tab
42
43   (* Variable: comma *)
44   let comma   = Sep.comma
45
46   (* Group: Generic primitives *)
47
48   (* Variable: eol *)
49   let eol     = Util.eol
50
51   (* Variable: comment *)
52   let comment = Util.comment
53
54   (* Variable: empty *)
55   let empty   = Util.empty
56
57   (* Variable: word *)
58   let word    = Rx.word
59
60    (* Variable: optval *)
61   let optval  = /[A-Za-z0-9\/_.:-]+/
62
63   (* Variable: target *)
64   let target  = Rx.device_name
65
66   (* Variable: fspath *)
67   let fspath  = Rx.fspath
68
69   (* Variable: uuid *)
70   let uuid = /UUID=[0-9a-f-]+/
71
72   (************************************************************************
73    * Group:                       ENTRIES
74    *************************************************************************)
75
76   (************************************************************************
77    * View: comma_sep_list
78    *   A comma separated list of options (opt=value or opt)
79    *************************************************************************)
80   let comma_sep_list (l:string) =
81     let value = [ label "value" . Util.del_str "=" . store optval ] in
82       let lns = [ label l . store word . value? ] in
83          Build.opt_list lns comma
84
85   (************************************************************************
86    * View: record
87    *   A crypttab record
88    *************************************************************************)
89
90   let record = [ seq "entry" .
91                    [ label "target" . store target ] . sep_tab .
92                    [ label "device" . store (fspath|uuid) ] .
93                    (sep_tab . [ label "password" . store fspath ] .
94                     ( sep_tab . comma_sep_list "opt")? )?
95                  . eol ]
96
97   (*
98    * View: lns
99    *   The crypttab lens
100    *)
101   let lns = ( empty | comment | record ) *
102
103   (* Variable: filter *)
104   let filter = (incl "/etc/crypttab")
105
106   let xfm = transform lns filter
107
108 (* coding: utf-8 *)