jossh 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -14
- data/bin/jossh +2 -57
- data/lib/jossh/bin_handler.rb +77 -0
- data/lib/jossh/templates/docopt.txt +30 -0
- data/lib/jossh/templates/ssh_hosts.yml +21 -0
- data/lib/jossh/version.rb +1 -1
- data/lib/jossh.rb +1 -0
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44f63f279e57f3d0989f79931804f0c5739e1500
|
4
|
+
data.tar.gz: ab66d4c0dd2ce09933bec771b2bd62998039f214
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 810969e0823f92a77c6e3060b86a8cda94f8b9c02097db57ac2bbffed7273c3e949f9e98cc1847111025a8d69084a2e8b90bc0c394a647a5c9ac02c832e4ae1e
|
7
|
+
data.tar.gz: 721e0c004c4814567509951875c9d6f9270625a62412e770b8a18458bf59b04b59f7413256986aa1f9b7c9bffea06267dc70308f0549ca4cbaea2d2a0972dd67
|
data/README.md
CHANGED
@@ -40,24 +40,38 @@ After installing, you can call `jossh` from the command line to run arbitrary
|
|
40
40
|
commands or a local script over SSH.
|
41
41
|
|
42
42
|
```
|
43
|
-
$ jossh
|
43
|
+
$ jossh -h
|
44
44
|
|
45
|
-
|
46
|
-
jossh -h
|
45
|
+
Jossh
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
Usage:
|
48
|
+
jossh <host> <script>
|
49
|
+
jossh -m | --make-hostfile
|
50
|
+
jossh -h | --help
|
51
|
+
jossh -v | --version
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
Arguments:
|
54
|
+
<host>
|
55
|
+
can be:
|
56
|
+
- :symbol : in this case we will look in ./ssh_hosts.yml
|
57
|
+
- host : in this case we will use the current logged in user
|
58
|
+
- user@host
|
59
|
+
|
60
|
+
<script>
|
61
|
+
can be:
|
62
|
+
- a filename
|
63
|
+
- one or more direct command
|
64
|
+
|
65
|
+
Options:
|
66
|
+
-m --make-hostfile Generate a template ssh_hosts.yml
|
67
|
+
-h --help Show this screen
|
68
|
+
-v --version Show version
|
69
|
+
|
70
|
+
Examples:
|
71
|
+
jossh :production "git status"
|
72
|
+
jossh jack@server.com "cd ~ && ls -l"
|
73
|
+
jossh server.com deploy
|
57
74
|
|
58
|
-
Examples: jossh :production git status
|
59
|
-
jossh jack@server.com "cd ~ && ls -l"
|
60
|
-
jossh server.com deploy
|
61
75
|
|
62
76
|
```
|
63
77
|
|
@@ -127,4 +141,8 @@ ssh_hostfile "my_hosts.yml"
|
|
127
141
|
ssh! :myhost, 'ls'
|
128
142
|
```
|
129
143
|
|
144
|
+
You can ask Jossh to create a sample file for you by running:
|
145
|
+
|
146
|
+
$ jossh --make-hostfile
|
147
|
+
|
130
148
|
See [ssh_hosts.example.yml](https://github.com/DannyBen/jossh/blob/master/ssh_hosts.example.yml) as an example.
|
data/bin/jossh
CHANGED
@@ -1,62 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'jossh'
|
4
|
-
require 'etc'
|
5
|
-
|
6
|
-
# for dev (not needed in most cases)
|
7
|
-
# require File.dirname(__FILE__) + "/../lib/jossh"
|
8
|
-
|
9
4
|
trap(:INT) { abort "\r\nGoodbye" }
|
5
|
+
include Jossh
|
6
|
+
BinHandler.new.handle ARGV
|
10
7
|
|
11
|
-
def short_usage
|
12
|
-
"\nUsage: jossh <host> <script>\n" +
|
13
|
-
" jossh -h\n\n"
|
14
|
-
end
|
15
|
-
|
16
|
-
def usage
|
17
|
-
short_usage +
|
18
|
-
" <host> can be:\n"+
|
19
|
-
" - :symbol - in this case we will look in ./ssh_hosts.yml\n" +
|
20
|
-
" - host - in this case we will use the current logged in user\n" +
|
21
|
-
" - user@host\n\n" +
|
22
|
-
" <script> can be:\n" +
|
23
|
-
" - a filename\n" +
|
24
|
-
" - one or more direct command - quotes are only needed if you include\n" +
|
25
|
-
" multiple commands with && or semicolor (;)\n\n" +
|
26
|
-
"Examples: jossh :production git status\n" +
|
27
|
-
" jossh jack@server.com \"cd ~ && ls -l\"\n" +
|
28
|
-
" jossh server.com deploy"
|
29
|
-
end
|
30
|
-
|
31
|
-
def run
|
32
|
-
ARGV.empty? and abort short_usage
|
33
|
-
ARGV[0] == '-h' and abort usage
|
34
|
-
host = ARGV.shift.dup
|
35
|
-
script = ARGV.join ' '
|
36
|
-
host and script or abort short_usage
|
37
|
-
host = standardize_host host
|
38
|
-
begin
|
39
|
-
if File.exist? script
|
40
|
-
ssh_script! host, script
|
41
|
-
else
|
42
|
-
ssh host, script
|
43
|
-
end
|
44
|
-
rescue => e
|
45
|
-
abort e.message
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def standardize_host(str)
|
50
|
-
if str[0] == ':'
|
51
|
-
str[0] = ''
|
52
|
-
return str.to_sym
|
53
|
-
end
|
54
|
-
|
55
|
-
if str =~ /^(.+)@(.+)$/
|
56
|
-
return { user: $1, host: $2 }
|
57
|
-
end
|
58
|
-
|
59
|
-
return { user: Etc.getlogin, host: str }
|
60
|
-
end
|
61
|
-
|
62
|
-
run
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'etc'
|
2
|
+
require 'docopt'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Jossh
|
6
|
+
|
7
|
+
class BinHandler
|
8
|
+
|
9
|
+
def handle(args)
|
10
|
+
begin
|
11
|
+
execute Docopt::docopt(doc, argv: args)
|
12
|
+
rescue Docopt::Exit => e
|
13
|
+
puts e.message
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def execute(args)
|
20
|
+
return make_hostfile if args['--make-hostfile']
|
21
|
+
return show_version if args['--version']
|
22
|
+
handle_script args['<host>'].dup, args['<script>']
|
23
|
+
end
|
24
|
+
|
25
|
+
def handle_script(host, script)
|
26
|
+
host = standardize_host host
|
27
|
+
|
28
|
+
begin
|
29
|
+
if File.exist? script
|
30
|
+
ssh_script! host, script
|
31
|
+
else
|
32
|
+
ssh host, script
|
33
|
+
end
|
34
|
+
# :nocov:
|
35
|
+
rescue => e
|
36
|
+
abort e.message
|
37
|
+
end
|
38
|
+
# :nocov:
|
39
|
+
end
|
40
|
+
|
41
|
+
def standardize_host(str)
|
42
|
+
if str[0] == ':'
|
43
|
+
str[0] = ''
|
44
|
+
return str.to_sym
|
45
|
+
end
|
46
|
+
|
47
|
+
# :nocov:
|
48
|
+
# We DO have a test for these two cases, requires manual password type
|
49
|
+
if str =~ /^(.+)@(.+)$/
|
50
|
+
return { user: $1, host: $2 }
|
51
|
+
end
|
52
|
+
|
53
|
+
return { user: Etc.getlogin, host: str }
|
54
|
+
# :nocov:
|
55
|
+
end
|
56
|
+
|
57
|
+
def make_hostfile
|
58
|
+
abort "ssh_hosts.yml already exists" if File.exist?('ssh_hosts.yml')
|
59
|
+
FileUtils.copy template('ssh_hosts.yml'), './ssh_hosts.yml'
|
60
|
+
File.exist? './ssh_hosts.yml' or abort "Unable to create ssh_hosts.yml"
|
61
|
+
puts "Created ssh_hosts.yml"
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_version
|
65
|
+
puts VERSION
|
66
|
+
end
|
67
|
+
|
68
|
+
def doc
|
69
|
+
return @doc if @doc
|
70
|
+
@doc = File.read template 'docopt.txt'
|
71
|
+
end
|
72
|
+
|
73
|
+
def template(file)
|
74
|
+
File.expand_path("../templates/#{file}", __FILE__)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Jossh
|
2
|
+
|
3
|
+
Usage:
|
4
|
+
jossh <host> <script>
|
5
|
+
jossh -m | --make-hostfile
|
6
|
+
jossh -h | --help
|
7
|
+
jossh -v | --version
|
8
|
+
|
9
|
+
Arguments:
|
10
|
+
<host>
|
11
|
+
can be:
|
12
|
+
- :symbol : in this case we will look in ./ssh_hosts.yml
|
13
|
+
- host : in this case we will use the current logged in user
|
14
|
+
- user@host
|
15
|
+
|
16
|
+
<script>
|
17
|
+
can be:
|
18
|
+
- a filename
|
19
|
+
- one or more direct command
|
20
|
+
|
21
|
+
Options:
|
22
|
+
-m --make-hostfile Generate a template ssh_hosts.yml
|
23
|
+
-h --help Show this screen
|
24
|
+
-v --version Show version
|
25
|
+
|
26
|
+
Examples:
|
27
|
+
jossh :production "git status"
|
28
|
+
jossh jack@server.com "cd ~ && ls -l"
|
29
|
+
jossh server.com deploy
|
30
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# SSH Hosts File for Jossh
|
2
|
+
#
|
3
|
+
# Supports any of the attributes available in Net::SSH#start
|
4
|
+
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
5
|
+
#
|
6
|
+
# :host: and :user: are required, everything else is optional
|
7
|
+
#
|
8
|
+
|
9
|
+
:localhost:
|
10
|
+
:host: 'localhost'
|
11
|
+
:user: 'me'
|
12
|
+
|
13
|
+
:production:
|
14
|
+
:host: 'production.server.com'
|
15
|
+
:user: 'josh'
|
16
|
+
:port: 22
|
17
|
+
:timeout: 60
|
18
|
+
:passphrase: 'when using private key to prevent prompt'
|
19
|
+
:password: 'when using user/password'
|
20
|
+
:forward_agent: true
|
21
|
+
:use_agent: true
|
data/lib/jossh/version.rb
CHANGED
data/lib/jossh.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jossh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: docopt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.5'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,8 +134,11 @@ files:
|
|
120
134
|
- bin/jossh
|
121
135
|
- lib/jossh.rb
|
122
136
|
- lib/jossh/api.rb
|
137
|
+
- lib/jossh/bin_handler.rb
|
123
138
|
- lib/jossh/command_runner.rb
|
124
139
|
- lib/jossh/output_handler.rb
|
140
|
+
- lib/jossh/templates/docopt.txt
|
141
|
+
- lib/jossh/templates/ssh_hosts.yml
|
125
142
|
- lib/jossh/version.rb
|
126
143
|
homepage: https://github.com/DannyBen/jossh
|
127
144
|
licenses:
|