ktec-subtrac 0.1.23 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 23
4
+ :patch: 24
data/bin/subtrac CHANGED
@@ -16,7 +16,7 @@ command :install do |c|
16
16
  c.description = 'Installation of default files required to host multipe development projects.'
17
17
  c.example 'description', 'installs the default trac and svn setup'
18
18
  c.option '-c','--clean', 'Performs a clean install'
19
- c.option '-d','--accept-defaults DEFAULTS', 'Accept all defaults'
19
+ c.option '-d','--defaults', 'Accept all defaults'
20
20
  c.when_called Subtrac::Commands::Install
21
21
  end
22
22
 
data/lib/subtrac.rb CHANGED
@@ -50,85 +50,130 @@ module Subtrac
50
50
 
51
51
  class << self
52
52
 
53
- # The Configuration instance used to configure the Subtrac environment
54
- def configuration
55
- @@configuration
56
- end
53
+ # Filesystem directories
57
54
 
58
- def configuration=(configuration)
59
- @@configuration = configuration
55
+ def root
56
+ Pathname.new(SUBTRAC_ROOT) if defined?(SUBTRAC_ROOT)
60
57
  end
61
58
 
62
- def initialized?
63
- @initialized || false
59
+ def public_path
60
+ @public_path ||= self.root ? File.join(self.root, "public") : "public"
64
61
  end
65
-
66
- def initialized=(initialized)
67
- @initialized ||= initialized
62
+
63
+ def public_path=(path)
64
+ @public_path = path
68
65
  end
69
66
 
70
- def root
71
- Pathname.new(SUBTRAC_ROOT) if defined?(SUBTRAC_ROOT)
67
+ def subtrac_path
68
+ @subtrac_path ||= self.root ? File.join(self.root, "subtrac") : "subtrac"
72
69
  end
73
70
 
74
- def public_path
75
- @@public_path ||= self.root ? File.join(self.root, "public") : "public"
71
+ def install_dir
72
+ @install_dir ||= File.expand_path(@APP_CONFIG[:installation_dir])
73
+ end
74
+
75
+ def install_dir=(name)
76
+ puts "Setting new install_dir variable to #{name}"
77
+ @install_dir = name
76
78
  end
77
79
 
78
- def subtrac_path
79
- @@subtrac_path ||= self.root ? File.join(self.root, "subtrac") : "subtrac"
80
+ def apache_conf_dir
81
+ @apache_conf_dir ||= @APP_CONFIG[:apache_conf_dir]
80
82
  end
81
83
 
82
- def public_path=(path)
83
- @@public_path = path
84
+ def apache_conf_dir=(name)
85
+ @APP_CONFIG[:apache_conf_dir] = @@apache_conf_dir = name
84
86
  end
85
87
 
86
88
  def docs_dir
87
- @@docs_dir ||= File.join(@install_dir,@APP_CONFIG[:dirs][:docs])
89
+ @docs_dir ||= File.join(install_dir,@APP_CONFIG[:dirs][:docs])
88
90
  end
89
91
 
90
- def docs_dir=(dir)
91
- @@docs_dir = dir
92
+ def svn_dir
93
+ @svn_dir ||= File.join(install_dir,@APP_CONFIG[:dirs][:svn])
92
94
  end
93
95
 
94
- def svn_dir
95
- @@svn_dir ||= File.join(@install_dir,@APP_CONFIG[:dirs][:svn])
96
+ def trac_dir
97
+ @trac_dir ||= File.join(install_dir,@APP_CONFIG[:dirs][:trac])
96
98
  end
97
99
 
98
- def svn_dir=(dir)
99
- @@svn_dir = dir
100
+ def temp_dir
101
+ @temp_dir ||= File.join(install_dir,@APP_CONFIG[:dirs][:temp])
100
102
  end
101
103
 
102
- def trac_dir
103
- @@trac_dir ||= File.join(@install_dir,@APP_CONFIG[:dirs][:trac])
104
+ def log_dir
105
+ @log_dir ||= File.join(install_dir,@APP_CONFIG[:dirs][:log])
104
106
  end
105
107
 
106
- def trac_dir=(dir)
107
- @@trac_dir = dir
108
+ def locations_dir
109
+ @locations_dir ||= File.join(install_dir,@APP_CONFIG[:dirs][:locations])
108
110
  end
109
111
 
110
- def temp_dir
111
- @@temp_dir ||= File.join(@install_dir,@APP_CONFIG[:dirs][:temp])
112
+ def server_name
113
+ @server_name ||= @APP_CONFIG[:server_name]
112
114
  end
113
115
 
114
- def temp_dir=(dir)
115
- @@temp_dir = dir
116
+ def server_name=(name)
117
+ @APP_CONFIG[:server_name] = @@server_name = name
116
118
  end
117
119
 
118
- def log_dir
119
- @@log_dir ||= File.join(@install_dir,@APP_CONFIG[:dirs][:log])
120
+ def server_hostname
121
+ @server_hostname ||= @APP_CONFIG[:server_hostname]
120
122
  end
121
123
 
122
- def log_dir=(dir)
123
- @@log_dir = dir
124
+ def server_hostname=(name)
125
+ @APP_CONFIG[:server_hostname] = @@server_hostname = name
124
126
  end
125
127
 
126
- def locations_dir
127
- @@locations_dir ||= File.join(@install_dir,@APP_CONFIG[:dirs][:locations])
128
+ def default_client
129
+ @default_client ||= @APP_CONFIG[:default_client]
130
+ end
131
+
132
+ def default_client=(name)
133
+ @APP_CONFIG[:default_client] = @@default_client = name
134
+ end
135
+
136
+ def default_project
137
+ @default_project ||= @APP_CONFIG[:default_project]
138
+ end
139
+
140
+ def default_project=(name)
141
+ puts "Updating default_project to #{name}"
142
+ @APP_CONFIG[:default_project] = @@default_project = name
143
+ end
144
+
145
+ # LDAP
146
+
147
+ def enable_ldap
148
+ @enable_ldap ||= @APP_CONFIG[:ldap][:enable]
128
149
  end
129
150
 
130
- def locations_dir=(dir)
131
- @@locations_dir = dir
151
+ def enable_ldap=(value)
152
+ @APP_CONFIG[:ldap][:enable] = @@enable_ldap = value
153
+ end
154
+
155
+ def ldap_bind_dn
156
+ @ldap_bind_dn ||= @APP_CONFIG[:ldap][:bind_dn]
157
+ end
158
+
159
+ def ldap_bind_dn=(value)
160
+ @APP_CONFIG[:ldap][:bind_dn] = @@ldap_bind_dn = value
161
+ end
162
+
163
+ def ldap_bind_password
164
+ @ldap_bind_password ||= @APP_CONFIG[:ldap][:bind_password]
165
+ end
166
+
167
+ def ldap_bind_password=(value)
168
+ @APP_CONFIG[:ldap][:bind_password] = @@ldap_bind_password = value
169
+ end
170
+
171
+ def ldap_bind_host
172
+ @ldap_bind_host ||= @APP_CONFIG[:ldap][:bind_host]
173
+ end
174
+
175
+ def ldap_bind_host=(value)
176
+ @APP_CONFIG[:ldap][:bind_host] = @@ldap_bind_password = value
132
177
  end
133
178
 
134
179
  end
@@ -142,8 +187,7 @@ module Subtrac
142
187
  file_path = File.join(subtrac_path,"/config/config.yml") if not File.exists?(file_path)
143
188
  puts "Attempting to read config file: #{file_path}"
144
189
  begin
145
- raw_config = File.read(file_path)
146
- yamlFile = YAML.load(raw_config)
190
+ yamlFile = YAML.load(File.read(file_path))
147
191
  rescue Exception => e
148
192
  raise StandardError, "Config #{file_path} could not be loaded."
149
193
  end
@@ -156,100 +200,78 @@ module Subtrac
156
200
  else
157
201
  raise StandardError, "config/config.yml does not exist."
158
202
  end
159
- puts "\n==== Installation options ===="
160
-
161
- say("Setting up default configuration...")
162
- @server_name = @APP_CONFIG[:server_name]
163
- @server_hostname = @APP_CONFIG[:server_hostname]
164
- @server_ip = @APP_CONFIG[:server_ip]
165
-
166
- @default_client = @APP_CONFIG[:default_client]
167
- @default_project = @APP_CONFIG[:default_project]
168
-
169
- @install_dir = File.expand_path(@APP_CONFIG[:installation_dir])
170
- @conf_dir = @APP_CONFIG[:apache2_conf]
171
-
172
- @ldap_enable = @APP_CONFIG[:ldap][:enable]
173
- if (@ldap_enable) then
174
- @ldap_bind_dn = @APP_CONFIG[:ldap][:bind_dn]
175
- @ldap_bind_password = @APP_CONFIG[:ldap][:bind_password]
176
- @ldap_url = @APP_CONFIG[:ldap][:host]
177
- end
178
-
203
+ say("Configuration loaded successfully...")
179
204
  end
180
205
 
181
206
 
182
207
  # Install
183
208
  def self.install(args,options)
184
209
  puts "\n==== Installing development server files ===="
210
+
185
211
  if options.defaults then
186
- create_environment_directories(options.clean)
187
- install_common_files()
188
- install_default_theme()
189
- configure_admin_user()
190
- create_virtual_host()
191
- # create default project and client
192
- create_project(@default_project,@default_client)
193
- save_config()
212
+ overwrite = options.clean
213
+ confirm_default_client = true
194
214
  else
195
215
  # check where we are installing
196
- change_install_dir = agree("The default installation directory is \"#{@install_dir}\". Would you like to change this? [Y/n]")
197
- @install_dir = ask("Where would you like to install this server?") if change_install_dir
198
-
199
- unless !File.directory?(@install_dir)
216
+ confirm_or_replace_value(:install_dir,"install_dir")
217
+
218
+ unless !File.directory?(install_dir)
200
219
  # Ask if the user agrees (yes or no)
201
220
  confirm_clean = agree("Err, it seems there's some stuff in there. You sure you want me to overwrite? [Y/n]") if options.clean
202
- confirm_clean = agree("Doubly sure? I can't undo this....[Y/n]") if confirm_clean
221
+ overwrite = agree("Doubly sure? I can't undo this....[Y/n]") if confirm_clean
203
222
  end
204
223
 
205
- # right lets install
206
- change_server_name = agree("The default server name is \"#{@server_name}\". Would you like to change this? [Y/n]")
207
- @server_name = ask("What would you like to call your new development server? ") if change_server_name
224
+ # confirm server
225
+ confirm_or_replace_value(:server_name,"server_name")
208
226
 
209
227
  # ask for hostname
210
- change_server_hostname = agree("The default server hostname is \"#{@server_hostname}\". Would you like to change this? [Y/n]")
211
- @server_hostname = ask("What url will your new server use? ") if change_server_hostname
212
-
213
- create_environment_directories(confirm_clean)
214
- confirm_default_client = agree("Do you want to create a default client project? [Y/n]")
215
- # create default project and client
216
- if confirm_default_client
217
- change_client = agree("The default client name is \"#{@default_client}\". Would you like to change this? [Y/n]")
218
- @default_client = ask("What client name would you like to use? ") if change_client
219
- change_project = agree("The default project name is \"#{@default_project}\". Would you like to change this? [Y/n]")
220
- @default_project = ask("What would you like to call your new project? ") if change_project
221
- create_project(@default_project,@default_client)
222
- end
223
- install_common_files()
224
- install_default_theme()
225
- configure_admin_user()
226
- # TODO: Need to check for default client/project before creating virtual host
227
- # otherwise we need remove the rewrite rule
228
- create_virtual_host()
229
- save_config()
228
+ confirm_or_replace_value(:server_hostname,"server_hostname")
229
+
230
+ # default client/project name
231
+ confirm_or_replace_value(:default_client,"default_client")
232
+ confirm_or_replace_value(:default_project,"default_project")
233
+
230
234
  end
