hieb 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -2
- data/bin/hieb +3 -51
- data/lib/hieb.rb +60 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ff1ace9b37607d5a3884babe3d52704a13292b3b4de2ef7b1e33ffa8370aedf
|
4
|
+
data.tar.gz: f7732b5ab27aca53ae05b7289cd76aa82b62c2cf4eda16aab2fd102f4b8b9b8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13fc31580d0a1de8fd6f2466ec4fe7e804c84ddd8426836735a895a66436b332b579220b7d9bbcbd45301449db7271f6d4c5df1c90925187d5c2fa7b31b0795a
|
7
|
+
data.tar.gz: 89c1fa832be38f0b05a6810275b6970f091ca372f90d19d8ab55f5a84a4884840896cea204290d218c22be66aa203e97c0915e5b0cab4b46e01f7a916e04be3e
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ hieb 192.168.0.1 user ~/.ssh/id_rsa
|
|
20
20
|
|
21
21
|
Hieb is searching in the working directory for `_exe.json`. The content might look like this:
|
22
22
|
|
23
|
-
```
|
23
|
+
```json
|
24
24
|
{
|
25
25
|
"commands": [
|
26
26
|
"hostname",
|
@@ -47,7 +47,7 @@ _files/
|
|
47
47
|
|
48
48
|
## Remarks
|
49
49
|
|
50
|
-
Hieb is an extreme simple tool to execute commands and upload files using only SSH. It is by no mean a replacement for tools like Puppets, Chef, etc. The intention is to have a tool for one time deployments without complex dependencies. I always had the feeling most tools
|
50
|
+
Hieb is an extreme simple tool to execute commands and upload files using only SSH. It is by no mean a replacement for tools like Puppets, Chef, etc. The intention is to have a tool for one time deployments without complex dependencies. I always had the feeling that most tools are to complex for simple machine deployments.
|
51
51
|
|
52
52
|
To simplify the command execution you can add the following to your ```/etc/sudoers```:
|
53
53
|
|
data/bin/hieb
CHANGED
@@ -1,49 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'net/scp'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
DEFAULT_UPLOAD_DIR = '_files'
|
8
|
-
DEFAULT_EXE_FILE = '_exe.json'
|
3
|
+
require 'hieb'
|
9
4
|
|
10
5
|
HOST = ARGV[0]
|
11
6
|
USER = ARGV[1]
|
12
7
|
KEY = ARGV[2]
|
13
8
|
|
14
|
-
def ping ip
|
15
|
-
begin
|
16
|
-
r = `ping -c 1 -t1 -W1 #{ip} |grep packets`
|
17
|
-
r.match(/transmitted, (.*?) packets/)[1].to_i == 1
|
18
|
-
rescue
|
19
|
-
false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def exe(ssh, cmd)
|
24
|
-
puts "# #{cmd}"
|
25
|
-
ssh.exec!(cmd) do |channel, stream, data|
|
26
|
-
puts "#{data}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def upload(scp, file)
|
31
|
-
puts ">> UPLOAD: /#{file}"
|
32
|
-
scp.upload! "_files/#{file}", "/#{file}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def upload_dir(scp, dir)
|
36
|
-
Dir.foreach dir do |f1|
|
37
|
-
next if f1 =~ /^\.|\..$/
|
38
|
-
f2 = File.join(dir, f1)
|
39
|
-
if File.directory? f2
|
40
|
-
upload_dir scp, f2
|
41
|
-
else
|
42
|
-
upload scp, f2.sub!(/^#{DEFAULT_UPLOAD_DIR}\//, '')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
9
|
10.times do |i|
|
48
10
|
sleep 1
|
49
11
|
begin
|
@@ -52,16 +14,6 @@ end
|
|
52
14
|
end
|
53
15
|
end
|
54
16
|
|
55
|
-
|
56
|
-
Net::SCP.start(HOST, USER, :password => KEY, :keys => [ KEY ]) do |scp|
|
57
|
-
upload_dir scp, DEFAULT_UPLOAD_DIR
|
58
|
-
end if File.exist? DEFAULT_UPLOAD_DIR
|
17
|
+
upload_files(HOST, USER, KEY, DEFAULT_UPLOAD_DIR)
|
59
18
|
|
60
|
-
|
61
|
-
Net::SSH.start(HOST, USER, :password => KEY, :keys => [ KEY ]) do |ssh|
|
62
|
-
serialized = File.read(DEFAULT_EXE_FILE)
|
63
|
-
data = JSON.parse(serialized)
|
64
|
-
data['commands'].each do |cmd|
|
65
|
-
exe ssh, cmd
|
66
|
-
end
|
67
|
-
end if File.exist? DEFAULT_EXE_FILE
|
19
|
+
execute_commands(HOST, USER, KEY, DEFAULT_EXE_FILE)
|
data/lib/hieb.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'net/ssh'
|
4
|
+
require 'net/scp'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
DEFAULT_UPLOAD_DIR = '_files'
|
8
|
+
DEFAULT_EXE_FILE = '_exe.json'
|
9
|
+
|
10
|
+
def ping ip
|
11
|
+
begin
|
12
|
+
r = `ping -c 1 -t1 -W1 #{ip} |grep packets`
|
13
|
+
r.match(/transmitted, (.*?) packets/)[1].to_i == 1
|
14
|
+
rescue
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def exe(ssh, cmd)
|
20
|
+
puts "# #{cmd}"
|
21
|
+
ssh.exec!(cmd) do |channel, stream, data|
|
22
|
+
puts "#{data}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def upload(scp, file)
|
27
|
+
puts ">> UPLOAD: /#{file}"
|
28
|
+
scp.upload! "_files/#{file}", "/#{file}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def upload_dir(scp, dir)
|
32
|
+
Dir.foreach dir do |f1|
|
33
|
+
next if f1 =~ /^\.|\..$/
|
34
|
+
f2 = File.join(dir, f1)
|
35
|
+
if File.directory? f2
|
36
|
+
upload_dir scp, f2
|
37
|
+
else
|
38
|
+
upload scp, f2.sub!(/^#{DEFAULT_UPLOAD_DIR}\//, '')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def upload_files(host, user, key, upload_dir)
|
44
|
+
# Upload deploy files
|
45
|
+
Net::SCP.start(host, user, :password => key, :keys => [ key ]) do |scp|
|
46
|
+
upload_dir scp, upload_dir
|
47
|
+
end if File.exist? upload_dir
|
48
|
+
end
|
49
|
+
|
50
|
+
def execute_commands(host, user, key, exe_file)
|
51
|
+
# Execute commands
|
52
|
+
Net::SSH.start(host, user, :password => key, :keys => [ key ]) do |ssh|
|
53
|
+
serialized = File.read(exe_file)
|
54
|
+
data = JSON.parse(serialized)
|
55
|
+
data['commands'].each do |cmd|
|
56
|
+
exe ssh, cmd
|
57
|
+
end
|
58
|
+
end if File.exist? exe_file
|
59
|
+
end
|
60
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hieb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bovensiepen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -58,9 +58,10 @@ executables:
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
-
- bin/hieb
|
62
61
|
- LICENSE
|
63
62
|
- README.md
|
63
|
+
- bin/hieb
|
64
|
+
- lib/hieb.rb
|
64
65
|
homepage: https://github.com/bovi/hieb
|
65
66
|
licenses:
|
66
67
|
- MIT
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
version: '0'
|
82
83
|
requirements: []
|
83
84
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.7.3
|
85
86
|
signing_key:
|
86
87
|
specification_version: 4
|
87
88
|
summary: Simple deployment tool
|