hieb 0.0.1

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +1 -0
  4. data/bin/hieb.rb +61 -0
  5. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0abdb59809a09921df4484ff5ea8e304c95f0e41
4
+ data.tar.gz: 305fc8ebd10b7c21b365afe215a0781bda9da195
5
+ SHA512:
6
+ metadata.gz: 0cad7c534f611b4d991185828357b6554e7773c13d34773d1a273812d867015a0eba55a55ab7011f0aedbff86d7e3fe5c8e3d81a29494afc5d9ee9b724e688a3
7
+ data.tar.gz: 44a07b5cad55c728546dff88ce6f17f7386162c80d7ee93b2d4209d9b4d57121c3784dcd78158aa86bfb19dd3df72e5d03cbf7a0bfb0d11b01a879f82a94405e
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Daniel Bovensiepen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # hieb
data/bin/hieb.rb ADDED
@@ -0,0 +1,61 @@
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
+ HOST = ARGV[0]
11
+ USER = ARGV[1]
12
+ KEY = ARGV[2]
13
+
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
+ raise 'Host not reachable' unless ping HOST
48
+
49
+ # Upload deploy files
50
+ Net::SCP.start(HOST, USER, :password => KEY, :keys => [ KEY ]) do |scp|
51
+ upload_dir scp, DEFAULT_UPLOAD_DIR
52
+ end if File.exist? DEFAULT_UPLOAD_DIR
53
+
54
+ # Execute commands
55
+ Net::SSH.start(HOST, USER, :password => KEY, :keys => [ KEY ]) do |ssh|
56
+ serialized = File.read(DEFAULT_EXE_FILE)
57
+ data = JSON.parse(serialized)
58
+ data['commands'].each do |cmd|
59
+ exe ssh, cmd
60
+ end
61
+ end if File.exist? DEFAULT_EXE_FILE
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hieb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Bovensiepen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple deployment tool using SSH and supporting command execution and
14
+ file upload
15
+ email: daniel@bovensiepen.net
16
+ executables:
17
+ - hieb.rb
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/hieb.rb
22
+ - LICENSE
23
+ - README.md
24
+ homepage: https://github.com/bovi/hieb
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.0.14.1
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Simple deployment tool
48
+ test_files: []