235
+
236
+ say("Ok we're about to install now, these are the options you have chosen:
237
+ installation directory: #{install_dir}
238
+ overwrite: #{overwrite}
239
+ server name: #{server_name}
240
+ server hostname: #{server_hostname}
241
+ default client: #{default_client}
242
+ default project: #{default_project}")
243
+
244
+ confirm = agree("Is this ok? [y/n]")
245
+
246
+ exit 0 if !confirm
247
+
248
+ create_environment_directories(overwrite)
249
+ create_virtual_host()
250
+ install_common_files()
251
+ install_default_theme()
252
+ configure_admin_user()
253
+ create_project(default_project,default_client)
254
+ save_config()
231
255
 
232
256
  end
233
257
 
234
258
  private
235
259
 
260
+ # confirms the current value with the user or accepts a new value if required
261
+ def self.confirm_or_replace_value(prop, name)
262
+ method(prop).call # initialise the property
263
+ current_value = instance_variable_get("@#{prop}")
264
+ accept_default = agree("The default value for #{prop} is \"#{current_value}\". Is this ok? [y/n]")
265
+ if !accept_default then
266
+ answer = ask("What would you like to change it to?")
267
+ send("#{prop}=", answer)
268
+ #instance_variable_set(prop, answer)
269
+ end
270
+ end
271
+
236
272
  # Write the changes configuration to disk
237
273
  def self.save_config
238
- # save the things that might have changed
239
- @APP_CONFIG[:server_name] = @server_name
240
- @APP_CONFIG[:server_hostname] = @server_hostname
241
- @APP_CONFIG[:server_ip] = @server_ip
242
-
243
- @APP_CONFIG[:default_client] = @default_client
244
- @APP_CONFIG[:default_project] = @default_project
245
-
246
- @APP_CONFIG[:installation_dir] = @install_dir
247
- @APP_CONFIG[:apache2_conf] = @conf_dir
248
-
249
- @APP_CONFIG[:ldap][:bind_dn] = @ldap_bind_dn
250
- @APP_CONFIG[:ldap][:bind_password] = @ldap_bind_password
251
- @APP_CONFIG[:ldap][:host] = @ldap_url
252
-
274
+ # save the things that might have changed
253
275
  file_path = File.join(subtrac_path, USER_CONFIG)
254
276
  open(file_path, 'w') {|f| YAML.dump({SUBTRAC_ENV => @APP_CONFIG}, f)}
255
277
  end
@@ -281,17 +303,17 @@ module Subtrac
281
303
 
282
304
  # creates a new virtual host and reloads apache and enables the new virtual host
283
305
  def self.create_virtual_host
284
- # TODO: Need to check for default client/project before creating virtual host
285
- # otherwise we need remove the rewrite rule
286
306
  puts "\n==== Creating new virtual host ===="
287
307
  vhost_template = File.join(subtrac_path, @APP_CONFIG[:templates][:virtual_host])
288
- puts "group apache tempalte: #{vhost_template}"
289
- new_vhost = File.join(@conf_dir,@server_hostname)
308
+ puts "group apache virtual host template: #{vhost_template}"
309
+ # TODO: Copy this to the conf folder and map a file with an Include to it.
310
+ # this way the vhost file will get backed up as well.
311
+ new_vhost = File.join(apache_conf_dir,server_hostname)
290
312
  puts "group apache file: #{new_vhost}"
291
313
  parse_template(vhost_template,new_vhost,binding) if SUBTRAC_ENV != 'test'
292
314
  # reload apache configuration
293
315
  `/etc/init.d/apache2 force-reload` if SUBTRAC_ENV != 'test'
294
- `a2ensite #{@server_hostname}` if SUBTRAC_ENV != 'test'
316
+ `a2ensite #{server_hostname}` if SUBTRAC_ENV != 'test'
295
317
  end
296
318
 
297
319
  def self.install_common_files
@@ -300,14 +322,12 @@ module Subtrac
300
322
  # TODO: refactor /common to the app config
301
323
  FileUtils.cp_r(Dir.glob(File.join(subtrac_path, "common/.")),docs_dir)
302
324
  FileUtils.cp_r(Dir.glob(File.join(subtrac_path, "shared/.")),create_if_missing(File.join(trac_dir, ".shared")))
303
- # this need to be replaced with a question/answer session
304
- #FileUtils.cp(,@install_dir)
305
325
  end
306
326
 
307
327
  def self.configure_admin_user
308
328
  puts "\n==== Configure admin user ===="
309
329
  # create admin user
310
- passwd_file = File.join(@install_dir, ".passwd")
330
+ passwd_file = File.join(install_dir, ".passwd")
311
331
  admin_user = ask("New admin user: ") { |q| q.echo = true }
312
332
  admin_pass = ask("New password: ") { |q| q.echo = "*" }
313
333
  admin_pass_confirm = ask("Re-type new password: ") { |q| q.echo = "*" }
@@ -324,11 +344,11 @@ module Subtrac
324
344
 
325
345
  def self.create_environment_directories(overwrite=false)
326
346
  puts "\n==== Creating new environment directories ===="
327
- FileUtils.rm_rf @install_dir if overwrite
328
- create_if_missing @install_dir
347
+ FileUtils.rm_rf install_dir if overwrite
348
+ create_if_missing install_dir
329
349
  # create the environment directories
330
350
  @APP_CONFIG[:dirs].each do |key, value|
331
- dir = File.join(@install_dir,value)
351
+ dir = File.join(install_dir,value)
332
352
  create_if_missing dir
333
353
  end
334
354
  end
@@ -365,8 +385,9 @@ module Subtrac
365
385
 
366
386
  #`sudo svn co --username #{@APP_CONFIG[:admin_user]} --password #{@APP_CONFIG[:admin_pass]} \
367
387
  # file://#{svn_dir}/#{client_name}/trac_theme/trunk #{client_theme_dir}` if SUBTRAC_ENV != 'test'
388
+ # TODO: Need to find a way to test before trying
368
389
  template_dir = File.join(subtrac_path, "templates","trac","themes","subtractheme")
369
- `sudo easy_install #{template_dir}`
390
+ say(`sudo easy_install #{template_dir}`)
370
391
  end
371
392
 
372
393
  def self.create_project(project, client, project_type=@APP_CONFIG[:default_project_template])
@@ -412,7 +433,7 @@ module Subtrac
412
433
  # create a new trac site
413
434
  say("Creating a new trac site...")
414
435
  result = `trac-admin #{project_trac_dir} initenv #{project_name} sqlite:#{project_trac_dir}/db/trac.db svn #{project_svn_dir}` if SUBTRAC_ENV != 'test'
415
- FileUtils.chown_R('www-data', 'www-data', project_trac_dir, :verbose => true) if SUBTRAC_ENV != 'test'
436
+ FileUtils.chown_R('www-data', 'www-data', project_trac_dir, :verbose => false) if SUBTRAC_ENV != 'test'
416
437
  FileUtils.mkdir_p("#{project_trac_dir}/conf") if SUBTRAC_ENV == 'test' # fake the folder for tests
417
438
 
418
439
  say("Installing trac configuration...")
@@ -443,7 +464,8 @@ module Subtrac
443
464
  end
444
465
 
445
466
  # chown the whole directory
446
- FileUtils.chown_R('www-data', 'www-data', File.join(@install_dir,"*"), :verbose => true) if SUBTRAC_ENV != 'test'
467
+ `sudo chown -R www-data:www-data #{install_dir}`
468
+ #FileUtils.chown_R('www-data', 'www-data', File.join(install_dir,"*"), :verbose => true) if SUBTRAC_ENV != 'test'
447
469
 
448
470
  # run trac upgrade
449
471
  say("Upgrading the trac installation...")
@@ -3,7 +3,6 @@ development: &non_production_settings
3
3
  :admin_user: "admin"
4
4
  :server_name: "Subtrac Development Server"
5
5
  :server_hostname: "dev.subtrac.com"
6
- :server_ip: "192.168.2.1"
7
6
 
8
7
  :installation_dir: test
9
8
 
@@ -13,7 +12,7 @@ development: &non_production_settings
13
12
  :default_project: "Public"
14
13
  :shared_trac_ini: "shared/trac.ini"
15
14
 
16
- :apache2_conf: /etc/apache2/sites-available
15
+ :apache_conf_dir: /etc/apache2/sites-available
17
16
 
18
17
  :ldap:
19
18
  :enable: false
@@ -13,7 +13,7 @@ This is the home of development for <%= client %>. This page is editable by desi
13
13
  Make sure you have subversion client installed, then you can check the project out using:
14
14
 
15
15
  {{{
16
- svn checkout http://<%= @server_hostname %><%= @APP_CONFIG[:urls][:svn] %>/<%= client_name %>/<%= project_name %>/trunk <%= project_name %>
16
+ svn checkout http://<%= server_hostname %><%= @APP_CONFIG[:urls][:svn] %>/<%= client_name %>/<%= project_name %>/trunk <%= project_name %>
17
17
  }}}
18
18
 
19
19
  === Using SVN ===
@@ -1,26 +1,26 @@
1
1
  <virtualhost *>
2
2
  ServerAdmin webmaster@localhost
3
- ServerName <%= @server_hostname %>
3
+ ServerName <%= server_hostname %>
4
4
  DocumentRoot <%= docs_dir %>
5
- ErrorLog <%= log_dir %>/error.<%= @server_hostname %>.log
6
- CustomLog <%= log_dir %>/access.<%= @server_hostname %>.log combined
5
+ ErrorLog <%= log_dir %>/error.<%= server_hostname %>.log
6
+ CustomLog <%= log_dir %>/access.<%= server_hostname %>.log combined
7
7
  LogLevel error
8
8
 
9
9
  RewriteEngine On
10
- RewriteRule ^/$ http://<%= @server_hostname %>/<%= @default_client.downcase %>/<%= @default_project.downcase %>
11
- RewriteRule ^/index*$ http://<%= @server_hostname %>/<%= @default_client.downcase %>/<%= @default_project.downcase %>
10
+ RewriteRule ^/$ http://<%= server_hostname %>/<%= default_client.downcase %>/<%= default_project.downcase %>
11
+ RewriteRule ^/index*$ http://<%= server_hostname %>/<%= default_client.downcase %>/<%= default_project.downcase %>
12
12
 
13
13
  <location />
14
14
  AuthType Basic
15
- AuthName '<%= @server_name %>'
16
- AuthUserFile <%= @install_dir %>/.passwd
15
+ AuthName '<%= server_name %>'
16
+ AuthUserFile <%= install_dir %>/.passwd
17
17
  Require valid-user
18
18
  AuthBasicProvider file
19
- <% if @ldap_enable then %>
19
+ <% if enable_ldap then %>
20
20
  #AuthBasicProvider file ldap
21
- #AuthLDAPBindDN '<%= @ldap_bind_dn %>'
22
- #AuthLDAPBindPassword '<%= @ldap_bind_password %>'
23
- #AuthLDAPURL '<%= @ldap_url %>'
21
+ #AuthLDAPBindDN '<%= ldap_bind_dn %>'
22
+ #AuthLDAPBindPassword '<%= ldap_bind_password %>'
23
+ #AuthLDAPURL '<%= ldap_url %>'
24
24
  #AuthzLDAPAuthoritative off
25
25
  <% end %>
26
26
  </location>
@@ -30,7 +30,7 @@
30
30
  SVNParentPath <%= @APP_CONFIG[:dirs][:svn] %>/
31
31
  SVNListParentPath On
32
32
  SVNAutoversioning On
33
- SVNReposName '<%= @server_name %>'
33
+ SVNReposName '<%= server_name %>'
34
34
  </location>
35
35
 
36
36
  Include <%= locations_dir %>/*
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ktec-subtrac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Salisbury
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-22 00:00:00 -07:00
12
+ date: 2009-04-23 00:00:00 -07:00
13
13
  default_executable: subtrac
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency