script_executor 1.3.2 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.idea/codeStyleSettings.xml +14 -0
- data/.idea/misc.xml +1 -1
- data/.idea/script_executor.iml +195 -14
- data/.idea/workspace.xml +408 -345
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGES +9 -1
- data/Gemfile +6 -13
- data/Gemfile.lock +10 -1
- data/README.md +96 -20
- data/lib/executable.rb +0 -2
- data/lib/script_executor.rb +0 -2
- data/lib/script_executor/executable.rb +10 -121
- data/lib/script_executor/local_command.rb +78 -0
- data/lib/script_executor/remote_command.rb +91 -0
- data/lib/script_executor/version.rb +2 -2
- data/lib/script_locator.rb +0 -2
- data/spec/executable_spec.rb +1 -2
- data/spec/script_locator_spec.rb +5 -5
- metadata +10 -18
- data/.rbenv-gemsets +0 -1
- data/.rbenv-version +0 -1
- data/.rvmrc +0 -5
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'script_executor/output_buffer'
|
2
|
+
require 'net/ssh'
|
3
|
+
require "highline"
|
4
|
+
|
5
|
+
class RemoteCommand
|
6
|
+
attr_reader :domain, :user, :password, :identity_file, :suppress_output, :capture_output, :simulate
|
7
|
+
|
8
|
+
def initialize params
|
9
|
+
@domain = params[:domain]
|
10
|
+
@user = params[:user]
|
11
|
+
@password = params[:password]
|
12
|
+
@identity_file = params[:identity_file]
|
13
|
+
@suppress_output = params[:suppress_output]
|
14
|
+
@capture_output = params[:capture_output]
|
15
|
+
@simulate = params[:simulate]
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute commands, line_action
|
19
|
+
print commands, $stdout
|
20
|
+
|
21
|
+
unless simulate
|
22
|
+
storage = capture_output ? OutputBuffer.new : nil
|
23
|
+
output = suppress_output ? nil : $stdout
|
24
|
+
|
25
|
+
password = HighLine.new.ask("Enter password for #{user}: ") { |q| q.echo = '*' } if @password.nil?
|
26
|
+
|
27
|
+
Net::SSH.start(domain, user, :password => password) do |session|
|
28
|
+
session.exec(commands) do |channel, _, line|
|
29
|
+
if ask_password?(line)
|
30
|
+
channel.request_pty
|
31
|
+
channel.send_data password + "\n"
|
32
|
+
else
|
33
|
+
output.print(line) if output
|
34
|
+
storage.save(line.chomp) if storage
|
35
|
+
|
36
|
+
line_action.call(line) if line_action
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
session.loop # run the aggregated event loop
|
41
|
+
end
|
42
|
+
|
43
|
+
storage.buffer.join("\n") if storage
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def print commands, output
|
50
|
+
ssh_command = ssh_command(domain, user, identity_file)
|
51
|
+
|
52
|
+
if simulate
|
53
|
+
output.puts "Remote script: '#{ssh_command}'"
|
54
|
+
output.puts "-------"
|
55
|
+
|
56
|
+
lines = StringIO.new commands
|
57
|
+
|
58
|
+
lines.each_line do |line|
|
59
|
+
output.puts line
|
60
|
+
end
|
61
|
+
|
62
|
+
output.puts "-------"
|
63
|
+
else
|
64
|
+
output.puts "Remote execution on: '#{ssh_command}'"
|
65
|
+
output.puts "-------"
|
66
|
+
|
67
|
+
lines = StringIO.new commands
|
68
|
+
|
69
|
+
lines.each_line do |line|
|
70
|
+
output.puts line
|
71
|
+
end
|
72
|
+
|
73
|
+
output.puts "-------"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def ssh_command domain, user, identity_file
|
78
|
+
cmd = user.nil? ? domain : "#{user}@#{domain}"
|
79
|
+
|
80
|
+
cmd << " -i #{identity_file}" if identity_file
|
81
|
+
|
82
|
+
#cmd << " -t -t"
|
83
|
+
|
84
|
+
"ssh #{cmd}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def ask_password? line
|
88
|
+
line =~ /^\[sudo\] password for user:/ || line =~ /sudo password:/ || line =~ /Password:/
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "1.3.
|
1
|
+
class ScriptExecutor
|
2
|
+
VERSION = "1.3.4"
|
3
3
|
end
|
data/lib/script_locator.rb
CHANGED
data/spec/executable_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe MyExecutable do
|
|
11
11
|
subject { MyExecutable.new }
|
12
12
|
|
13
13
|
before :all do
|
14
|
-
@password ||= ask("Enter password for #{ENV['USER']}: ") { |q| q.echo = '*' }
|
14
|
+
@password ||= HighLine.new.ask("Enter password for #{ENV['USER']}: ") { |q| q.echo = '*' }
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "local execution" do
|
@@ -46,7 +46,6 @@ describe MyExecutable do
|
|
46
46
|
)
|
47
47
|
end
|
48
48
|
|
49
|
-
puts "2 #{@password}"
|
50
49
|
result.to_s.should == "root\nroot"
|
51
50
|
end
|
52
51
|
end
|
data/spec/script_locator_spec.rb
CHANGED
@@ -11,18 +11,18 @@ describe MyScriptLocator do
|
|
11
11
|
subject { MyScriptLocator.new }
|
12
12
|
|
13
13
|
it "should read after __END__" do
|
14
|
-
|
14
|
+
scripts = subject.scripts(__FILE__)
|
15
15
|
|
16
|
-
|
16
|
+
scripts.should_not be_nil
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should locate script" do
|
20
|
-
|
20
|
+
scripts = subject.scripts(__FILE__)
|
21
21
|
|
22
22
|
name = "alisa"
|
23
|
-
|
23
|
+
result = subject.evaluate_script_body(scripts['test1'], binding)
|
24
24
|
|
25
|
-
|
25
|
+
result.should =~ /#{name}/
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: script_executor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alexander Shvets
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: highline
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: net-ssh
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: gemspec_deps_gen
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: gemcutter
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -84,6 +75,7 @@ files:
|
|
84
75
|
- .gitignore
|
85
76
|
- .idea/.name
|
86
77
|
- .idea/.rakeTasks
|
78
|
+
- .idea/codeStyleSettings.xml
|
87
79
|
- .idea/encodings.xml
|
88
80
|
- .idea/misc.xml
|
89
81
|
- .idea/modules.xml
|
@@ -91,9 +83,8 @@ files:
|
|
91
83
|
- .idea/script_executor.iml
|
92
84
|
- .idea/vcs.xml
|
93
85
|
- .idea/workspace.xml
|
94
|
-
- .
|
95
|
-
- .
|
96
|
-
- .rvmrc
|
86
|
+
- .ruby-gemset
|
87
|
+
- .ruby-version
|
97
88
|
- CHANGES
|
98
89
|
- Gemfile
|
99
90
|
- Gemfile.lock
|
@@ -103,7 +94,9 @@ files:
|
|
103
94
|
- lib/executable.rb
|
104
95
|
- lib/script_executor.rb
|
105
96
|
- lib/script_executor/executable.rb
|
97
|
+
- lib/script_executor/local_command.rb
|
106
98
|
- lib/script_executor/output_buffer.rb
|
99
|
+
- lib/script_executor/remote_command.rb
|
107
100
|
- lib/script_executor/script_executor.rb
|
108
101
|
- lib/script_executor/script_locator.rb
|
109
102
|
- lib/script_executor/version.rb
|
@@ -115,27 +108,26 @@ files:
|
|
115
108
|
- spec/spec_helper.rb
|
116
109
|
homepage: http://github.com/shvets/script_executor
|
117
110
|
licenses: []
|
111
|
+
metadata: {}
|
118
112
|
post_install_message:
|
119
113
|
rdoc_options: []
|
120
114
|
require_paths:
|
121
115
|
- lib
|
122
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
117
|
requirements:
|
125
118
|
- - ! '>='
|
126
119
|
- !ruby/object:Gem::Version
|
127
120
|
version: '0'
|
128
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
122
|
requirements:
|
131
123
|
- - ! '>='
|
132
124
|
- !ruby/object:Gem::Version
|
133
125
|
version: '0'
|
134
126
|
requirements: []
|
135
127
|
rubyforge_project:
|
136
|
-
rubygems_version:
|
128
|
+
rubygems_version: 2.0.14
|
137
129
|
signing_key:
|
138
|
-
specification_version:
|
130
|
+
specification_version: 4
|
139
131
|
summary: This library helps to execute code, locally or remote over ssh
|
140
132
|
test_files:
|
141
133
|
- spec/executable_spec.rb
|
data/.rbenv-gemsets
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
script_executor
|
data/.rbenv-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.9.3-p327
|