aboutsummaryrefslogtreecommitdiffstats
path: root/modules/subversion/manifests/init.pp
blob: dd00586d03a2d9d05f523b577d44041be6ba3acd (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# should be replaced by vcsrepo
# https://github.com/reductivelabs/puppet-vcsrepo
# but not integrated in puppet directly for the moment
class subversion {

    class tools {
        package { "subversion-tools": }
    }

    class server {
        include subversion::tools

        package { "subversion-server": }
        
        $svn_base_path = '/svn/'

        xinetd::service { "svnserve":
            content => template('subversion/xinetd')
        }

        file { "$svn_base_path":
            ensure => directory,
        }

        package { ["perl-SVN-Notify-Config", "perl-SVN-Notify-Mirror"]: }
       
        $local_dir = "/usr/local/share/subversion/"
        $local_dirs = ["$local_dir/pre-commit.d", "$local_dir/post-commit.d"] 
        file { [$local_dir,$local_dirs]:
             ensure => directory,
        }

        # workaround the lack of umask command in puppet < 2.7
        local_script { "create_svn_repo.sh":
             content => template('subversion/create_svn_repo.sh') 
        }

        file { "$local_dir/pre-commit.d/no_binary":
            mode => 755,
            content => template('subversion/no_binary') 
        }

        file { "$local_dir/pre-commit.d/no_root_commit":
            mode => 755,
            content => template('subversion/no_root_commit') 
        }

        file { "$local_dir/pre-commit.d/no_empty_message":
            mode => 755,
            content => template('subversion/no_empty_message') 
        }

        file { "$local_dir/pre-commit.d/single_word_commit":
            mode => 755,
            content => template('subversion/single_word_commit') 
        }

        file { "$local_dir/pre-revprop-change":
            mode => 755,
            content => template('subversion/pre-revprop-change') 
        }

        # TODO : add check for
        #    - ym       perl -MYAML -e 'YAML::LoadFile("-");'
        #    - tt       ( do not seem to be possible, but this would be great )
        #    - php      php -l
        #    - python
        #    - named    named-checkzone/named-checkconf ( may requires some interaction with facter/erb )
        #    - po       msgfmt -c
        #    - openldap , like named

        define syntax_check($regexp_ext,$check_cmd) {
            file { "$local_dir/pre-commit.d/$name":
                mode => 755,
                content => template('subversion/syntax_check.sh') 
            }
        }


        syntax_check{"check_perl":
            regexp_ext => '\.p[lm]$',
            check_cmd => 'perl -c'
        }

        syntax_check{"check_puppet":
            regexp_ext => '\.pp$',
            check_cmd => 'puppet parser validate -'
        }

        syntax_check{"check_ruby":
            regexp_ext => '\.rb$',
            check_cmd => 'ruby -c'
        }

        syntax_check{"check_puppet_templates":
            regexp_ext => 'modules/.*/templates/.*$',
            check_cmd => 'erb -P -x -T - | ruby -c'
        }

        syntax_check{"check_po":
            regexp_ext => '\.po$',
            check_cmd => 'msgfmt -c -'
        }

        syntax_check{"check_php":
            regexp_ext => '\.php$',
            check_cmd => 'php -d display_errors=1 -d error_reporting="E_ALL|E_STRICT" -l'
        }

	# needed for check_php
        package { "php-cli": }

    }

   
    define pre_commit_link() {
        $scriptname = regsubst($name,'^.*/', '')
        file { "${name}":
            ensure => "/usr/local/share/subversion/pre-commit.d/$scriptname",
            mode => 755,
        }
    } 

    # TODO 
    #   deploy a cronjob to make a backup file ( ie, dump in some directory )

    # documentation :
    #    group : group that have commit access on the svn
    #    public : boolean if the svn is readable by anybody or not
    #    commit_mail : array of people who will receive mail after each commit
    #    cia_post : send commits to cia.vc
    #    cia_module : name of the module to send to cia.vc
    #    cia_ignore_author : a regexp to ignore commits from some authors
    #    no_binary : do not accept files with common binary extentions on this repository
    #    restricted_to_user : restrict commits to select user
    #    syntax_check : array of pre-commit script with syntax check to add
    #    extract_dir : hash of directory to update upon commit ( with svn update ), 
    #            initial checkout is not handled, nor the permission
    #            TODO, handle the tags ( see svn::notify::mirror )

    define repository ($group = "svn",
                       $public = true,
                       $commit_mail = '',
                       $i18n_mail = '',
                       $cia_post = true,
                       $cia_module = 'default',
		       $cia_ignore_author = '',
		       $no_binary = false,
		       $restricted_to_user = false,
                       $syntax_check = '',
                       $extract_dir = '') {
        # check permissions
        # http://svnbook.red-bean.com/nightly/fr/svn.serverconfig.multimethod.html
        # $name ==> directory of the repo
	include subversion::server
        # TODO set umask -> requires puppet 2.7.0
	# unfortunatly, umask is required
	# http://projects.puppetlabs.com/issues/4424
        exec { "/usr/local/bin/create_svn_repo.sh $name":
            user => root,
            group => $group,
            creates => "$name/hooks",
	    require => Package['subversion-tools'],
        }
        
	file { "$name":
            group => $group,
            owner => root,
            mode => $public ? {
                        true => 644,
                        false => 640
                    },
            ensure => directory
        }

        file { ["$name/hooks/pre-commit","$name/hooks/post-commit"]:
            mode => 755,
            content => template("subversion/hook_commit.sh"),
	    require => Exec["/usr/local/bin/create_svn_repo.sh $name"],
        }

        file { ["$name/hooks/post-commit.d", "$name/hooks/pre-commit.d"]:
            ensure => directory,
            require => File["$name/hooks/pre-commit"],
        }

        file { "$name/hooks/pre-revprop-change":
            ensure => "$subversion::server::local_dir/pre-revprop-change",
            mode => 755,
            require => File["$name/hooks/pre-commit"],
        } 

        if $restricted_to_user {
            subversion::hook::pre_commit("$name|restricted_to_user":
                content => template("subversion/restricted_to_user"),
            }
        } else {
            file { "$name/hooks/pre-commit.d/restricted_to_user":
                ensure => absent,
            }
        }

        if $commit_mail {
            subversion::hook::post_commit("$name|send_mail":
                content => template("subversion/hook_sendmail.pl"),
                require => [Package['perl-SVN-Notify-Config']],
            }
        } else {
            file { "$name/hooks/post-commit.d/send_mail":
	    	ensure => absent,
	    }
	}

	if $cia_post {
            subversion::hook::post_commit("$name|cia.vc":
                content => template("subversion/ciabot_svn.sh"),
            }
		
	} else {
	    file { "$name/hooks/post-commit.d/cia.vc":
		ensure => absent,
	    }
	}

	if $no_binary {
	    pre_commit_link { "$name/hooks/pre-commit.d/no_binary": }
	} else {
	    file { "$name/hooks/pre-commit.d/no_binary":
	       ensure => absent,
	    }
	}

        if $extract_dir {
            subversion::hook::post_commit("$name|extract_dir":
                content => template("subversion/hook_extract.pl"),
	    	require => [Package['perl-SVN-Notify-Mirror']],
            }
        } else {
            file { "$name/hooks/post-commit.d/extract_dir":
                ensure => absent,
	    }
	}

	pre_commit_link { "$name/hooks/pre-commit.d/no_empty_message": } 

	pre_commit_link { "$name/hooks/pre-commit.d/no_root_commit": }

	if $syntax_check {
	    $syntax_check_array = regsubst($syntax_check,'^',"$name/hooks/pre-commit.d/")
	    pre_commit_link { $syntax_check_array: }
        }
    }


    class client {
        # svn spam log with 
        # Oct 26 13:30:01 valstar svn: No worthy mechs found
        # without it, source http://mail-index.netbsd.org/pkgsrc-users/2008/11/23/msg008706.html 
        #
        $sasl2_package = $architecture ? {
        	x86_64 => "lib64sasl2-plug-anonymous",
        	default => "libsasl2-plug-anonymous"
    	}
 	
        package {['subversion', "$sasl2_package"]: }
    }

    define snapshot($source, $refresh = '*/5', $user = 'root')  {

        include subversion::client

        exec { "/usr/bin/svn co $source $name":
            creates => $name,           
            user => $user,
            require => Package['subversion']
        }

        cron { "update $name":
           command => "cd $name && /usr/bin/svn update -q",
           user => $user,
           minute => $refresh,
           require => Exec["/usr/bin/svn co $source $name"],
        }   
    }
    
    class mirror { 
        include subversion::tools
        local_script { "create_svn_mirror.sh":
             content => template('subversion/create_svn_mirror.sh') 
        }
    }

    define mirror_repository($source,
                             $refresh = '*/5') {
        include subversion::mirror 

        exec { "/usr/local/bin/create_svn_mirror.sh $name $source":
            creates => $name,           
            require => Package['subversion-tools']
        }

        cron { "update $name":
           command => "/usr/bin/svnsync synchronize -q file://$name",
           minute => $refresh,
           require => Exec["/usr/local/bin/create_svn_mirror.sh $name $source"],
        }   
    } 
}