sshez 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -7
- data/lib/sshez.rb +44 -13
- data/lib/sshez/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cec6ed214de47ce94ced8d951f0d17d5396b3281
|
4
|
+
data.tar.gz: 340865e6e375fe4389f3a7a2e2e2860e75bcf6e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef73d905d7aad616af3035a4e2efb4c7d391701aaacd1ee02afc813454794598a72faf9236bfe96a0f1fef2ce2aa5dbce40d36231020877b035bd90f9ba0bb61
|
7
|
+
data.tar.gz: 2c4d2dd8e939aecf1cfd5d78ecd331fa2d11fba4f1ad1fbab6be4eb17e5816c518f737f4e19b0aaafc5856b9758a55082feec367a5874488ea92aac08e1cba1b
|
data/README.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# Sshez
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/sshez.svg)](https://badge.fury.io/rb/sshez)
|
2
3
|
|
3
|
-
|
4
|
+
If you have multiple servers that you access on daily bases! sshez helps you configure your ssh/config file so you will never need to remember ip or ports again.
|
5
|
+
|
6
|
+
### Example
|
7
|
+
|
8
|
+
sshez mw_server root@74.125.224.72 -p 120
|
9
|
+
|
10
|
+
you will be able to use
|
11
|
+
|
12
|
+
ssh mw_server
|
13
|
+
|
4
14
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
15
|
|
7
16
|
## Installation
|
8
17
|
|
@@ -24,7 +33,7 @@ Or install it yourself as:
|
|
24
33
|
|
25
34
|
try sshez -h
|
26
35
|
|
27
|
-
Usage: sshez user@ip [options]
|
36
|
+
Usage: sshez aliase user@ip [options]
|
28
37
|
|
29
38
|
Specific options:
|
30
39
|
-p, --port PORT Specify a port
|
@@ -49,10 +58,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Gomaak
|
|
49
58
|
|
50
59
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
60
|
|
52
|
-
## Output
|
53
|
-
sshez where you don't have to remember your ips or deal with ssh config
|
54
|
-
|
55
|
-
Show version
|
56
61
|
|
57
62
|
|
58
63
|
## Missing
|
@@ -60,3 +65,8 @@ sshez where you don't have to remember your ips or deal with ssh config
|
|
60
65
|
* All the other options in [ssh documentation](http://linux.die.net/man/5/ssh_config)
|
61
66
|
* Add -r option to remove aliases
|
62
67
|
|
68
|
+
## Credit
|
69
|
+
|
70
|
+
Mohamed Ossama who gave me this idea
|
71
|
+
|
72
|
+
|
data/lib/sshez.rb
CHANGED
@@ -17,7 +17,7 @@ module Sshez
|
|
17
17
|
options = OpenStruct.new
|
18
18
|
|
19
19
|
opt_parser = OptionParser.new do |opts|
|
20
|
-
opts.banner = "Usage: sshez
|
20
|
+
opts.banner = "Usage: sshez alias (role@host|-r) [options]"
|
21
21
|
|
22
22
|
opts.separator ""
|
23
23
|
opts.separator "Specific options:"
|
@@ -75,27 +75,58 @@ module Sshez
|
|
75
75
|
file.close
|
76
76
|
end
|
77
77
|
output += "to #{file_path}\n"
|
78
|
+
output += "try ssh #{name} \n"
|
78
79
|
|
79
80
|
output
|
80
81
|
end
|
81
82
|
|
82
83
|
def self.form(name, user, host, options)
|
83
|
-
retuned =
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
retuned = "\n"
|
85
|
+
retuned += "Host #{name}\n"
|
86
|
+
retuned += " HostName #{host}\n"
|
87
|
+
retuned += " User #{user}\n"
|
88
|
+
|
87
89
|
if options.port
|
88
|
-
retuned +=
|
89
|
-
|
|
90
|
+
retuned += " Port #{options.port}\n"
|
90
91
|
end
|
91
92
|
|
92
93
|
if options.identity_file
|
93
|
-
retuned +=
|
94
|
-
|
|
94
|
+
retuned += " IdentityFile #{options.identity_file}\n"
|
95
95
|
end
|
96
96
|
retuned
|
97
97
|
|
98
98
|
end
|
99
|
+
|
100
|
+
def self.remove(name)
|
101
|
+
output = ""
|
102
|
+
started_removing = false
|
103
|
+
file_path = File.expand_path('~')+"/.ssh/config"
|
104
|
+
file = File.open(file_path, "r")
|
105
|
+
new_file = File.open(file_path+"temp", "w")
|
106
|
+
file.each do |line|
|
107
|
+
if line.include?("Host #{name}")|| started_removing
|
108
|
+
if started_removing && line.include?("Host ") && !line.include?(name)
|
109
|
+
started_removing = false
|
110
|
+
else
|
111
|
+
output += line
|
112
|
+
started_removing = true
|
113
|
+
end
|
114
|
+
else
|
115
|
+
new_file.write(line)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
file.close
|
119
|
+
new_file.close
|
120
|
+
File.delete(file_path)
|
121
|
+
File.rename(file_path+"temp", file_path)
|
122
|
+
|
123
|
+
if output.empty?
|
124
|
+
return "could not find host (#{name})"
|
125
|
+
else
|
126
|
+
return output
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
99
130
|
|
100
131
|
|
101
132
|
|
@@ -105,10 +136,12 @@ module Sshez
|
|
105
136
|
|
106
137
|
def process(args)
|
107
138
|
# parse the params to get the options
|
108
|
-
if (args.length < 2 || !args[1].include?("@"))
|
139
|
+
if (args.length < 2 || !args[1].include?("@") || args[0][0] == '-')
|
109
140
|
if args[0] == "-h"
|
110
141
|
Params.parse(args)
|
111
142
|
return nil
|
143
|
+
elsif ['-r', "--remove"].include?(args[1])
|
144
|
+
return ConfigFile.remove(args[0])
|
112
145
|
end
|
113
146
|
output = %Q|Invalid input
|
114
147
|
Use -h for help|
|
@@ -117,9 +150,7 @@ module Sshez
|
|
117
150
|
options = Params.parse(args)
|
118
151
|
|
119
152
|
|
120
|
-
|
121
|
-
"Not implemented :("
|
122
|
-
else
|
153
|
+
unless options.remove
|
123
154
|
user, host = args[1].split("@")
|
124
155
|
output = ConfigFile.append(args[0], user, host, options)
|
125
156
|
output + "Done!"
|
data/lib/sshez/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshez
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Immortal Friday
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|