akitaonrails-locarails 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,8 +16,27 @@ require 'erb'
16
16
  require 'highline/import'
17
17
 
18
18
  # configuracoes da sua hospedagem
19
- config = OpenStruct.new
20
- mysqlcfg = OpenStruct.new
19
+ class MyOpenStruct < OpenStruct
20
+ def blank?(campo)
21
+ send(campo).nil? || send(campo).empty?
22
+ end
23
+
24
+ def input(campo, message, default_value = nil)
25
+ unless blank?(campo)
26
+ puts "* #{message} > #{message =~ /senha/ ? "********" : send(campo)}"
27
+ return send(campo)
28
+ end
29
+ result = if message =~ /senha/
30
+ ask("* #{message} > ") { |q| q.echo = "*" }
31
+ else
32
+ ask("* #{message} > ")
33
+ end
34
+ send("#{campo}=", (default_value && result.empty?) ? default_value : result)
35
+ end
36
+ end
37
+
38
+ config = MyOpenStruct.new
39
+ mysqlcfg = MyOpenStruct.new
21
40
 
22
41
  # defaults
23
42
  config.force = false
@@ -56,6 +75,42 @@ STR
56
75
  config.force = true
57
76
  end
58
77
 
78
+ opts.on("-u", "--usuario=login", "Usuario da hospedagem Linux") do |usuario|
79
+ config.usuario = usuario
80
+ end
81
+
82
+ opts.on("-a", "--aplicacao=aplicacao", "Nome da sua aplicacao", "O mesmo do apontamento /public_html/aplicacao") do |aplicacao|
83
+ config.app_name = aplicacao
84
+ end
85
+
86
+ opts.on("-d", "--dominio=URL", "Dominio do seu site", "ex. www.seu_dominio.com") do |dominio|
87
+ config.dominio = dominio
88
+ end
89
+
90
+ opts.on("-q", "--banco=banco", "Nome do seu banco de dados") do |db|
91
+ mysqlcfg.db = db
92
+ end
93
+
94
+ opts.on("-l", "--banco-usuario=login", "Login do seu banco de dados MySQL") do |dbuser|
95
+ mysqlcfg.user = dbuser
96
+ end
97
+
98
+ opts.on("-p", "--banco-senha=senha", "Senha do seu banco de dados MySQL") do |dbpass|
99
+ mysqlcfg.pass = dbpass
100
+ end
101
+
102
+ opts.on("-v", "--banco-servidor=servidor", "Servidor do seu banco de dados", "ex. mysql6666.locaweb.com.br") do |dbhost|
103
+ mysqlcfg.host = dbhost
104
+ end
105
+
106
+ opts.on("-b", "--git-branch=branch", "Branch local do seu repositorio Git", "padrao: master") do |gitbranch|
107
+ config.branch = gitbranch
108
+ end
109
+
110
+ opts.on("-r", "--git-remote=remote", "Nome do repositorio remoto gravado no seu .git/config", "padrao: locaweb") do |gitname|
111
+ config.remote_repo = gitname
112
+ end
113
+
59
114
  begin
60
115
  opts.parse!(ARGV)
61
116
  rescue OptionParser::ParseError => e
@@ -71,24 +126,12 @@ elsif !File.exists?(ARGV.first)
71
126
  abort "`#{ARGV.first}' nao existe. Tente novamente."
72
127
  elsif !File.directory?(ARGV.first)
73
128
  abort "`#{ARGV.first}' nao eh um diretorio. Tente novamente."
74
- elsif ARGV.length > 1
75
- abort "Argumentos demais; por favor especifique somente o diretorio da aplicacao Rails.."
76
- end
77
-
78
- def get_input(message, default_value = nil)
79
- result = if message =~ /senha/
80
- ask("* #{message} > ") { |q| q.echo = "*" }
81
- else
82
- ask("* #{message} > ")
83
- end
84
- result = default_value if default_value && result.empty?
85
- result
86
129
  end
87
130
 
88
131
  # configuracoes locais da sua maquina
89
132
  config.bin_path = File.dirname(File.expand_path(__FILE__))
90
133
  config.local_path = File.expand_path(ARGV.shift)
91
- config.app_name = config.local_path.split('/').last
134
+ config.app_name ||= config.local_path.split('/').last
92
135
 
93
136
  if !config.force && File.exists?(File.join(config.local_path, 'config/deploy.rb'))
94
137
  abort "Voce ja tem capistrano configurado em config/deploy.rb. Configuracao abortada."
@@ -115,18 +158,18 @@ Garanta que a seguinte pasta contem sua aplicacao Rails:
115
158
  STR
116
159
 
117
160
  # configuracoes inseridas manualmente pelo usuario
118
- config.app_name = get_input( "Nome da sua aplicacao" ) if config.app_name.nil? || config.app_name.empty?
119
- config.dominio = get_input "Dominio do seu site (ex. teste.tempsite.ws)"
120
- config.usuario = get_input "Seu usuario de hospedagem"
121
- mysqlcfg.db = get_input "Nome do seu banco mysql (enter para '#{config.usuario}')", config.usuario
122
- mysqlcfg.user = get_input "Seu usuario de mysql (enter para #{mysqlcfg.db})", mysqlcfg.db
123
- mysqlcfg.pass = get_input "Sua senha de mysql"
124
- mysqlcfg.host = get_input "Seu servidor mysql (ex. mysqlxxxx.locaweb.com.br)"
125
- mysqlcfg.host = "#{mysqlcfg.host}.locaweb.com.br" unless mysqlcfg.host =~ /locaweb\.com\.br/
161
+ config.input( :app_name, "Nome da sua aplicacao" )
162
+ config.input( :dominio, "Dominio do seu site (ex. teste.tempsite.ws)" )
163
+ config.input( :usuario, "Seu usuario de hospedagem" )
164
+ mysqlcfg.input( :db, "Nome do seu banco mysql (enter para '#{config.usuario}')", config.usuario )
165
+ mysqlcfg.input( :user, "Seu usuario de mysql (enter para #{mysqlcfg.db})", mysqlcfg.db )
166
+ mysqlcfg.input( :pass, "Sua senha de mysql" )
167
+ mysqlcfg.input( :host, "Seu servidor mysql (ex. mysqlxxxx.locaweb.com.br)" )
168
+ mysqlcfg.host = "#{mysqlcfg.host}.locaweb.com.br" unless mysqlcfg.host =~ /locaweb\.com\.br/
126
169
  if config.mode == 'git'
