root/trunk/setup.rb

Revision 399, 9.8 kB (checked in by ssmith, 3 years ago)

Update to the stock checkout, to make sure that things are properly updated
for Rails.
Updated CHANGELOG and UPGRADE
Fixed setupp.rb to include MILITRY_TIME_FORMAT
Added themes/newspaper/javascript/newspaper-functions.js to stop an
annoying error in the message logs

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env ruby
2 require './config/boot'
3 begin
4     require 'rubygems'
5 rescue LoadError
6     print "You have to have Ruby Gems installed to use this program.\n"
7     exit
8 end
9
10 print "\nWelcome to TigerEvents\n"
11 print "-----------------------\n\n"
12
13 print "This setup program will generate a site-specific SQL script\n"
14 print "which can be used to setup the database as well as perform\n"
15 print "all site-specific configurations.\n"
16 print "\nPlease follow the instructions carefully!\n\n"
17 print "Continue (y/n)? "
18
19 cont = gets.strip
20
21 if cont != "y"
22     print "Bye.\n"
23     exit
24 end
25
26 military_time = nil
27 while not military_time
28   print "Section 0: Time Format\n"
29   print "--------------------------------\n"
30   print "\nPlease choose the time format you would like to use\n\n"
31   print "\t[1] 12 Hour Format\n"
32   print "\t[2] 24 Hour Format\n"
33   military_time = gets.strip
34   if military_time != "2"
35     military_time = true
36   else
37     military_time = false
38   end
39 end
40
41 print "Section 1: Server\n"
42 print "--------------------------------\n"
43
44 te_path = nil
45 while not te_path
46     print "\nWhat is the root path to your tigerevents install?\n"
47     print "e.g. http://tigerevents.tigeronrails.com\n\n"
48     print "Hostname/path: "
49     te_path = gets.strip
50 end
51
52 print "Section 2: Authentication System\n"
53 print "--------------------------------\n"
54
55 auth = nil
56 while not auth
57     print "\nWhich authentication system do you want to use to\n"
58     print "authenticate user?\n\n"
59     print "\t[1] Database\n"
60     print "\t[2] LDAP (requires an SSL/TLS enabled LDAP server)\n\n"
61     print "Selection (default [1]): "
62     auth = gets.strip
63     if auth == ""
64         auth = "1"
65     end
66     auth = auth.to_i
67     if auth != 1 && auth != 2
68         auth = nil
69     end
70 end
71
72 # use database authentication
73 if auth == 1
74     print "Database authentication selected.\n\n"
75     auth_type = 'SQLAccountController'
76 elsif auth == 2
77     print "LDAP authentication selected.\n\n"
78     auth_type = 'LDAPAccountController'
79     ldap_ok = false
80     while not ldap_ok
81         print "Please specify your LDAP server (e.g ldap.foobar.com): "
82         ldap_url = gets.strip
83         print "Do you want to use encrypted communication (SSL/TLS) with\n"
84         print "the LDAP server (y/n)? "
85         ldap_use_ssl = gets.strip
86         if ldap_use_ssl == "y"
87             ldap_use_ssl = "yes"
88         else
89             ldap_use_ssl = "no"
90         end
91         if ldap_use_ssl == "yes"
92             print "Do you want to use TLS 1.0 instead of SSL (y/n)? "
93             ldap_start_tls = gets.strip
94             if ldap_start_tls == "y"
95                 ldap_start_tls = "yes"
96             else
97                 ldap_start_tls = "no"
98             end
99         end
100         print "Please specify your LDAP search base for user\n"
101         print "accounts (e.g. dc=foobar,dc=com): "
102         ldap_dn = gets.strip
103
104         print "Please specify the field name your LDAP configuration\n"
105         print "uses for the user's full name: "
106         ldap_displayname = gets.strip
107
108         print "Please specify the field name your LDAP configuration\n"
109         print "uses for the user's e-mail address: "
110         ldap_email = gets.strip
111
112         print "\nPlease check the following LDAP configuration:\n\n"
113         print "\tLDAP server:      #{ldap_url}\n"
114         print "\tUse SSL/TLS:      #{ldap_use_ssl}\n"
115         if ldap_use_ssl == "yes"
116             print "\tUse TLS:          #{ldap_start_tls}\n"
117         end
118         print "\tLDAP search base: #{ldap_dn}\n"
119         print "\tLDAP display name field: #{ldap_displayname}\n"
120         print "\tLDAP e-mail field: #{ldap_email}\n"
121         print "\nAre those settings correct (y/n)? "
122         ldap_ok = gets.strip
123         if ldap_ok == "y"
124             ldap_ok = true
125         else
126             ldap_ok = false
127         end
128     end
129 end
130 if not ldap_use_ssl or ldap_use_ssl != "yes"
131     ldap_use_ssl = "false"
132     ldap_start_tls = "false"
133 else
134     ldap_use_ssl = "true"
135     if ldap_start_tls == "yes"
136         ldap_start_tls = "true"
137     else
138         ldap_start_tls = "false"
139     end
140 end
141 if not ldap_url
142     ldap_url = ""
143 end
144 if ldap_use_ssl == "true" and ldap_start_tls == "false"
145     ldap_port = "636"
146 else
147     ldap_port = "389"
148 end
149 if not ldap_dn
150     ldap_dn = "dc=search,dc=domain"
151 end
152  
153 print "Section 2: Administrator Settings\n"
154 print "---------------------------------\n"
155
156 admin_ok = false
157 while not admin_ok
158     print "\nPlease specify the administrators name (e.g. John Doe): "
159     admin_name = gets.strip
160     print "\nWhat is the administrator's email address\n"
161     print "(e.g. john.doe@foobar.com)? "
162     admin_email = gets.strip
163     if auth_type == "SQLAccountController"
164         begin
165             require "digest/sha1"
166         rescue LoadError
167             puts "You need to have the digest/sha1 module installed\n"
168             puts "to use SQL authentication."
169             puts "Bye."
170             exit
171         end
172         print "\nYou have choosen database authentication.\n"   
173         print "What should be the administrator's username (e.g. jdoe)? "
174         admin_username = gets.strip
175         print "What should be the administrator's password? \033[8m"
176         admin_password = gets.strip
177 #        admin_password = Digest::SHA1.hexdigest(admin_password)
178         print "\033[0m"
179     elsif auth_type == "LDAPAccountController"
180         print "\nYou have choosen LDAP authentication.\n"
181         print "What is the administrators username on the LDAP server? "
182         admin_username = gets.strip
183     end
184
185     print "Please verify the settings:\n\n"
186     print "\tAdministrator's name:         #{admin_name}\n"
187     print "\tAdministrator's email addres: #{admin_email}\n"
188     print "\tAdministrator's username:     #{admin_username}\n"
189     print "\nAre those settings correct (y/n)? "
190     admin_ok = gets.strip
191     if admin_ok == "y"
192         admin_ok = true
193     else
194         admin_ok = false
195     end
196 end
197 admin_password ||= ""
198
199 print "Section 3: Database Settings\n"
200 print "----------------------------\n\n"
201 print "The following are questions about your database connectivity.\n"
202 print "TigerEvents currently only supports MySQL databases.\n"
203
204 db_ok = false
205 while not db_ok
206     print "\nHow should the database server be connected:\n\n"
207     print "\t[1] Socket\n"
208     print "\t[2] TCP/IP\n"
209     print "\nSelection (default [1]): "
210     db_conn = gets.strip
211     if db_conn == ""
212         db_conn = "1"
213     end
214     db_conn = db_conn.to_i
215     if db_conn == 1
216         db_conn = "socket"
217     elsif db_conn == 2
218         db_conn = "TCP/IP"
219     end
220
221     if db_conn == "socket"
222         print "Please specify the path to the socket to use\n"
223         print "(default: /var/run/mysqld/mysqld.sock): "
224         db_sock = gets.strip
225         if db_sock == ""
226             db_sock = "/var/run/mysqld/mysqld.sock"
227         end
228     elsif db_conn == "TCP/IP"
229         print "Please specify the hostname of the database server\n"
230         print "(default: localhost): "
231         db_host = gets.strip
232         if db_host == ""
233             db_host = "localhost"
234         end
235     end
236
237     print "Specify the database that should be used\n"
238     print "(default: tigerevents): "
239     db_name = gets.strip
240     if db_name == ""
241         db_name = "tigerevents"
242     end
243    
244     print "Specify the username used to connect to the database\n"
245     print "(default: tigerevents): "
246     db_user = gets.strip
247     if db_user == ""
248         db_user = "tigerevents"
249     end
250
251     print "Specify the password used for the database user\n"
252     print "(default: none): "
253     db_pass = gets.strip
254     if db_pass == ""
255         db_pass = nil
256     end
257    
258     print "Please verify the database connectivity information:\n\n"
259     print "\tConnection type: #{db_conn}\n"
260     if db_conn == "socket"
261         print "\tSocket:          #{db_sock}\n"
262     elsif db_conn == "TCP/IP"
263         print "\tHostname:        #{db_host}\n"
264     end
265     print "\tDatabase:            #{db_name}\n"
266     print "\tUsername:            #{db_user}\n"
267     print "\tPassword:            #{db_pass}\n"
268     print "\nAre those informations correct (y/n)? "
269     db_ok = gets.strip
270     if db_ok == "y"
271         db_ok = true
272     else
273         db_ok = false
274     end
275 end
276 if db_conn == "socket"
277     db_prot = "socket: #{db_sock}"
278 elsif db_conn == "TCP/IP"
279     db_prot = "host: #{db_host}"
280 end
281
282 print "\n\n--------------------------------------------------------------\n"
283 print "\nThe program is now going to generate 2 files:\n\n"
284 print "\tconfig/database.yml: contains database connectivity information\n"
285 print "\t                     for the application\n\n"
286 print "\tconfig/tigerevents_config: local TigerEvents configuration\n\n"
287 print "\nExiting files with be saves with extension .orig\n"
288 print "Continue (y/n)? "
289 cont = gets.strip
290
291 if cont != "y"
292     print "Bye.\n"
293     exit
294 end
295
296 database = File.join("config", "database.yml")
297 config = File.join("config", "tigerevents_config.rb")
298
299 # write database.yml
300 if FileTest.exists?(database)
301     File.rename(database, database + ".orig")
302 end
303 f = File.open(database + ".tmpl", "r")
304 tmpl = f.read
305 f.close
306 x = eval("\"" + tmpl + "\"")
307 f = File.open(database, "w")
308 f.write(x)
309 f.close
310
311 # write tigerevents_config.rb
312 if FileTest.exists?(config)
313     File.rename(config, config + ".orig")
314 end
315 f = File.open(config + ".tmpl", "r")
316 tmpl = f.read
317 f.close
318 x = eval("\"" + tmpl + "\"")
319 f = File.open(config, "w")
320 f.write(x)
321 f.close
322
323 fork do
324     exec "rake migrate"
325 end
326 Process.wait
327 require './config/environment'
328 User.create(:login => "#{admin_username}",
329         :user_password => "#{admin_password}",
330         :fullname => "#{admin_name}",
331         :superuser => true,
332         :email => "#{admin_email}")
333
334 print "\n\nThe configuration has been written and the database has\n"
335 print "been set up. You can now run the local test web-server\n"
336 print "by executing:\n\n"
337 print "\truby script/server\n\n"
338 print "and connect to http://localhost:3000/.\n\n"
339 print "You need to login to the website with the administrator account\n"
340 print "to setup appropriate group classes before users can start\n"
341 print "posting events and announcements.\n\n"
Note: See TracBrowser for help on using the browser.