fulmar-shell 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 163cd665e5afb087113d0f5db20bc22ce723060f
4
+ data.tar.gz: 84b82d03fd5473f437ef8bb35ebf4691819733d4
5
+ SHA512:
6
+ metadata.gz: 7e970c4ae6bcd02b1c82c15314cb31ae754eee8b4ba89979dacc0a059a902c6b24223aa5a3f601fa6a0ea6c9535603d14157da1957b8df7754cacd179c7d016e
7
+ data.tar.gz: 82013e50a32a6170d0d1cdf73dfb9fdbf9290dfed86ecf905b3e6b9bf9bf53c035e4857cf690ebfbc71e50ac1e172028d5e9f17ebdd0cb67f7c93df5f4acc8b9
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.gem
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fulmar_shell.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Gerrit Visscher
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Fulmar Shell
2
+
3
+ This service takes a directory and a hostname (which might be 'localhost'). It then runs all commands given
4
+ in the given directory on that machine. You can access the return values and the output on both stdout and stderr.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'fulmar-shell', :git => 'https://github.com/CORE4/fulmar-shell.git'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ git clone https://github.com/CORE4/fulmar-shell.git
21
+ $ cd fulmar-shell
22
+ $ gem build fulmar-shell.gemspec
23
+ $ gem install fulmar-shell-#.#.#.gem
24
+
25
+ ## Usage
26
+
27
+ You can test the shell in irb:
28
+
29
+ $ irb -r fulmar-shell
30
+
31
+ And get a new shell object with
32
+
33
+ irb(main):001:0> shell = Fulmar::Shell.new '.'
34
+
35
+ Shell.new takes two parameters: a directory (this is mandatory) and a hostname which is configured for
36
+ access via ssh with key authentication (i.e. does not require a password). You can supply a username with
37
+ 'my-user@my-host'.
38
+ All commands will be executed in the given directory, which is the current directory in the example above.
39
+
40
+ irb(main):002:0> shell.run 'echo Hello World'
41
+
42
+ This will run echo and return true/false depending on the return code of the command. Currently, you cannot
43
+ access the return code directly. You can, however, get the output of the last command(s):
44
+
45
+ irb(main):003:0> shell.last_output
46
+ => ["Hello World"]
47
+
48
+ And of course the last error messages:
49
+
50
+ irb(main):004:0> shell.run 'echo Hello World 1>&2'
51
+ Hello World
52
+ => true
53
+ irb(main):005:0> shell.last_error
54
+ => ["Hello World"]
55
+
56
+ If you want to run multiple commands, you can supply them as an array. This is especially recommended if
57
+ you work on a remote shell since it will only connect once and chain all commands (with an "&&", so the first
58
+ failure will stop the execution of the list).
59
+
60
+ irb(main):006:0> shell.run ['echo foo', 'echo bar', 'test -f non_existing_file', 'echo Hidden']
61
+ => false
62
+ irb(main):007:0> shell.last_output
63
+ => ["foo", "bar"]
64
+
65
+ You can see that it stopped after the third command. You get the output of all commands before that.
66
+
67
+ If you activate the debug output, you can see which commands are executed:
68
+
69
+ irb(main):008:0> shell.run ["echo 'in single quotes'", "echo \"in double quotes\""]
70
+ sh -c 'cd . && echo '\''in single quotes'\'' && echo "in double quotes"'
71
+ => true
72
+
73
+ The commands will always be run in /bin/sh. Single quotes will be escaped and if you run this on a remote shell,
74
+ it will escape them twice which might look weird. :)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fulmar/shell'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fulmar-shell'
8
+ spec.version = Fulmar::Shell::VERSION
9
+ spec.authors = ['Gerrit Visscher']
10
+ spec.email = ['g.visscher@core4.de']
11
+
12
+ # if spec.respond_to?(:metadata)
13
+ # spec.metadata['allowed_push_host'] = 'TODO: Set to \'http://mygemserver.com\' to prevent pushes to rubygems.org, or delete to allow pushes to any server.'
14
+ # end
15
+
16
+ spec.summary = 'Small service to run shell commands on a local or remote shell'
17
+ spec.description = 'This service takes a directory and a hostname (which might be \'localhost\'). It then runs all commands given in the given directory on that machine.'
18
+ spec.homepage = 'https://github.com/CORE4/fulmar-shell'
19
+ spec.license = 'MIT'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }
22
+ spec.bindir = 'bin'
23
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.8'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ end
@@ -0,0 +1,64 @@
1
+ require 'open3'
2
+
3
+ # This shell is part of the fulmar deployment tools
4
+ # it can be used stand-alone, though
5
+ module Fulmar
6
+ # Implements simple access to shell commands
7
+ class Shell
8
+ VERSION = '1.1.2'
9
+
10
+ attr_accessor :debug, :last_output, :last_error, :quiet
11
+
12
+ def initialize(path, host = 'localhost')
13
+ @path = (path.nil? || path.empty?) ? '.' : path
14
+ @host = host
15
+ @last_output = []
16
+ @last_error = []
17
+ @debug = false
18
+ @quiet = false
19
+ end
20
+
21
+ def run(command)
22
+ command = [command] if command.class == String
23
+
24
+ command.unshift "cd #{@path}"
25
+
26
+ if local?
27
+ execute("sh -c '#{escape_for_sh(command.join(' && '))}'")
28
+ else
29
+ remote_command = escape_for_sh('/bin/sh -c \'' + escape_for_sh(command.join(' && ')) + '\'')
30
+ execute("ssh #{@host} '#{remote_command}'")
31
+ end
32
+ end
33
+
34
+ def local?
35
+ @host == 'localhost'
36
+ end
37
+
38
+ protected
39
+
40
+ # Run the command and capture the output
41
+ def execute(command)
42
+ # DEBUG, baby!
43
+ puts command if @debug
44
+
45
+ stdin, stdout, stderr, wait_thr = Open3.popen3(command)
46
+
47
+ # Remove annoying newlines at the end
48
+ @last_output = stdout.readlines.collect(&:chomp)
49
+ @last_error = stderr.readlines.collect(&:chomp)
50
+
51
+ stdin.close
52
+ stdout.close
53
+ stderr.close
54
+
55
+ @last_error.each { |line| puts line } unless @quiet
56
+
57
+ wait_thr.value == 0
58
+ end
59
+
60
+ def escape_for_sh(text)
61
+ text.gsub('\\', '\\\\').gsub("'", "'\\\\''")
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fulmar-shell
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Gerrit Visscher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This service takes a directory and a hostname (which might be 'localhost').
42
+ It then runs all commands given in the given directory on that machine.
43
+ email:
44
+ - g.visscher@core4.de
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - fulmar-shell.gemspec
55
+ - lib/fulmar/shell.rb
56
+ homepage: https://github.com/CORE4/fulmar-shell
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Small service to run shell commands on a local or remote shell
80
+ test_files: []