127
- config.branch = get_input "Git branch (enter para 'master')", 'master'
128
- config.remote_repo = get_input "Nome do repositorio remoto (enter para 'locaweb')", 'locaweb'
129
- config.remote_git = "#{config.usuario}@#{config.dominio}:~/repo/#{config.app_name}.git"
170
+ config.input( :branch, "Git branch (enter para 'master')", 'master' )
171
+ config.input( :remote_repo, "Nome do repositorio remoto (enter para 'locaweb')", 'locaweb' )
172
+ config.remote_git = "#{config.usuario}@#{config.dominio}:~/repo/#{config.app_name}.git"
130
173
  end
131
174
 
132
175
  # forca rodar capistrano
@@ -148,7 +191,13 @@ if config.mode == 'git'
148
191
  "#{config.local_path}/.gitignore") unless File.exists?("#{config.local_path}/.gitignore")
149
192
  end
150
193
 
151
- File.open("#{config.local_path}/config/deploy.rb", 'w+') do |out|
194
+ FileUtils.copy_file("#{config.bin_path}/../templates/locaweb_backup.rb",
195
+ "#{config.local_path}/config/locaweb_backup.rb") unless File.exists?("#{config.local_path}/config/locaweb_backup.rb")
196
+
197
+ FileUtils.copy_file("#{config.bin_path}/../templates/ssh_helper.rb",
198
+ "#{config.local_path}/config/ssh_helper.rb") unless File.exists?("#{config.local_path}/config/ssh_helper.rb")
199
+
200
+ File.open("#{config.local_path}/config/deploy.rb", 'w') do |out|
152
201
  erb = ERB.new(File.read("#{config.bin_path}/../templates/deploy.rb.erb"))
153
202
  buffer = erb.result(config.send(:binding))
154
203
  erb = ERB.new(File.read("#{config.bin_path}/../templates/deploy.common.rb.erb"))
@@ -156,7 +205,7 @@ File.open("#{config.local_path}/config/deploy.rb", 'w+') do |out|
156
205
  out.puts buffer
157
206
  end
158
207
 
159
- File.open("#{config.local_path}/config/database.locaweb.yml", 'w+') do |out|
208
+ File.open("#{config.local_path}/config/database.locaweb.yml", 'w') do |out|
160
209
  erb = ERB.new(File.read("#{config.bin_path}/../templates/database.locaweb.yml.erb"))
161
210
  out.puts erb.result(mysqlcfg.send(:binding))
162
211
  end
@@ -2,7 +2,7 @@ module Locarails
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{locarails}
3
- s.version = "1.1.2"
3
+ s.version = "1.1.3"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Fabio Akita"]
@@ -124,10 +124,11 @@ namespace :ssh do
124
124
  }
125
125
  exit 0
126
126
  end
127
- run "test -d ~/.ssh || mkdir -m 755 ~/.ssh"
128
- upload public_key_path, "~/.ssh"
129
- run "test -f ~/.ssh/authorized_keys || touch ~/.ssh/authorized_keys"
130
- run "cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys"
131
- run "chmod 755 ~/.ssh/authorized_keys"
127
+ ssh_path = "/home/#{user}/.ssh"
128
+ run "test -d #{ssh_path} || mkdir -m 755 #{ssh_path}"
129
+ upload public_key_path, "#{ssh_path}/../id_rsa.pub"
130
+ run "test -f #{ssh_path}/authorized_keys || touch #{ssh_path}/authorized_keys"
131
+ run "cat #{ssh_path}/../id_rsa.pub >> #{ssh_path}/authorized_keys"
132
+ run "chmod 755 #{ssh_path}/authorized_keys"
132
133
  end
133
134
  end
@@ -24,7 +24,7 @@ when 'drop_all'
24
24
  end
25
25
 
26
26
  commands.each do |cmd|
27
- puts "executando: #{cmd.gsub(cfg['password'], 'xxxxxxxx')}"
27
+ puts "executando: #{cmd.gsub(prd['password'], '*****')}"
28
28
  `#{cmd}`
29
29
  end
30
30
  puts "operacao #{operation} finalizada."
@@ -282,10 +282,12 @@ class SSHHelper
282
282
  def self.generate_keys(filename)
283
283
  authorized_file = "#{File.dirname(filename)}/authorized_keys"
284
284
 
285
- private_key = OpenSSL::PKey::RSA.new(1024)
285
+ private_key = OpenSSL::PKey::RSA.new(2048)
286
286
  public_pem = export_ssh_pubkey( private_key )
287
287
 
288
+ File.delete( filename ) if File.exists?( filename )
288
289
  File.open( filename, "w" ) { |file| file.write private_key.export }
290
+ File.delete( "#{filename}.pub" ) if File.exists?("#{filename}.pub")
289
291
  File.open( "#{filename}.pub", "w" ) { |file| file.write public_pem }
290
292
  File.open( authorized_file, 'w') { |file| file.write public_pem + "\n"}
291
293
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akitaonrails-locarails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Akita