7
8
9
10
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/shaddox/target.rb', line 7
def deploy(shadow_script, opts)
tmpdir = opts[:tmpdir] || '/tmp/shaddox'
shadow_script_path = "#{tmpdir}/shadow_script.rb"
new_actor do
rm_tmpdir = lambda {
unless !exec("test -e #{tmpdir} >/dev/null")
info "Removing #{tmpdir}", 1
exec("rm -r #{tmpdir}")
end
}
rm_tmpdir.call() if opts[:force]
info "Creating #{tmpdir}", 1
unlocked = exec "mkdir #{tmpdir}"
raise TargetError, "Shaddox is already running on this machine. Try again later." unless unlocked
begin
ruby_installed = exec 'type ruby >/dev/null'
raise TargetError, "Ruby is required to use shaddox. Please install it manually." unless ruby_installed
gem_installed = exec 'type gem >/dev/null'
raise TargetError, "Gem is required to use shaddox. Please install it manually." unless gem_installed
shaddox_installed = lambda { exec 'gem list shaddox -i >/dev/null' }
if shaddox_installed.call()
info "Updating shaddox...", 1
updated = exec "gem update shaddox"
warn "Shaddox could not be automatically updated. Please update it manually with 'gem update shaddox'.", 1 unless updated
else
info "Installing shaddox...", 1
exec "gem install shaddox"
end
unless shaddox_installed.call()
raise TargetError, "Shaddox could not be automatically installed. Please install manually with 'gem install shaddox'."
end
info "Writing shadow script", 1
write_file(shadow_script.script, shadow_script_path)
info "Executing shadow script", 1
raise TargetError, "Shadow script was not executed successfully." unless exec "ruby #{shadow_script_path}"
rm_tmpdir.call() unless opts[:keep_tmp_dir]
rescue => e
rm_tmpdir.call() unless opts[:keep_tmp_dir]
raise e
end
end
end
|