summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: c4e5334500e799b00328d98c02efcf39a2168016 (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
class cgit (
    String $root = '/var/www/cgit',
    String $filterpath = '/usr/lib/cgit/extra-filters',
    String $root_title,
    String $root_desc,
    String $about_filter,
    String $auth_filter,
    String $source_filter,
    String $scan_path,
    Array[String] $clone_url,
    Boolean $enable_http_clone = false,
    Array[String] $public_repos = [],
    Array[Struct[{
      name => String,
      pass => String }]] $users = [],
    Variant[Boolean, Enum['nginx']] $manage_server = false,
    Optional[String] $server_name = undef,
    Optional[String] $certname = undef,
    String $htpasswd = '/var/lib/nginx/cgit-htpasswd',
) {

    # TODO figure out where CSS comes from

    ensure_packages([
        'git',
        'cgit',
    ], { ensure => installed })

    file { '/etc/cgitrc':
      ensure => file,
      content => epp('cgit/cgitrc.epp'),
    }

    file { "${root}/logo":
        ensure => directory,
    }

    file { "${root}/logo/logo.png":
        ensure => file,
        source => 'puppet:///modules/cgit/logo.png',
    }

    file { "${root}/logo/logo_large.png":
        ensure => file,
        source => 'puppet:///modules/cgit/logo_large.png',
    }

    file { "${root}/root_readme":
        ensure => file,
        source => 'puppet:///modules/cgit/root_readme',
    }

    file { dirname($filterpath):
        ensure => directory,
    }

    file { $filterpath:
        ensure => directory,
    }

    [$about_filter, $source_filter].each |$f| {
        file { "${filterpath}/${f}":
            ensure => file,
            source => "puppet:///modules/cgit/filters/${f}",
            mode   => stdlib::extname($f) ? {
                 '.lua'  => '0444',
                 default => '0555',
            },
        }
    }

    file { "${filterpath}/${auth_filter}":
      ensure  => file,
      content => epp("cgit/${auth_filter}.epp"),
      mode    => '0444',
    }

    if $manage_server {
      if $server_name == undef {
        fail('server_name must be set if manage_server is set')
      }
    }

    case $manage_server {
      false: {}
      'nginx': {
        include ::cgit::nginx
      }
    }
}