This repository was archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsvn_checkout.cf
130 lines (104 loc) · 6.35 KB
/
svn_checkout.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright 2011 Nick Anderson <[email protected]>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY NICK ANDERSON ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NICK ANDERSON OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those of the
# authors and should not be interpreted as representing official policies, either expressed
# or implied, of Nick Anderson.
bundle agent maintain_svn_checkout_noauth(svn_url, revision, checkout_path) {
# Maintain CLEAN checkout of specified revision from specified SVN repository path noauth
# Requires cfengine stdlib copbl
# Example usage:
# methods:
# policyhub::
# "any" usebundle => maintain_svn_checkout_noauth("http://myrepo/cfengine/inputs/trunk, "HEAD", "/var/cfengine/inputs"),
# comment => "Ensure policy checkout is clean at at the proper revision";
classes:
"checkout_directory_exists" expression => fileexists($(checkout_path));
"svn_checkout_references_correct_repo" expression => returnszero("/usr/bin/svn info $(checkout_path)/ | grep '^URL: $(svn_url)' > /dev/null","useshell");
"svn_checkout_exists" expression => returnszero("/usr/bin/svn info $(checkout_path) > /dev/null","useshell");
"unversioned_files_present" expression => returnszero("/usr/bin/svn status --no-ignore $(checkout_path) | grep ^? > /dev/null","useshell");
"modified_files_present" expression => returnszero("/usr/bin/svn status --no-ignore $(checkout_path) | grep ^M > /dev/null","useshell");
"svn_repo_needs_update" expression => returnszero("/usr/bin/svn status --show-updates $(checkout_path) | grep '*' > /dev/null", "useshell");
files:
# if checkout directory exists but isnt a valid checkout
checkout_directory_exists.!svn_checkout_exists::
"$(checkout_path)"
handle => "purge $(checkout_path)",
comment => "The file or directory $(checkout_path) not a valid working copy. Deleting all conflicting files.",
delete => tidy,
file_select => by_name(".*"),
depth_search => recurse("inf");
commands:
# If there is a checkout present, but it is of the wrong repository then switch to the right one
!svn_checkout_references_correct_repo.svn_checkout_exists::
"/usr/bin/svn switch --non-interactive $(svn_url)"
handle => "svn_switch",
comment => "Current checkout not pointing to the correct repository, switch to the correct repository",
classes => if_ok("svn_checkout_references_correct_repo"),
contain => in_shell;
# If valid svn co, ensure no unversioned files
unversioned_files_present::
"/usr/bin/svn status --no-ignore $(checkout_path) | grep ^? | cut -c 8- | xargs -I '{}' rm -rfv '{}' || exit 1"
handle => "svn_clean",
comment => "Remove unversioned files",
classes => define_cancel_if_ok("removed_unversioned_files","unversioned_files_present"),
contain => in_shell;
# if modified files present then revert them
modified_files_present::
"/usr/bin/svn revert --recursive $(checkout_path)"
handle => "svn_revert",
comment => "Ensure svn working copy $(checkout_path) has no modified files",
classes => define_cancel_if_ok("reverted_modified_files","modified_files_present");
# if svn checkout references the correct repository ensure we are up to date
svn_repo_needs_update.svn_checkout_references_correct_repo::
"/usr/bin/svn update $(checkout_path) --revision $(revision)"
handle => "svn_update",
comment => "Ensure svn working copy $(checkout_path) is up to date with revision $(revision)",
classes => if_ok("svn_checkout_updated");
# If not a valid working copy, or nothing exists at the specified location perform a checkout
!svn_checkout_exists||!checkout_directory_exists.!svn_checkout_references_correct_repo::
"/usr/bin/svn checkout --revision $(revision) $(svn_url) $(checkout_path)"
handle => "svn_checkout",
comment => "Checkout $(svn_url) revision $(revision) to $(checkout_path)",
classes => if_ok("svn_checkout_exists, checkout_directory_exists");
reports:
checkout_directory_exists.!svn_checkout_exists::
"SVN: Perform new checkout of $(checkout_path) from $(svn_url) revision $(revision)";
svn_checkout_updated::
"SVN: Updated svn working copy $(checkout_path) to $(revision) from repo $(svn_url)";
reverted_modified_files::
"SVN: Reverted modified files in $(checkout_path)";
removed_unversioned_files::
"SVN: Removed unversioned files in $(checkout_path)";
}
body classes cancel_if_ok(x)
{
cancel_repaired => { "$(x)" };
cancel_kept => { "$(x)" };
}
body classes define_cancel_if_ok(define, cancel)
{
cancel_repaired => { "$(cancel)" };
cancel_kept => { "$(cancel)" };
promise_repaired => { "$(define)" };
promise_kept => { "$(define)" };
}