11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cap_vagrant/app.rb', line 11
def setup
if options[:version]
puts CapVagrant::VERSION
exit
end
check_path?('Capfile', "Have you already setup Capistrano?")
check_path?('config/deploy', "Are you using the multistage extension?")
check_path?('Vagrantfile', "Have you already setup Vagrant?")
ssh_details = {'HostName' => 'host', 'User' => 'user', 'Port' => 'port', 'IdentityFile' => "keys"}
vars = {'name' => options[:name]}
ssh_config=`vagrant ssh-config`.split("\n ") ; result=$?.success?
abort "Calling vagrant ssh-config failed." unless result
ssh_config.each do |i|
k,v = i.split(" ")
vars[ssh_details[k]] = v if ssh_details[k]
end
stage_file = File.join('.', 'config', 'deploy', "#{options[:name]}.rb")
if options[:update]
check_path?(stage_file)
text = File.read(stage_file)
replace = text.gsub(/:port.*\n/, ":port] = #{vars['port']}\n")
File.open(stage_file, 'w') do |f|
f.puts replace
end
else
config = ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates', 'stage.rb.erb')))
File.open(stage_file, 'w') do |f|
f.write config.result(binding)
end
end
end
|