Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1fde3fa1d492d7d22aa9b821410fbd77c0bbef0f (plain) (blame)
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
309
310
311
312
313
314
315
316
317
318
319
320
/*******************************************************************************
 * Copyright (c) 2012 Frank Becker and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Frank Becker - initial API and implementation
 *     Steffen Pingel (Tasktop Techologies)
 *******************************************************************************/
define bugzilla::site (
  $major,
  $minor,
  $micro,
  $branch               = "${major}.${minor}",
  $bugz_dbname          =  regsubst($title, '([^.-]+)([.-]+)', '\1_', 'G'),
  $bugz_user            = $bugzilla::dbuser,
  $bugz_password        = $bugzilla::dbuserPassword,
  $www_url              = "$title",
  $bugzillaDir          = "$title",
  $branchTag            = "",
  $custom_wf            = false,
  $custom_wf_and_status = false,
  $xmlrpc_enabled       = true,
  $base                 = $bugzilla::bugzillaBase,
  $envtype              = "bugzilla",
  $envid                = "$title",
  $userOwner            = $bugzilla::userOwner,
  $userGroup            = $bugzilla::userGroup,
  $envversion           = "",
  $envdefault           = false,
  $envdefault_rest      = false,
  $desciptorfile        = " ",
  $usebugaliases        = false,
  $clearMode            = $bugzilla::clearMode,
  $rest_enabled         = false,
  $envinfo              = "",
  $testdataVersion      = "",
  ) {

  include "bugzilla"
  $propertyanz = 0
  $confDir = "$base/conf.d"
  if ($branchTag !="") {
    $branchTagInternal = $branchTag
  } else {
    if ($micro !="") {
      $branchTagInternal = "release-${major}.${minor}.${micro}"
    } else {
      $branchTagInternal = "release-${major}.${minor}"
    }
  }
    if ($envversion !="") {
    $envversionInternal = $envversion
  } else {
    if ($micro !="") {
      $envversionInternal = "${major}.${minor}.${micro}"
    } else {
      $envversionInternal = "${major}.${minor}"
    }
  }
  if $custom_wf {
    $envinfo1 = "Custom Workflow"
  } elsif $custom_wf_and_status {
    $envinfo1 = "Custom Workflow and Status"
  } elsif $usebugaliases {
    $envinfo1 = "Use Bugaliases"
  } else {
    $envinfo1 = ""
  }
  if $envinfo1 != "" {
    if !$xmlrpc_enabled {
      $envinfo2 = "$envinfo1, XML-RPC disabled"
    } else {
       $envinfo2 = "$envinfo1"
    }
  } else {
    if !$xmlrpc_enabled {
      $envinfo2 = "XML-RPC disabled"
    } else {
       $envinfo2 = ""
    }
  }
  if $envinfo != "" {
      $envinfo_intern = $envinfo
  } else {
      $envinfo_intern = $envinfo2
  }
  if $major == "3" {
    if $minor == "6" {
      $VersionCreateName = "name"
    } else {
      $VersionCreateName = "value"
    }
  } else {
    $VersionCreateName = "value"
  }

  if $branch == "master" {
    if $branchTagInternal == "HEAD" {
      exec { "master master git fetch $bugzillaDir":
        command => "git fetch",
        onlyif    => "/usr/bin/test -d $base/$bugzillaDir",
        cwd     => "$base/$bugzillaDir",
        user => "$userOwner",
        timeout => 300,
        logoutput => true,
        require   => Exec["prepare bugzilla"],
        notify => Exec["end extract bugzilla $bugzillaDir"],
      }
      exec { "master master git clone $bugzillaDir":
        command => "git clone http://git.mozilla.org/bugzilla/bugzilla $base/$bugzillaDir",
        cwd     => "$base",
        user => "$userOwner",
        timeout => 300,
        creates => "$base/$bugzillaDir",
        require   => Exec["prepare bugzilla"],
        notify => Exec["end extract bugzilla $bugzillaDir"],
      }
    } else {
      exec { "master $branchTagInternal git clone $bugzillaDir":
        command => "git clone -b $branch http://git.mozilla.org/bugzilla/bugzilla $base/$bugzillaDir",
        cwd     => "$base",
        user => "$userOwner",
        timeout => 300,
        creates => "$base/$bugzillaDir",
        require   => Exec["prepare bugzilla"],
      }
      exec { "master $branchTagInternal git checkout $bugzillaDir":
        command => "git checkout $branchTagInternal",
        cwd     => "$base/$bugzillaDir",
        user => "$userOwner",
        logoutput => true,
        timeout => 300,
        require   => Exec["master $branchTagInternal git clone $bugzillaDir"],
        notify => Exec["end extract bugzilla $bugzillaDir"],
      }
    }
  } else {
    exec { "$branch $branchTagInternal git fetch $bugzillaDir":
      command => "git fetch",
      onlyif    => "/usr/bin/test -d $base/$bugzillaDir",
      cwd     => "$base/$bugzillaDir",
      user => "$userOwner",
      timeout => 300,
      logoutput => true,
      require   => Exec["prepare bugzilla"],
      notify => Exec["end extract bugzilla $bugzillaDir"],
    }

    exec { "$branch $branchTagInternal git clone $bugzillaDir":
      command => "git clone -b $branch http://git.mozilla.org/bugzilla/bugzilla $base/$bugzillaDir",
      cwd     => "$base",
      user => "$userOwner",
      timeout => 300,
      creates => "$base/$bugzillaDir",
      require   => Exec["prepare bugzilla"],
    }
    if $branchTagInternal == "HEAD" {
      exec { "$branch $branchTagInternal dummy git checkout $bugzillaDir":
        command => "echo '$branch $branchTagInternal dummy git checkout $bugzillaDir'",
        logoutput => true,
        require   => Exec["$branch $branchTagInternal git clone $bugzillaDir"],
        notify => Exec["end extract bugzilla $bugzillaDir"],
      }
    } else {
      exec { "$branch $branchTagInternal git checkout $bugzillaDir":
        command => "git checkout $branchTagInternal",
        cwd     => "$base/$bugzillaDir",
        user => "$userOwner",
        timeout => 300,
        require   => Exec["$branch $branchTagInternal git clone $bugzillaDir"],
        notify => Exec["end extract bugzilla $bugzillaDir"],
      }
    }
  }

  exec { "end extract bugzilla $bugzillaDir":
      command => "echo 'end extract bugzilla $bugzillaDir $branch $branchTagInternal'",
      logoutput => true,
    }

  file { "$base/$bugzillaDir/installPerlModules.sh":
    content => template('bugzilla/installPerlModules.sh.erb'),
    owner   => "$userOwner",
    group   => "$userGroup",
    mode    => 0755,
    require => Exec["end extract bugzilla $bugzillaDir"],
  }

  exec { "post extract bugzilla $bugzillaDir":
    command => "$base/$bugzillaDir/installPerlModules.sh  >$base/$bugzillaDir/CGI.out",
    cwd     => "$base/$bugzillaDir",
    creates => "$base/$bugzillaDir/CGI.out",
    user => "$userOwner",
    timeout => 300,
    require   => File["$base/$bugzillaDir/installPerlModules.sh"]
  }

  exec { "mysql-grant-${bugz_dbname}-${bugzilla::dbuser}":
    unless    =>
    "/usr/bin/mysql --user=root --batch -e \"SELECT user FROM db WHERE Host='localhost' and Db='${bugz_dbname}' and User='${bugzilla::dbuser}'\" mysql | /bin/grep '${bugzilla::dbuser}'",
    command   => "/usr/bin/mysql --verbose --user=root -e \"GRANT ALL ON ${bugz_dbname}.* TO '${bugzilla::dbuser}'@localhost\" \
        		; /usr/bin/mysqladmin --verbose --user=root flush-privileges",
    require   => Exec["post extract bugzilla $bugzillaDir"]
  }

  if $clearMode == "clear" {
    exec { "mysql-dropdb-$bugzillaDir":
      onlyif    => "/usr/bin/mysql --user=root '${bugz_dbname}'",
      command   => "/usr/bin/mysqladmin -v --user=root --force drop '${bugz_dbname}'",
      require   => Exec["mysql-grant-${bugz_dbname}-${bugzilla::dbuser}"]
    }

    exec { "mysql-createdb-$bugzillaDir":
      unless    => "/usr/bin/mysql --user=root '${bugz_dbname}'",
      command   => "/usr/bin/mysqladmin -v --user=root --force create '${bugz_dbname}'",
      require   => Exec["mysql-dropdb-$bugzillaDir"]
    }
  } else {
    exec { "mysql-createdb-$bugzillaDir":
      unless    => "/usr/bin/mysql --user=root '${bugz_dbname}'",
      command   => "/usr/bin/mysqladmin -v --user=root --force create '${bugz_dbname}'",
      require   => Exec["mysql-grant-${bugz_dbname}-${bugzilla::dbuser}"]
    }
  }

  file { "$base/$bugzillaDir/callchecksetup.pl":
    content => template('bugzilla/callchecksetup.pl.erb'),
    owner   => "$userOwner",
    group   => "$userGroup",
    mode    => 0755,
    require => Exec["post extract bugzilla $bugzillaDir"],
  }

  file { "$base/$bugzillaDir/answers":
    content => template('bugzilla/answers.erb'),
    owner   => "$userOwner",
    group   => "$userGroup",
    require => Exec["post extract bugzilla $bugzillaDir"],
  }

  file { "$base/$bugzillaDir/extensions/Mylyn":
    ensure  => directory, # so make this a directory
    recurse => true, # enable recursive directory management
    purge   => true, # purge all unmanaged junk
    force   => true, # also purge subdirs and links etc.
    owner   => "$userOwner",
    group   => "$userGroup",
    source  => "puppet:///modules/bugzilla/extensions/Mylyn",
    require => Exec["post extract bugzilla $bugzillaDir"],
  }

  file { "$base/$bugzillaDir/extensions/Mylyn/Extension.pm":
    content => template('bugzilla/Extension.pm.erb'),
    require => File["$base/$bugzillaDir/extensions/Mylyn"],
    owner   => "$userOwner",
    group   => "$userGroup",
    mode    => 0644,
  }

  exec { "init bugzilla_checksetup $bugzillaDir":
    command => "$base/$bugzillaDir/callchecksetup.pl",
    cwd     => "$base/$bugzillaDir",
    creates => "$base/$bugzillaDir/localconfig",
    user => "$userOwner",
    logoutput => true,
    require => [
      Exec["mysql-createdb-$bugzillaDir"],
      File["$base/$bugzillaDir/answers"],
      File["$base/$bugzillaDir/callchecksetup.pl"],
      File["$base/$bugzillaDir/extensions/Mylyn/Extension.pm"]]
  }

  exec { "update bugzilla_checksetup $bugzillaDir":
    command   => "$base/$bugzillaDir/callchecksetup.pl",
    cwd       => "$base/$bugzillaDir",
    logoutput => true,
    user => "$userOwner",
    require   => [
      Exec["mysql-createdb-$bugzillaDir"],
      Exec["init bugzilla_checksetup $bugzillaDir"],
      File["$base/$bugzillaDir/answers"],
      File["$base/$bugzillaDir/extensions/Mylyn/Extension.pm"],
      ]
  }

  if !$xmlrpc_enabled {
    file { "$base/$bugzillaDir/xmlrpc.cgi":
      content => template('bugzilla/xmlrpc.cgi.erb'),
      owner   => "$userOwner",
      group   => "$userGroup",
      mode    => 755,
      require => Exec["update bugzilla_checksetup $bugzillaDir"],
    }
  }

  file { "$base/$bugzillaDir/service.json":
    content => template('bugzilla/service.json.erb'),
    owner   => "$userOwner",
    group   => "$userGroup",
    mode    => 644,
    require =>  Exec["update bugzilla_checksetup $bugzillaDir"],
  }

  file { "$confDir/$bugzillaDir.conf":
    content => template('bugzilla/apache2.conf.erb'),
    require => [Package["apache2"], Exec["update bugzilla_checksetup $bugzillaDir"]],
    notify  => Service["apache2"],
  }

  exec { "add $bugzillaDir to /etc/apache2/conf-enabled/bugzilla.conf":
    command => "echo 'Include $base/conf.d/[^.#]*\n' >> /etc/apache2/conf-enabled/bugzilla.conf",
    require => File["$confDir/$bugzillaDir.conf"],
    notify  => Service["apache2"],
    onlyif  => "grep -qe '^Include $base/conf.d' /etc/apache2/conf-enabled/bugzilla.conf; test $? != 0"
  }

}

Back to the top