create_rails_mysql_db 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,6 @@
1
+ Manifest
2
+ README
3
+ Rakefile
4
+ bin/create_rails_mysql_db
5
+ create_rails_mysql_db.gemspec
6
+ lib/create_rails_mysql_db.rb
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('create_rails_mysql_db', '0.2') do |p|
6
+ p.description = "cli util to create database and username readed from config/database.yml"
7
+ p.url = "https://github.com/dmitryz/create_rails_mysql_db"
8
+ p.author = "Dmitry Biryukov"
9
+ p.email = "dmitry@biryukov.net"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'create_rails_mysql_db'
4
+
5
+ exit CreateRailsMysqlDb::Application.run!(*ARGV).to_i
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{create_rails_mysql_db}
5
+ s.version = "0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Dmitry Biryukov"]
9
+ s.cert_chain = ["/home/dmitry/.gem/gem-public_cert.pem"]
10
+ s.date = %q{2011-02-01}
11
+ s.default_executable = %q{create_rails_mysql_db}
12
+ s.description = %q{cli util to create database and username readed from config/database.yml}
13
+ s.email = %q{dmitry@biryukov.net}
14
+ s.executables = ["create_rails_mysql_db"]
15
+ s.extra_rdoc_files = ["README", "bin/create_rails_mysql_db", "lib/create_rails_mysql_db.rb"]
16
+ s.files = ["Manifest", "README", "Rakefile", "bin/create_rails_mysql_db", "create_rails_mysql_db.gemspec", "lib/create_rails_mysql_db.rb"]
17
+ s.homepage = %q{https://github.com/dmitryz/create_rails_mysql_db}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Create_rails_mysql_db", "--main", "README"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{create_rails_mysql_db}
21
+ s.rubygems_version = %q{1.3.7}
22
+ s.signing_key = %q{/home/dmitry/.gem/gem-private_key.pem}
23
+ s.summary = %q{cli util to create database and username readed from config/database.yml}
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 3
28
+
29
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
30
+ else
31
+ end
32
+ else
33
+ end
34
+ end
@@ -0,0 +1,74 @@
1
+ module CreateRailsMysqlDb
2
+ class Application
3
+ class << self
4
+ def run!(*arguments)
5
+
6
+ require 'rubygems'
7
+ require 'yaml'
8
+
9
+ @DBPATH='config/database.yml'
10
+ @DBTYPES=['mysql', 'mysql2']
11
+
12
+ if arguments.include?('-h')
13
+ puts <<-eos
14
+ create_rails_mysql_db
15
+ Without options reads config/database.yml and create listed databases, grant access to username
16
+ -g : options to generate new password, and replace username to database name
17
+ eos
18
+ exit
19
+ end
20
+
21
+ generate_password=arguments.include?('-g')
22
+ puts "Warning if password empty username=database name, new password will be generated\nconfig/database.yml will be overwrited\n" if (generate_password)
23
+
24
+ begin
25
+
26
+ def newpwd(len)
27
+ chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
28
+ newpass = ""
29
+ 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
30
+ return newpass
31
+ end
32
+ newpass = newpwd(8)
33
+ changed=0
34
+
35
+ File.open(@DBPATH) do |f|
36
+ dbconf=YAML.load(f)
37
+ dbconf.each do |type,db|
38
+ raise 'Adapter must be mysql' unless @DBTYPES.include?(db['adapter'])
39
+ raise 'Not defined username' unless db['username']
40
+ if !db['password'] && generate_password
41
+ dbconf[type]['password'] = newpass
42
+ dbconf[type]['username'] = dbconf[type]['database'].length>16 ? dbconf[type]['database'].gsub(/(\_.{4}).*/, '\1') : dbconf[type]['database']
43
+ raise 'Too long username' if dbconf[type]['username'].length>16
44
+ changed+=1
45
+ elsif !db['password']
46
+ raise 'Not defined password' unless db['password']
47
+ end
48
+ raise 'Too long username' if dbconf[type]['username'].length>16
49
+ end
50
+
51
+ File.open(@DBPATH, "w") { |f| YAML::dump(dbconf, f) } if (changed>0)
52
+ puts "Enter mysql root password:"
53
+ STDOUT.flush
54
+ system "stty -echo"
55
+ mysql_root=STDIN.gets.gsub("\n", "")
56
+ system "stty echo"
57
+ dbconf.each do |type,db|
58
+ mysql_command="mysql -uroot -p\"#{mysql_root}\" -e \"create database #{db['database']}; grant all on #{db['database']}.* to #{db['username']}@'localhost' identified by '#{db['password']}'\";"
59
+ system(mysql_command)
60
+ end
61
+ end
62
+ rescue Errno::ENOENT => e
63
+ puts "Can't open #{@DBPATH}"
64
+ rescue ArgumentError, SyntaxError => e
65
+ puts "Error in yaml format"
66
+ rescue => e
67
+ puts e.message
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: create_rails_mysql_db
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Dmitry Biryukov
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDNDCCAhygAwIBAgIBADANBgkqhkiG9w0BAQUFADBAMQ8wDQYDVQQDDAZkbWl0
19
+ cnkxGDAWBgoJkiaJk/IsZAEZFghiaXJ5dWtvdjETMBEGCgmSJomT8ixkARkWA25l
20
+ dDAeFw0xMTAyMDEwODQ1MjJaFw0xMjAyMDEwODQ1MjJaMEAxDzANBgNVBAMMBmRt
21
+ aXRyeTEYMBYGCgmSJomT8ixkARkWCGJpcnl1a292MRMwEQYKCZImiZPyLGQBGRYD
22
+ bmV0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt/YU3QS+9TEVomSW
23
+ 7RyRZeyhXfZ8WukAkqQ6kEoXfHQZJbGClnZ6jXlgog2utjNI6+WIKZAgRsZZeqGT
24
+ mkTBWtEh1A2bbAKMwixggudqbsGi4pD57KnncwYg5t7WZH0mNmF6uxsvXa5XgJYp
25
+ Tw8Em9U/yhG7PtrK9fp8qDzM8avGc7hz6FslAIJrSuRHipqCEM72DJFigkIxwpu8
26
+ A/Qu1StK1R1L6pp2lLMnAo+2SM1SaDTo5SVlzcCwhf77YfRebeis7AXhI8JWlwri
27
+ VQqcVa91sFWQkxDYIv8neKvvo34X/WWqb/KNjGy5s/TcJukJND2f4jAllAFGSE1L
28
+ a4d0CwIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU
29
+ 9QV52pu02VunFzMRcjnc1Tiup+swDQYJKoZIhvcNAQEFBQADggEBAJpaj02Ogkxj
30
+ qmqmtUJ7iPzRFzAarjmtUoDzDI7fz7eS5mjGbGYSnkfcK6zKPzz+2NdsoueVqkHD
31
+ /X2MQXwsM+EVah5wo674XatzKr8xQqKUGjcmB3vv/5+p1trQwPxuhjQt9XC+yLmo
32
+ mhzSyEpHWeFMNdUoV4R1goTc76JymIVUUqLcZqIW/U+4tqVXfKsINujm9t4i7NQP
33
+ YGJ70XANqIsACuvlBFJQCCq1rIQR1yNEeCG9xCz61iMSGeDh9qoJcvgdGU6vaNfK
34
+ 9mQg4LmgiNswjSO1czL5y45sB/TzTbEdyKNFtZ3C7i3WHNI93Ae6HNheBK/dEvyW
35
+ En/DvHrQBNY=
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2011-02-01 00:00:00 +02:00
39
+ default_executable:
40
+ dependencies: []
41
+
42
+ description: cli util to create database and username readed from config/database.yml
43
+ email: dmitry@biryukov.net
44
+ executables:
45
+ - create_rails_mysql_db
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - README
50
+ - bin/create_rails_mysql_db
51
+ - lib/create_rails_mysql_db.rb
52
+ files:
53
+ - Manifest
54
+ - README
55
+ - Rakefile
56
+ - bin/create_rails_mysql_db
57
+ - create_rails_mysql_db.gemspec
58
+ - lib/create_rails_mysql_db.rb
59
+ has_rdoc: true
60
+ homepage: https://github.com/dmitryz/create_rails_mysql_db
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --line-numbers
66
+ - --inline-source
67
+ - --title
68
+ - Create_rails_mysql_db
69
+ - --main
70
+ - README
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 11
88
+ segments:
89
+ - 1
90
+ - 2
91
+ version: "1.2"
92
+ requirements: []
93
+
94
+ rubyforge_project: create_rails_mysql_db
95
+ rubygems_version: 1.3.7
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: cli util to create database and username readed from config/database.yml
99
+ test_files: []
100
+
metadata.gz.sig ADDED
Binary file