projektbauer 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +118 -0
- data/lib/projektbauer.rb +466 -0
- data/lib/projektbauer/erb/index_html.erb +6 -0
- data/lib/projektbauer/erb/post-commit.erb +24 -0
- data/lib/projektbauer/erb/project_location_httpd_conf.erb +31 -0
- data/lib/projektbauer/erb/svn_authz_file.erb +15 -0
- data/lib/projektbauer/erb/trac.ini.erb +258 -0
- data/lib/projektbauer/erb/virtual_host_httpd_conf.erb +27 -0
- data/lib/projektbauer/version.rb +3 -0
- data/projektbauer.gemspec +30 -0
- data/rakefile.rb +22 -0
- data/spec/reference/domain_01/include_locations.httpd.conf +2 -0
- data/spec/reference/domain_01/project_01/Feldbauer-environment.htdigest +8 -0
- data/spec/reference/domain_01/project_01/Feldbauer-environment.htdigest.txt +11 -0
- data/spec/reference/domain_01/project_01/project_01.dav_svn_authz +15 -0
- data/spec/reference/domain_01/project_01/project_01.httpd.conf +31 -0
- data/spec/reference/domain_01/project_02/Feldbauer-environment.htdigest +7 -0
- data/spec/reference/domain_01/project_02/Feldbauer-environment.htdigest.txt +9 -0
- data/spec/reference/domain_01/project_02/project_02.dav_svn_authz +15 -0
- data/spec/reference/domain_01/project_02/project_02.httpd.conf +31 -0
- data/spec/reference/domain_01/virtual_host.httpd.conf +43 -0
- data/spec/reference/domain_01/www/index.html +6 -0
- data/spec/reference/domain_02/include_locations.httpd.conf +1 -0
- data/spec/reference/domain_02/project_01/Feldbauer-environment.htdigest +7 -0
- data/spec/reference/domain_02/project_01/Feldbauer-environment.htdigest.txt +9 -0
- data/spec/reference/domain_02/project_01/project_01.dav_svn_authz +15 -0
- data/spec/reference/domain_02/project_01/project_01.httpd.conf +31 -0
- data/spec/reference/domain_02/virtual_host.httpd.conf +43 -0
- data/spec/reference/domain_02/www/index.html +6 -0
- data/spec/reference/include_virtual_hosts.httpd.conf +4 -0
- data/spec/reference/space domain 02/include_locations.httpd.conf +1 -0
- data/spec/reference/space domain 02/space project 01/Feldbauer-environment.htdigest +7 -0
- data/spec/reference/space domain 02/space project 01/Feldbauer-environment.htdigest.txt +9 -0
- data/spec/reference/space domain 02/space project 01/space project 01.dav_svn_authz +15 -0
- data/spec/reference/space domain 02/space project 01/space project 01.httpd.conf +31 -0
- data/spec/reference/space domain 02/virtual_host.httpd.conf +43 -0
- data/spec/reference/space domain 02/www/index.html +6 -0
- data/spec/setup_project_spec.rb +88 -0
- data/testresults/test_results.html +308 -0
- data/weichel21_projekbauer.rb +28 -0
- metadata +251 -0
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
spec/reference/**/svn
|
19
|
+
spec/reference/domain_01/project_01/svn
|
20
|
+
spec/tmp_output
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bernhard Weichel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# Projektbauer
|
2
|
+
|
3
|
+
Projektbauer (a german play on words which could be translated to
|
4
|
+
"project builder" or to "poject farmer") is a ruby gem which supports
|
5
|
+
the setup of an SVN/Trac environment in an apache enviroment.
|
6
|
+
|
7
|
+
To use it one creates a configuration file which is actually a ruby
|
8
|
+
script and executes the same. The following approach applies
|
9
|
+
|
10
|
+
- **top level project folder** all projects are kept under one
|
11
|
+
particular folder for a **project collection** Usually on one host,
|
12
|
+
there is exactly one project collection.
|
13
|
+
|
14
|
+
- **virtual host** acting as project set: Within the project
|
15
|
+
collection, multiple project sets can be installed. One project set
|
16
|
+
corelates to an apache virtual host (e.g `myprojects.mydomin.xx`).
|
17
|
+
**Projektbauer** creates an apache configuration file for this
|
18
|
+
virtual domain.
|
19
|
+
|
20
|
+
**Projektbauer** supports virtual host by
|
21
|
+
- creating a folder for the virtual host
|
22
|
+
- creating an apache configuration for that virtual host
|
23
|
+
(`virtual_host.httpd.conf`)
|
24
|
+
- maintains a configuration file (`include_locations.httpd.conf`)
|
25
|
+
which is be included in the aforehead mentioned file. This file
|
26
|
+
includes the project configurations.
|
27
|
+
|
28
|
+
**Note** that some providers (e.g. <http://www.webhostone.de>) do
|
29
|
+
not support creation of virtual hosts this way. In this case, you
|
30
|
+
can simply ignore the generated virtual host. But you need to
|
31
|
+
include the project list in the existing virtual host.
|
32
|
+
|
33
|
+
- **project** a project is associated with a **virtual host** such
|
34
|
+
that it can be accessed by
|
35
|
+
- `https://myprojects.mydomin.xx/myproject/svn`
|
36
|
+
- `https://myprojects.mydomin.xx/myproject/trac`
|
37
|
+
|
38
|
+
**Projektbauer** generates the configuration of the the project,
|
39
|
+
namely:
|
40
|
+
- svn repository
|
41
|
+
- htdigest user file
|
42
|
+
- svn_authz file
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
As of now **Projektbauer** is not released at <http://rubygems.org>. Therefore you need
|
47
|
+
to install it on your server by
|
48
|
+
|
49
|
+
$ git clone https://github.com/bwl21/projektbauer.git
|
50
|
+
|
51
|
+
Add this line to your application's Gemfile:
|
52
|
+
|
53
|
+
gem 'projektbauer'
|
54
|
+
|
55
|
+
And then execute:
|
56
|
+
|
57
|
+
$ bundle
|
58
|
+
|
59
|
+
Or install it yourself as:
|
60
|
+
|
61
|
+
$ gem install projektbauer
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
In order to use **Projektbauer** you need to create a configuration file
|
66
|
+
which is in fact a ruby program.
|
67
|
+
|
68
|
+
require './lib/projektbauer.rb'
|
69
|
+
|
70
|
+
p=Project.new
|
71
|
+
p.project_name = "{name of the project}"
|
72
|
+
p.project_users = {
|
73
|
+
admin: ["admin.first", "admin.second"],
|
74
|
+
observer: ["observer.first", "observer.second"],
|
75
|
+
contributor: ["contributor.first", "contributor.second"]
|
76
|
+
}
|
77
|
+
p.virtual_host = "{server internal folder name of the virtual host,}"
|
78
|
+
p.project_realm = "{realm for authorization, no spaces, no colons!}"
|
79
|
+
p.server_root = "{path to top level project folder on the server}"
|
80
|
+
p.virtual_host_ip = "{url of virtual host without port}"
|
81
|
+
p.server_name = "{domain of the virtual host}"
|
82
|
+
p.server_admin = "{email adress}"
|
83
|
+
p.server_port_nossl = 8080
|
84
|
+
p.server_port_ssl = 443
|
85
|
+
|
86
|
+
# this is required for the trac configuration
|
87
|
+
|
88
|
+
p.smtp_default_domain = "foo.bar.de" # Default dopmain for smtp
|
89
|
+
p.smtp_enabled = true # allow trac to send smtp
|
90
|
+
p.smtp_from = "projektbauer@foo.bar.de" # sender adress
|
91
|
+
p.smtp_from_author = false # not supported defaults to false
|
92
|
+
p.smtp_from_name = "Projekt bauer at foo bar de" # name of sender adress
|
93
|
+
p.smtp_user = "sample.user.smtp" # username for smtp
|
94
|
+
p.smtp_password = "sample.password.smtp" # password for smtp
|
95
|
+
p.smtp_port = 25 # port for smtp
|
96
|
+
p.smtp_replyto = "projetkbauer.trac.replyto@#{@p.server_name}" # reply-to adress
|
97
|
+
p.smtp_server = @p.server_name # smtp-server
|
98
|
+
p.smtp_subject_prefix = "__default__" # prefix for subject = __default__
|
99
|
+
|
100
|
+
|
101
|
+
p.create_all
|
102
|
+
|
103
|
+
For more details refer to the yard documentation included.
|
104
|
+
|
105
|
+
Note that you can run it repeatedly. Thereby
|
106
|
+
|
107
|
+
- new users are created
|
108
|
+
- old users are removed
|
109
|
+
|
110
|
+
you can see this in the project folder, in file `{project_realm}.htdigest.txt`
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
|
114
|
+
1. Fork it
|
115
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
116
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
117
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
118
|
+
5. Create new Pull Request
|
data/lib/projektbauer.rb
ADDED
@@ -0,0 +1,466 @@
|
|
1
|
+
#
|
2
|
+
# todo:
|
3
|
+
#
|
4
|
+
# add comments
|
5
|
+
# optimize file layout
|
6
|
+
# improve auth handling
|
7
|
+
# store auth-files in folder of virtual server
|
8
|
+
# cross use auth-files
|
9
|
+
# update htdigest files
|
10
|
+
# add rake tasks
|
11
|
+
# * add user
|
12
|
+
# * specifiy observer, contributors on config file
|
13
|
+
# * update trac permissions accordingly
|
14
|
+
#
|
15
|
+
# projektbauer init
|
16
|
+
# projektbuaer updateuser
|
17
|
+
# projektbauer add user
|
18
|
+
# ...
|
19
|
+
#
|
20
|
+
#
|
21
|
+
require 'fileutils'
|
22
|
+
require 'digest/md5'
|
23
|
+
require 'erb'
|
24
|
+
|
25
|
+
class Project
|
26
|
+
attr_accessor :output_folder, # output folder - currently not in use
|
27
|
+
:server_name, # server name of the virtual host <apache>
|
28
|
+
:server_root, # root folder on the server <apache>
|
29
|
+
:server_admin, # name of the server administrator <apache>
|
30
|
+
:document_root, # document root within the location <apache>
|
31
|
+
:project_name, # name of the project (please no spaces) \
|
32
|
+
# used for filename
|
33
|
+
:project_users, # hash of project users. Key is :admin, :observer, :contributor
|
34
|
+
:virtual_host, # domain of virtual host
|
35
|
+
:project_realm, # realm for the project authentification
|
36
|
+
:virtual_host_ip, # ip of the virtual host without port
|
37
|
+
:server_port_nossl, # port for the no ssl access of the virtual host (e.g. 8080)
|
38
|
+
:server_port_ssl, # port of ssel access to the virtual host (e.g. 443)
|
39
|
+
# used to find the right trac tools
|
40
|
+
:trac_admin, # allows the name of trac-admin (used for virtualenv)
|
41
|
+
|
42
|
+
### smtp configuration for trac
|
43
|
+
:smtp_default_domain, # Default dopmain for smtp
|
44
|
+
:smtp_enabled, # allow trac to send smtp
|
45
|
+
:smtp_from, # sender adress
|
46
|
+
:smtp_from_author, # not supported defaults to false
|
47
|
+
:smtp_from_name, # name of sender adress
|
48
|
+
:smtp_user, # username for smtp
|
49
|
+
:smtp_password, # password for smtp
|
50
|
+
:smtp_port, # port for smtp
|
51
|
+
:smtp_replyto, # reply-to adress
|
52
|
+
:smtp_server, # smtp-server
|
53
|
+
:smtp_subject_prefix # prefix for subject = __default__
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
#
|
58
|
+
# The class constructor
|
59
|
+
#
|
60
|
+
# @return [Project] returns the created class
|
61
|
+
def initialize
|
62
|
+
|
63
|
+
@server_port_nossl = nil
|
64
|
+
@server_port_ssl = nil
|
65
|
+
@server_root = "xxx"
|
66
|
+
|
67
|
+
|
68
|
+
@project_name = nil # name of project
|
69
|
+
@virtual_host = nil # set of the project
|
70
|
+
@project_realm = nil # realm for authorization
|
71
|
+
@project_admin_user = nil # admin - user
|
72
|
+
@server_admin = nil # email of server admin
|
73
|
+
@smtp_enabled = false # email is not supported by default
|
74
|
+
|
75
|
+
@trac_admin = "trac-admin" # the command to trac-admin
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
#
|
81
|
+
# Inititalizes filenames etc. Needs to be called
|
82
|
+
# whenever one or more of the attributes are changed.
|
83
|
+
#
|
84
|
+
# @return [nil] no return
|
85
|
+
def init_filenames
|
86
|
+
|
87
|
+
#todo add checks for the attributes
|
88
|
+
# no spaces in project_name
|
89
|
+
#
|
90
|
+
|
91
|
+
@_virtual_host_home_dir = "#{@server_root}/#{@virtual_host}"
|
92
|
+
@_include_virtual_hosts_httpd_conf = "#{@server_root}/include_virtual_hosts.httpd.conf"
|
93
|
+
@_project_home = "#{@_virtual_host_home_dir}/#{@project_name}"
|
94
|
+
@_virtual_host_httpd_conf = "#{@_virtual_host_home_dir}/virtual_host.httpd.conf"
|
95
|
+
@_virtual_host_locations_httpd_conf = "#{@_virtual_host_home_dir}/include_locations.httpd.conf"
|
96
|
+
@_project_location_httpd_conf = "#{@_project_home}/#{@project_name}.httpd.conf"
|
97
|
+
@_project_svn_dir = "#{@_project_home}/svn"
|
98
|
+
@_project_trac_dir = "#{@_project_home}/trac"
|
99
|
+
@_project_auth_user_file = "#{@_project_home}/#{@project_realm}.htdigest"
|
100
|
+
@_project_svn_authz_file = "#{@_project_home}/#{@project_name}.dav_svn_authz"
|
101
|
+
@_document_root_dir = "#{@_virtual_host_home_dir}/www"
|
102
|
+
@_index_html_file = "#{@_document_root_dir}/index.html"
|
103
|
+
@_trac_admin = "#{@trac_admin}"
|
104
|
+
@_trac_ini_file = "#{@_project_trac_dir}/conf/trac.ini"
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
#
|
111
|
+
# Creates the folders in the file system.
|
112
|
+
# If a folder already exists, nothing happens.
|
113
|
+
#
|
114
|
+
# @return [nil] no return
|
115
|
+
#
|
116
|
+
def create_folders
|
117
|
+
#todo: double check if path exists
|
118
|
+
FileUtils.mkdir_p @_project_svn_dir
|
119
|
+
FileUtils.mkdir_p @_project_trac_dir
|
120
|
+
FileUtils.mkdir_p @_document_root_dir
|
121
|
+
#todo: ensure that folders are not listable
|
122
|
+
#todo: htaccess - file
|
123
|
+
nil
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
#
|
129
|
+
# This basically creates the configuration of the virtual host
|
130
|
+
#
|
131
|
+
# @return [Nil] no return
|
132
|
+
#
|
133
|
+
def save_virtual_host_httpd_conf
|
134
|
+
config = expand_erb("virtual_host_httpd_conf.erb")
|
135
|
+
|
136
|
+
File.open(@_virtual_host_httpd_conf,"w"){|f|
|
137
|
+
f.puts config
|
138
|
+
}
|
139
|
+
|
140
|
+
nil
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
#
|
145
|
+
# create the apache configuration for the <location>
|
146
|
+
# It corresponds to a project.
|
147
|
+
#
|
148
|
+
# @return [Nil] no return
|
149
|
+
def save_project_location_httpd_conf
|
150
|
+
config = expand_erb("project_location_httpd_conf.erb")
|
151
|
+
|
152
|
+
File.open(@_project_location_httpd_conf,"w"){|f|
|
153
|
+
f.puts config
|
154
|
+
}
|
155
|
+
|
156
|
+
nil
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
#
|
161
|
+
# creates the Authorization file for svn.
|
162
|
+
# Thereby it creates an observer and a contributor group.
|
163
|
+
# the {Project.project_admin_user} is entered as contributor
|
164
|
+
#
|
165
|
+
# @return [Nil] no return
|
166
|
+
def create_svn_authz_file
|
167
|
+
config =expand_erb("svn_authz_file.erb")
|
168
|
+
|
169
|
+
File.open(@_project_svn_authz_file, "w") {|f|
|
170
|
+
f.puts config
|
171
|
+
}
|
172
|
+
nil
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
#
|
177
|
+
# Creates a minimalistic index.html in the virtual host.
|
178
|
+
# In particular this avoids that the files can be listed.
|
179
|
+
#
|
180
|
+
# @return [Nil] no return
|
181
|
+
#
|
182
|
+
def create_index_html
|
183
|
+
config = expand_erb("index_html.erb")
|
184
|
+
File.open(@_index_html_file, "w") {|f|
|
185
|
+
f.puts config
|
186
|
+
}
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
#
|
191
|
+
# Updates the include file with the locations.
|
192
|
+
# This file is subsequently included in the virtual hosts.
|
193
|
+
#
|
194
|
+
# Duplicate entries are removed.
|
195
|
+
#
|
196
|
+
# @return [Nil] no return
|
197
|
+
def update_virtual_host_locations_httpd_conf
|
198
|
+
_maintain_include_file(@_virtual_host_locations_httpd_conf,
|
199
|
+
@_project_location_httpd_conf
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
#
|
205
|
+
# Updates the include file with the virtual hosts.
|
206
|
+
# This file needs to be added manually to `/etc/apache2/apache2.conf`
|
207
|
+
#
|
208
|
+
# @return [Nil] no return
|
209
|
+
def update_include_virtual_hosts_httpd_conf
|
210
|
+
_maintain_include_file(@_include_virtual_hosts_httpd_conf,
|
211
|
+
@_project_location_httpd_conf
|
212
|
+
)
|
213
|
+
nil
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
#
|
219
|
+
# This creates the trac environment
|
220
|
+
#
|
221
|
+
# @return [type] [description]
|
222
|
+
def create_trac
|
223
|
+
quoted_project_trac_dir = "\"#{@_project_trac_dir}\""
|
224
|
+
|
225
|
+
unless File.exists?("#{@_project_trac_dir}/conf")
|
226
|
+
FileUtils.mkdir_p(@_project_trac_dir)
|
227
|
+
_trac_admin "#{quoted_project_trac_dir} initenv \"#{@project_name}\" sqlite:\"#{@_project_trac_dir}/db/trac.db\""
|
228
|
+
FileUtils.rm(@_trac_ini_file) # remove this such that it gets regenerated
|
229
|
+
end
|
230
|
+
|
231
|
+
_update_trac_ini
|
232
|
+
|
233
|
+
# create group for project.admins
|
234
|
+
_trac_admin "#{quoted_project_trac_dir} permission add project.admins TRAC_ADMIN TICKET_ADMIN WIKI_ADMIN"
|
235
|
+
|
236
|
+
|
237
|
+
@project_users[:admin].each{|u|
|
238
|
+
_trac_admin "#{quoted_project_trac_dir} permission add #{u} project.admins"
|
239
|
+
}
|
240
|
+
_trac_admin "#{quoted_project_trac_dir} permission add project.contributors TRAC_ADMIN TICKET_ADMIN WIKI_ADMIN"
|
241
|
+
anonymous_revoke="BROWSER_VIEW CHANGESET_VIEW FILE_VIEW LOG_VIEW MILESTONE_VIEW REPORT_SQL_VIEW"
|
242
|
+
anonymous_revoke <<" REPORT_VIEW ROADMAP_VIEW SEARCH_VIEW TICKET_VIEW TIMELINE_VIEW WIKI_VIEW"
|
243
|
+
|
244
|
+
_trac_admin "#{quoted_project_trac_dir} permission remove anonymous #{anonymous_revoke}"
|
245
|
+
_trac_admin "#{quoted_project_trac_dir} permission add authenticated #{anonymous_revoke}"
|
246
|
+
|
247
|
+
# crate include-file for webserver
|
248
|
+
#
|
249
|
+
_trac_admin "#{quoted_project_trac_dir} deploy #{quoted_project_trac_dir}"
|
250
|
+
|
251
|
+
cmd = "chmod +x #{@_project_trac_dir}/cgi-bin/*"
|
252
|
+
`#{cmd}`
|
253
|
+
# link to the svn repository
|
254
|
+
#
|
255
|
+
_trac_admin "#{quoted_project_trac_dir} repository add \"(default)\" \"#{@_project_svn_dir}\" svn"
|
256
|
+
|
257
|
+
_create_post_commit
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
#
|
262
|
+
# This creates the svn repository if it does not yet exist.
|
263
|
+
# Note that this is tested by investigating the format
|
264
|
+
# folder in the svn repository.
|
265
|
+
#
|
266
|
+
# todo: improve the detection
|
267
|
+
#
|
268
|
+
# @return [type] [description]
|
269
|
+
def create_svn
|
270
|
+
unless File.exists?(@_project_svn_dir + "/format")
|
271
|
+
cmd = "svnadmin create \"#{@_project_svn_dir}\""
|
272
|
+
puts cmd
|
273
|
+
`#{cmd}`
|
274
|
+
initialfolders= ["tags", "branches", "trunk"]
|
275
|
+
cmd = ["svn mkdir",
|
276
|
+
initialfolders.map{|d| "file://\"#{@_project_svn_dir}\"/#{d}"},
|
277
|
+
"-m \"Repository created by Projektbauer\""].flatten.join(" ")
|
278
|
+
puts cmd
|
279
|
+
`#{cmd}`
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
#
|
284
|
+
# This creates the htdigest file
|
285
|
+
#
|
286
|
+
# @return [Nil] no return
|
287
|
+
def create_htpasswd
|
288
|
+
|
289
|
+
allusers = @project_users.map{|k,v| v}.flatten
|
290
|
+
pwdhashes = {}
|
291
|
+
passwords = {}
|
292
|
+
allusers.each{|user|
|
293
|
+
password = (0...10).map{ ('a'..'z').to_a[rand(26)] }.join
|
294
|
+
pwdhashes[user] = _create_passwdentry(@project_realm, user, password)
|
295
|
+
passwords[user] = password
|
296
|
+
}
|
297
|
+
|
298
|
+
if File.exists?(@_project_auth_user_file) then
|
299
|
+
oldcontents = File.open(@_project_auth_user_file).readlines
|
300
|
+
oldcontents = oldcontents.map{|i| i.strip }.sort.uniq
|
301
|
+
|
302
|
+
oldentries={}
|
303
|
+
oldcontents.each{|entry|
|
304
|
+
|
305
|
+
record = entry.split(":")
|
306
|
+
if pwdhashes.has_key?(record.first) then
|
307
|
+
pwdhashes[record.first] = entry
|
308
|
+
passwords[record.first] = "<password unchanged>"
|
309
|
+
else
|
310
|
+
passwords[record.first] = "<user deleted>"
|
311
|
+
end
|
312
|
+
}
|
313
|
+
else
|
314
|
+
oldcontents=[]
|
315
|
+
end
|
316
|
+
|
317
|
+
newcontents=pwdhashes.map{|k,v| v }.sort.uniq
|
318
|
+
unless oldcontents==newcontents
|
319
|
+
File.open(@_project_auth_user_file, "w"){|f|
|
320
|
+
f.puts(newcontents.join("\n"))
|
321
|
+
}
|
322
|
+
end
|
323
|
+
|
324
|
+
File.open(@_project_auth_user_file+".txt", "a"){|f|
|
325
|
+
f.puts "generated passwords for #{@project_realm}"
|
326
|
+
f.puts ""
|
327
|
+
f.puts(passwords.map{|k,v| "#{k} => #{v}"}.sort.join("\n"))
|
328
|
+
}
|
329
|
+
|
330
|
+
end
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
#
|
335
|
+
# calling this method after setting all attributes
|
336
|
+
# does the entire generation job
|
337
|
+
#
|
338
|
+
# @return [Nil] no return
|
339
|
+
def create_all
|
340
|
+
init_filenames
|
341
|
+
create_folders
|
342
|
+
|
343
|
+
create_index_html
|
344
|
+
|
345
|
+
save_virtual_host_httpd_conf
|
346
|
+
save_project_location_httpd_conf
|
347
|
+
update_virtual_host_locations_httpd_conf
|
348
|
+
update_include_virtual_hosts_httpd_conf
|
349
|
+
|
350
|
+
create_htpasswd
|
351
|
+
create_svn_authz_file
|
352
|
+
create_svn
|
353
|
+
|
354
|
+
create_trac
|
355
|
+
end
|
356
|
+
|
357
|
+
|
358
|
+
private
|
359
|
+
|
360
|
+
|
361
|
+
#
|
362
|
+
# This expands the embedded ruby templated
|
363
|
+
# @param file [String] Path to the erb template
|
364
|
+
#
|
365
|
+
# @return [String] Expanded Templated
|
366
|
+
def expand_erb(file)
|
367
|
+
template=ERB.new File.new(File.dirname(__FILE__)+ "/projektbauer/erb/" + file).readlines.join
|
368
|
+
template.result(binding)
|
369
|
+
end
|
370
|
+
|
371
|
+
|
372
|
+
#
|
373
|
+
# This maintains an include file as follows:
|
374
|
+
#
|
375
|
+
# - the file is read
|
376
|
+
# - the new entry is appended
|
377
|
+
# - the result is sorted an duplicates are removed
|
378
|
+
# - the file is saved if it is different than before
|
379
|
+
#
|
380
|
+
# @param include_file [String] Name if the include file to be maintained
|
381
|
+
# @param entry [String] The new entry which shall be included
|
382
|
+
#
|
383
|
+
# @return [Nil] no return
|
384
|
+
#
|
385
|
+
def _maintain_include_file(include_file, entry)
|
386
|
+
if File.exists?(include_file) then
|
387
|
+
old = File.open(include_file).readlines.map{|i| i.strip}
|
388
|
+
new=old.clone
|
389
|
+
else
|
390
|
+
new=[]
|
391
|
+
end
|
392
|
+
|
393
|
+
new << "Include #{entry}"
|
394
|
+
|
395
|
+
new=new.sort.uniq
|
396
|
+
|
397
|
+
unless old == new then
|
398
|
+
File.open(include_file, "w") {|f|
|
399
|
+
f.puts new.join("\n")
|
400
|
+
}
|
401
|
+
end
|
402
|
+
nil
|
403
|
+
end
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
#
|
408
|
+
# This creates the post commit hook file
|
409
|
+
#
|
410
|
+
# @param file [type] [description]
|
411
|
+
#
|
412
|
+
# @return [type] [description]
|
413
|
+
def _create_post_commit()
|
414
|
+
post_commit_file="#{@_project_svn_dir}/hooks/post-commit"
|
415
|
+
trac_ini = expand_erb("post-commit.erb")
|
416
|
+
File.open(post_commit_file, "w") {|f|
|
417
|
+
f.puts trac_ini
|
418
|
+
}
|
419
|
+
cmd="chmod +x \"#{post_commit_file}\""
|
420
|
+
#{cmd}`
|
421
|
+
end
|
422
|
+
|
423
|
+
|
424
|
+
#
|
425
|
+
# This updates (actually rewrites) trac.ini
|
426
|
+
#
|
427
|
+
# @return [Nil]
|
428
|
+
def _update_trac_ini()
|
429
|
+
trac_ini = expand_erb("trac.ini.erb")
|
430
|
+
unless File.exists?(@_trac_ini_file)
|
431
|
+
File.open(@_trac_ini_file, "w") {|f|
|
432
|
+
f.puts trac_ini
|
433
|
+
}
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
#
|
440
|
+
# Creates on e particular password entry
|
441
|
+
#
|
442
|
+
# @param realm [String] Realm for the password
|
443
|
+
# @param user [String] username
|
444
|
+
# @param password [String] password
|
445
|
+
#
|
446
|
+
# @return [type] [description]
|
447
|
+
def _create_passwdentry(realm, user, password)
|
448
|
+
pwdhash=Digest::MD5.hexdigest("#{user}:#{realm}:#{password}")
|
449
|
+
result="#{user}:#{realm}:#{pwdhash}"
|
450
|
+
result
|
451
|
+
end
|
452
|
+
|
453
|
+
|
454
|
+
#
|
455
|
+
# This performs tracadmin commands
|
456
|
+
# @param cmd [STring] the arguments to trac-admin
|
457
|
+
#
|
458
|
+
# @return [String] [description]
|
459
|
+
def _trac_admin(command)
|
460
|
+
|
461
|
+
cmd= "#{@trac_admin} #{command}"
|
462
|
+
puts cmd
|
463
|
+
`#{cmd}`
|
464
|
+
end
|
465
|
+
|
466
|
+
end
|