shells 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shells/shell_base.rb +2 -0
- data/lib/shells/ssh_session.rb +48 -28
- data/lib/shells/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79a5181a0a44f0f7f3f58fa2d8016e882e1a0a85
|
4
|
+
data.tar.gz: 93cac3a6699467509be0e4165fa21c91b727d77e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd579203b87620a7d14bf40a31dbbeb5e4d4c66f13ac8b0e93fdca5b19de39c67ac63c0054359a03ed26a740aede2e624604ed017ab5270a5fdc5859098cecc9
|
7
|
+
data.tar.gz: 40a853476c627024cb33386434f7b3d612078ada71fd81f80d7287f767812e1e9a32daf5bba58f1d92c4663a69c90fff87f71c76c69eef4eb50e69b17ba8af85
|
data/lib/shells/shell_base.rb
CHANGED
data/lib/shells/ssh_session.rb
CHANGED
@@ -32,7 +32,9 @@ module Shells
|
|
32
32
|
# resulting prompt can very easily become something else entirely. If they are provided, they will be
|
33
33
|
# replaced to protect the shell from getting stuck.
|
34
34
|
# +shell+::
|
35
|
-
# If set to :shell, then the default shell is executed.
|
35
|
+
# If set to :shell, then the default shell is executed. This is the default value.
|
36
|
+
# If set to :none, then no shell is executed, but a PTY is still created.
|
37
|
+
# If set to :no_pty, then no shell is executed and no PTY is created.
|
36
38
|
# If set to anything else, it is assumed to be the executable path to the shell you want to run.
|
37
39
|
# +quit+::
|
38
40
|
# If set, this defines the command to execute when quitting the session.
|
@@ -132,33 +134,38 @@ module Shells
|
|
132
134
|
# open the channel
|
133
135
|
debug 'Opening channel...'
|
134
136
|
@channel = ssh.open_channel do |ch|
|
135
|
-
#
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
137
|
+
# start buffering the channel output.
|
138
|
+
buffer_input
|
139
|
+
|
140
|
+
if options[:shell] == :no_pty
|
141
|
+
debug 'Executing session without PTY...'
|
142
|
+
|
143
|
+
ssh_exec_session &block
|
144
|
+
else
|
145
|
+
# request a PTY
|
146
|
+
debug 'Requesting PTY...'
|
147
|
+
ch.request_pty do |ch_pty, success_pty|
|
148
|
+
raise FailedToRequestPty unless success_pty
|
149
|
+
|
150
|
+
if options[:shell] == :none
|
151
|
+
debug 'Executing session without shell...'
|
152
|
+
|
153
|
+
ssh_exec_session &block
|
154
|
+
else
|
155
|
+
# pick a method to start the shell with.
|
156
|
+
meth = (options[:shell] == :shell) ? :send_channel_request : :exec
|
157
|
+
|
158
|
+
# start the shell
|
159
|
+
debug 'Starting shell...'
|
160
|
+
ch_pty.send(meth, options[:shell].to_s) do |ch_sh, success_sh|
|
161
|
+
raise FailedToStartShell unless success_sh
|
162
|
+
|
163
|
+
# give the shell a chance to get ready.
|
164
|
+
sleep 0.25
|
165
|
+
|
166
|
+
debug 'Executing session in shell...'
|
167
|
+
ssh_exec_session &block
|
168
|
+
end
|
162
169
|
end
|
163
170
|
end
|
164
171
|
end
|
@@ -225,5 +232,18 @@ module Shells
|
|
225
232
|
end
|
226
233
|
end
|
227
234
|
|
235
|
+
private
|
236
|
+
|
237
|
+
def ssh_exec_session(&block)
|
238
|
+
begin
|
239
|
+
block.call
|
240
|
+
ensure
|
241
|
+
# send the exit command.
|
242
|
+
ignore_io_error = true
|
243
|
+
debug 'Closing connection...'
|
244
|
+
send_data options[:quit] + line_ending
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
228
248
|
end
|
229
249
|
end
|
data/lib/shells/version.rb
CHANGED