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.
- data/bin/locarails +77 -28
- data/lib/locarails/version.rb +1 -1
- data/locarails.gemspec +1 -1
- data/templates/deploy.common.rb.erb +6 -5
- data/templates/locaweb_backup.rb +1 -1
- data/templates/ssh_helper.rb +3 -1
- metadata +1 -1
data/bin/locarails
CHANGED
@@ -16,8 +16,27 @@ require 'erb'
|
|
16
16
|
require 'highline/import'
|
17
17
|
|
18
18
|
# configuracoes da sua hospedagem
|
19
|
-
|
20
|
-
|
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
|
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
|
119
|
-
config.dominio
|
120
|
-
config.usuario
|
121
|
-
mysqlcfg.db
|
122
|
-
mysqlcfg.user
|
123
|
-
mysqlcfg.pass
|
124
|
-
mysqlcfg.host
|
125
|
-
mysqlcfg.host
|
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
|
128
|
-
config.remote_repo
|
129
|
-
config.remote_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
|
-
|
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
|
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
|
data/lib/locarails/version.rb
CHANGED
data/locarails.gemspec
CHANGED
@@ -124,10 +124,11 @@ namespace :ssh do
|
|
124
124
|
}
|
125
125
|
exit 0
|
126
126
|
end
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
run "
|
131
|
-
run "
|
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
|
data/templates/locaweb_backup.rb
CHANGED
data/templates/ssh_helper.rb
CHANGED
@@ -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(
|
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
|
|