summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: c2d7c001a7b685478f83ebd591717bc60caff04f (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
# @summary Manages a cgit server
#
# Many of these options maps directly to cgit's options (replace
# underscore with dash).
#
# Also see cgitrc(5).
#
# @param root_title
#   Top title of webpage
# @param root_desc
#   Description under title on web page
# @param scan_path
#   Directory to scan for git repos
# @param clone_url
#   List of
# @param root
#   Webroot, media files and similar will be placed here
# @param filterpath
#   Where filter files shouldbe placed
# @param root_readme_source
#   Source attribute passed along to puppet's file for the global
#   summary page. Mutually exclusive with root_readme_content.
# @param root_readme_content
#   Content attribute passed along to puppet's file for the global
#   summary page. Mutually exclusive with root_readme_source.
# @param root_readme_sha256
#   SHA256 sum of root_readme_{source,content}
# @param root_readme_extension
#   Optional extension of file. Useful if ones "about" filter checks
#   filename to determine rendering.
# @param enable_http_clone
#   Enable cgit's built in dump HTTP clone entdpoint.
# @param public_repos
#   A list of repos under scan_path which should be public. Used if
#   manage_server is set to nginx, and is also dumped to the file
#   /usr/local/var/public-repos, for use by custom filters.
# @param users
#   Used for basic auth by nginx, if manage_server is true.
# @param manage_server
#   Should a webserver be managed by us. Currently only nginx is
#   supported.
# @param server_name
#   Passed to nginx::resource::server's server_name.
# @param htpasswd
#   Path to htpasswd file used by nginx's basic auth.
# @param cgitrc
#   Path to system cgitrc file.
# @param filters
#   CGIT filters to be managed.
#   @see cgit::filter
class cgit (
  String $root_title,
  String $root_desc,
  String $scan_path,
  Array[String] $clone_url = [],
  String $root = '/var/www/cgit',
  String $filterpath = '/usr/lib/cgit/puppet-controlled-filters',
  String $root_readme_source = "puppet:///modules/${module_name}/root_readme",
  Optional[String] $root_readme_content = undef,
  Optional[String] $root_readme_sha256 = undef,
  String $root_readme_extension = '', # lint:ignore:params_empty_string_assignment
  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,
  String $htpasswd = '/var/lib/nginx/cgit-htpasswd',
  String $cgitrc = '/etc/cgitrc',
  Hash[String, Hash] $filters = {},
) {
  # TODO figure out where CSS comes from

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

  Cgit::Filter <| |> -> Concat[$cgitrc]

  concat { $cgitrc:
    ensure => present,
  }

  concat::fragment { 'cgit config upper half':
    order   => 0,
    content => epp('cgit/upper.epp'),
    target  => $cgitrc,
  }

  concat::fragment { 'cgit config lower half':
    order   => 99,
    content => epp('cgit/lower.epp'),
    target  => $cgitrc,
  }

  create_resources(cgit::filter, $filters)

  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',
  }

  $chksum = if $root_readme_sha256 != undef {
    {
      'checksum'       => 'sha256',
      'checksum_value' => $root_readme_sha256,
    }
  } else {
    {}
  }

  $readme = "${root}/README${root_readme_extension}"
  if $root_readme_content {
    file { $readme:
      ensure  => file,
      content => $root_readme_content,
      *       => $chksum,
    }
  } else {
    file { $readme:
      ensure => file,
      source => $root_readme_source,
      *      => $chksum,
    }
  }

  file { ['/usr/local', '/usr/local/var']:
    ensure => directory,
  }

  file { '/usr/local/var/public-repos':
    ensure  => file,
    content => ($public_repos << '').join("\n"),
  }

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

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