-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathfile_hash.cf
64 lines (52 loc) · 2.21 KB
/
file_hash.cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2019 Northern.tech AS
# This file is part of Cfengine 3 - written and maintained by Northern.tech AS.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 3.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
# To the extent this program is licensed as part of the Enterprise
# versions of Cfengine, the applicable Commercial Open Source License
# (COSL) may apply to this file if you as a licensee so wish it. See
# included file COSL.txt.
#+begin_src prep
#@ ```
#@ echo 1 > /tmp/1
#@ echo 2 > /tmp/2
#@ echo 3 > /tmp/3
#@ ```
#+end_src
###############################################################################
#+begin_src cfengine3
body common control
{
bundlesequence => { "example" };
}
bundle agent example
{
vars:
"md5" string => file_hash("/tmp/1","md5");
"sha256" string => file_hash("/tmp/2","sha256");
"sha384" string => hash("/tmp/3","sha384");
"sha512" string => hash("/tmp/3","sha512");
reports:
"'1\n' hashed to: md5 $(md5)";
"'2\n' hashed to: sha256 $(sha256)";
"'3\n' hashed to: sha384 $(sha384)";
"'3\n' hashed to: sha512 $(sha512)";
}
#+end_src
###############################################################################
#+begin_src example_output
#@ ```
#@ R: '1\n' hashed to: md5 b026324c6904b2a9cb4b88d6d61c81d1
#@ R: '2\n' hashed to: sha256 53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3
#@ R: '3\n' hashed to: sha384 54f7379844b41bf513c0557a7195ca96a8ac90d0f8cc87d3607ef7ab593a7c61732759387afaabaf72ca2c0bd599373e
#@ R: '3\n' hashed to: sha512 48b3c46b24db82059b5c87603066cf8d2165837d66e268286feb384644c808c06edf99aeaca0d879f4ee6ec70ebfaa0b98d5b77c12f7c0a68de3f7302dec6e21
#@ ```
#+end_src