bleetz 1.0
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.
- data/LICENSE.txt +24 -0
- data/bin/bleetz +5 -0
- data/lib/bleetz.rb +149 -0
- data/lib/bleetz/conf.rb +50 -0
- data/lib/bleetz/object.rb +3 -0
- metadata +84 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
* Copyright (c) 2012, Thibaut Deloffre
|
2
|
+
* All rights reserved.
|
3
|
+
* Redistribution and use in source and binary forms, with or without
|
4
|
+
* modification, are permitted provided that the following conditions are met:
|
5
|
+
*
|
6
|
+
* * Redistributions of source code must retain the above copyright
|
7
|
+
* notice, this list of conditions and the following disclaimer.
|
8
|
+
* * Redistributions in binary form must reproduce the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer in the
|
10
|
+
* documentation and/or other materials provided with the distribution.
|
11
|
+
* * Neither the name of RocknRoot nor the names of its contributors may
|
12
|
+
* be used to endorse or promote products derived from this software
|
13
|
+
* without specific prior written permission.
|
14
|
+
*
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
|
16
|
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
|
19
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/bin/bleetz
ADDED
data/lib/bleetz.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'yaml'
|
4
|
+
require 'bleetz/conf.rb'
|
5
|
+
require 'bleetz/object.rb'
|
6
|
+
|
7
|
+
class Bleetz
|
8
|
+
|
9
|
+
VERSION = "1.0"
|
10
|
+
|
11
|
+
USAGE = <<-EOF
|
12
|
+
Usage: bleetz [-c conf_file -h -l -s][[-t -v -c conf_file] task]
|
13
|
+
|
14
|
+
-c <conf_file> - Specify a special bleetz configuration file.
|
15
|
+
-h - Help.
|
16
|
+
-l - List available task(s) defined in bleetz configuration file.
|
17
|
+
-s - Test ssh connection defined in bleetz conf.
|
18
|
+
-t <task_name> - Test tasks (just print command that will be executed.
|
19
|
+
-v - Verbose Mode.
|
20
|
+
-V - Print bleetz version.
|
21
|
+
EOF
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
arg_get
|
25
|
+
@cmd_to_exec = []
|
26
|
+
begin
|
27
|
+
if @file.nil?
|
28
|
+
cnf = YAML::load(File.open("#{Dir.pwd}/.bleetz"))
|
29
|
+
@file = cnf[:config] || cnf['config']
|
30
|
+
end
|
31
|
+
load @file
|
32
|
+
rescue Exception => e
|
33
|
+
abort "Problem during configuration loading: #{e.message}"
|
34
|
+
end
|
35
|
+
list if @list
|
36
|
+
test_ssh if @ssh_test
|
37
|
+
abort "You need to specify a task." if @action.nil?
|
38
|
+
format_cmds
|
39
|
+
test if @test
|
40
|
+
connect
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def arg_get
|
46
|
+
@help = false
|
47
|
+
if ARGV.empty?
|
48
|
+
usage
|
49
|
+
end
|
50
|
+
@file = nil
|
51
|
+
@test = @ssh_test = @list = @verbose = false
|
52
|
+
loop {
|
53
|
+
case ARGV[0]
|
54
|
+
when '-t'
|
55
|
+
ARGV.shift; @test = true
|
56
|
+
when '-s'
|
57
|
+
ARGV.shift; @ssh_test = true
|
58
|
+
when '-l'
|
59
|
+
ARGV.shift; @list = true
|
60
|
+
when '-v'
|
61
|
+
ARGV.shift; @verbose = true
|
62
|
+
when '-V'
|
63
|
+
ARGV.shift; version
|
64
|
+
when '-c'
|
65
|
+
ARGV.shift; @file = ARGV.shift
|
66
|
+
when '-h'
|
67
|
+
@help = true; usage
|
68
|
+
when /^-/
|
69
|
+
@help = false; puts("Unknown option: #{ARGV[0].inspect}"); usage
|
70
|
+
else
|
71
|
+
break
|
72
|
+
end
|
73
|
+
}
|
74
|
+
@action = ARGV.shift if !ARGV[0].nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def format_cmds(action = @action)
|
78
|
+
abort "Unknown task: '#{action}'." unless @@actions.include?(action.to_sym)
|
79
|
+
@@actions[action.to_sym].each { |c|
|
80
|
+
if c.is_a? Symbol
|
81
|
+
abort "Undefined task: :#{c}. You have to define it." unless @@tasks.include?(c)
|
82
|
+
format_cmds(c)
|
83
|
+
else
|
84
|
+
@cmd_to_exec << c
|
85
|
+
end
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def list
|
90
|
+
puts "Available tasks:"
|
91
|
+
@@tasks.each { |k,v|
|
92
|
+
desc = (v.empty? ? "No desc" : v)
|
93
|
+
puts "#{k}: #{desc}"
|
94
|
+
}
|
95
|
+
exit(0)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test
|
99
|
+
puts "Simulation, command printing without SSH. No excution."
|
100
|
+
@cmd_to_exec.each { |c| puts c }
|
101
|
+
exit(0)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_ssh
|
105
|
+
puts "Test SSH connection:"
|
106
|
+
connect
|
107
|
+
puts "SSH connection: SUCCES"
|
108
|
+
exit(0)
|
109
|
+
end
|
110
|
+
|
111
|
+
def connect
|
112
|
+
abort "You have to configure SSH options." if @@options.empty?
|
113
|
+
begin
|
114
|
+
Timeout::timeout(@@options.delete(:timeout) || 10) {
|
115
|
+
Net::SSH.start(@@options.delete(:host), @@options.delete(:username), @@options) { |ssh|
|
116
|
+
if !@cmd_to_exec.empty?
|
117
|
+
@cmd_to_exec.each { |command|
|
118
|
+
output = ssh.exec!(command)
|
119
|
+
puts output if @verbose
|
120
|
+
}
|
121
|
+
end
|
122
|
+
}
|
123
|
+
}
|
124
|
+
rescue NotImplementedError => e
|
125
|
+
abort "SSH error: #{e.message}"
|
126
|
+
rescue Net::SSH::HostKeyMismatch => e
|
127
|
+
e.remember_host!
|
128
|
+
retry
|
129
|
+
rescue Net::SSH::AuthenticationFailed => e
|
130
|
+
abort "SSH auth failed: #{e.message}"
|
131
|
+
rescue StandardError => e
|
132
|
+
abort "SSH connection error: #{e.to_s}"
|
133
|
+
rescue Timeout::Error
|
134
|
+
abort "Timed out trying to get a connection."
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def usage
|
139
|
+
puts USAGE
|
140
|
+
@help ? exit(0) : exit(1)
|
141
|
+
end
|
142
|
+
|
143
|
+
def version
|
144
|
+
puts "bleetz version #{VERSION}. Fuck yeah !"
|
145
|
+
exit(0)
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
data/lib/bleetz/conf.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Conf
|
2
|
+
|
3
|
+
@@actions = {}
|
4
|
+
@@tasks = {}
|
5
|
+
@@options = {}
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def task(action, desc = "")
|
12
|
+
check_main_call(:task)
|
13
|
+
@cmds = []
|
14
|
+
yield
|
15
|
+
h = { action.to_sym => @cmds }
|
16
|
+
t = { action.to_sym => desc.to_s }
|
17
|
+
@@actions = @@actions.merge(h)
|
18
|
+
@@tasks = @@tasks.merge(t)
|
19
|
+
end
|
20
|
+
|
21
|
+
def shell(cmd)
|
22
|
+
check_sub_call(:shell)
|
23
|
+
raise "'shell' needs a String as parameter." unless cmd.is_a? String
|
24
|
+
@cmds << cmd
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(task)
|
28
|
+
check_sub_call(:call)
|
29
|
+
raise "'call :task_name'. You didn't pass a Symbol." unless task.is_a? Symbol
|
30
|
+
@cmds << task
|
31
|
+
end
|
32
|
+
|
33
|
+
def set(opt, value)
|
34
|
+
check_main_call(:set)
|
35
|
+
@@options[opt.to_sym] = value
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def check_main_call(func)
|
41
|
+
method = caller[2][/`([^']*)'/, 1]
|
42
|
+
raise "Main configuration function, you cannot call '#{func}' it in '#{method}'." unless method.eql?("load")
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_sub_call(func)
|
46
|
+
method = caller[2][/`([^']*)'/, 1]
|
47
|
+
raise "'#{func}' has to be called in 'task'." unless method.eql?("task")
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bleetz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thibaut Deloffre
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: highline
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: net-ssh
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Fast KISS deployment tool
|
47
|
+
email: tib@rocknroot.org
|
48
|
+
executables:
|
49
|
+
- bleetz
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE.txt
|
53
|
+
files:
|
54
|
+
- lib/bleetz.rb
|
55
|
+
- lib/bleetz/conf.rb
|
56
|
+
- lib/bleetz/object.rb
|
57
|
+
- LICENSE.txt
|
58
|
+
- bin/bleetz
|
59
|
+
homepage: https://github.com/TibshoOT/bleetz
|
60
|
+
licenses:
|
61
|
+
- BSD
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.24
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Fast KISS deployment tool
|
84
|
+
test_files: []
|