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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 225
def run
require 'rubygems'
require 'rubygems/command.rb'
require 'rubygems/dependency_installer.rb'
unless Gem.available?('mysql') || Gem.available?('ruby-mysql')
if ask? _("Mysql gem is not available. Install?")
ok = false
while !ok
inst = Gem::DependencyInstaller.new
begin
inst.install 'mysql'
rescue
begin
inst.install 'ruby-mysql'
rescue
error _("Installation of mysql gem failed.")
return
end
puts _(
"The mysql gem failed to compile, so the pure-ruby version was installed.
You should install the compiled version manually for better performance.")
end
end
else
error _("Can't configure mysql without the mysql gem.")
return
end
end
require 'mysql'
local = discovery
use_local = nil
unless local.empty?
local_str = local.map{ |l|
l[:socket] ? l[:socket] : "#{l[:host]}:#{l[:port]}"
}
use_local = ask _("We found the following MySQL instances. Do you want to use one of them?"),
:choices => local_str, :return_index => true, :allow_cancel => _("No")
use_local = local[use_local] if use_local
end
@socket = nil
@host = nil
@port = nil
if use_local
@socket = use_local[:socket]
@host = use_local[:host]
@port = use_local[:port]
else
ok = false
while !ok
if (ask _("Do you want to connect via socket or via network?"),
:choices => ['socket', 'network']) == 'network'
ask _("Host:"), :host, :default => 'localhost'
ask _("Port:"), :port, :default => 3306
else
ask _("Socket location"), :socket
end
if @socket
if File.socket?(@socket)
ok = true
else
error _("%s does not seem to be a socket") % @socket
end
else
begin
s = TCPSocket::open(@host, @port)
ok = true
rescue
error _("Connection to %s failed") % "#{@host}:#{@port}"
ok = ask_error
end
end
end
end
ok = false
connect_ok = false
while !ok
ask! _("Username"), :user
ask _("Password"), :pass
conn = @socket ? @socket : "#{@host}:#{@port}"
notify_partial _("Trying to connect to mysql at %s ... ") % conn
begin
m = ::Mysql.new(@host, @user, @pass, nil, @port, @socket)
m.ping
m.close
connect_ok = true
ok = true
notify_partial("Ok.", true)
rescue
notify_partial("", true)
error _("Connection failed.")
ok = ask_error
end
end
ok = false
while !ok
ask _("Db name:"), :db_name
if connect_ok
notify_partial _("Checking if db exists... ")
begin
m = ::Mysql.new(@host, @user, @pass, @db_name, @port, @socket)
ok = true
notify_partial("Ok.", true)
rescue => exc
notify_partial("", true)
error _("Database %s does not exist.") % @db_name
ok = ask_error
end
else
ok = true
end
end
end
|