shells 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84290cfa99c45a5ed364ed2768d33bd53065efa6
4
- data.tar.gz: bf1b5abab47b36aaf979578203b650ca2ed750c1
3
+ metadata.gz: ff3218a25e2f8801926946df4d8f1d5c99cd4485
4
+ data.tar.gz: c882cd4c588766c21dd819817c22d8a9dd2db154
5
5
  SHA512:
6
- metadata.gz: 246b734e106f7b40d4de02278a8a5f66f0191bb1341b92e68990d120ca23fb712d1aacb85dbb35c12c1856fe57f990b156f349d3f70f196db3ee50eb0cb24d66
7
- data.tar.gz: f5f99c98cbbdd287442e65fd9f371a3ce761047a64dc8b779616b5efcc65cd2c7a0187ff915ae435014509f25ce90d06c2898b35031a59aa999ec406eb221b78
6
+ metadata.gz: 6fcb625d9d48f2096a858326e5430555527d9956bda1747fb7fafc2911b73c6cb8b5fc5de0d0e5c6989ca7457b9d239183b7793cc20c0ba1009fe1ecc50a00ed
7
+ data.tar.gz: 5738c4d03f81e93b05806bd8ff76933afc37110ed53e4e826550771bb21c78b59be97d0e33aa4aa06d59f9a5686a779ec114b9a6fc7552f5c8f55c582fff6e4f
data/.gitignore CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
@@ -35,6 +35,36 @@ module Shells
35
35
  end
36
36
  end
37
37
 
38
+ ##
39
+ # Executes an elevated command using the 'sudo' command.
40
+ def sudo_exec(command, options = {}, &block)
41
+ sudo_prompt = '[sp:'
42
+ sudo_match = /[\r\n]\[sp:$/
43
+ sudo_strip = /\[sp:[^\n]*\n/
44
+ ret = exec("sudo -p \"#{sudo_prompt}\" bash -c \"#{command.gsub('"', '\\"')}\"", options) do |data,type|
45
+ test_data = data.to_s
46
+ desired_length = sudo_prompt.length + 1 # prefix a NL before the prompt.
47
+
48
+ # pull from the current stdout to get the full test data, but only if we received some new data.
49
+ if test_data.length > 0 && test_data.length < desired_length
50
+ test_data = stdout[-desired_length..-1].to_s
51
+ end
52
+
53
+ if test_data =~ sudo_match
54
+ options[:password]
55
+ else
56
+ if block
57
+ block.call(data, type)
58
+ else
59
+ nil
60
+ end
61
+ end
62
+ end
63
+ # remove the sudo prompts.
64
+ ret.gsub(sudo_strip, '')
65
+ end
66
+
67
+
38
68
  protected
39
69
 
40
70
  ##
data/lib/shells/errors.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -404,6 +404,7 @@ module Shells
404
404
  last_exit_code
405
405
  end
406
406
 
407
+
407
408
  ##
408
409
  # Reads from a file on the device.
409
410
  def read_file(path)
@@ -22,7 +22,8 @@ module Shells
22
22
  # The user to login with. This option is required.
23
23
  # +password+::
24
24
  # The password to login with.
25
- # If our public key is an authorized key on the host, the password is ignored.
25
+ # If our public key is an authorized key on the host, the password is ignored for connection.
26
+ # The #sudo_exec method for bash-like shells will also use this password for elevation.
26
27
  # +prompt+::
27
28
  # The prompt used to determine when processes finish execution.
28
29
  # Defaults to '~~#', but if that doesn't work for some reason because it is valid output from one or more
@@ -1,5 +1,5 @@
1
1
  module Shells
2
2
  ##
3
3
  # The current version of the gem.
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
data/lib/shells.rb CHANGED
File without changes
data/shells.gemspec CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shells
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beau Barker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-22 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh