paratele 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/paratele +140 -0
  2. data/paratele.gemspec +2 -2
  3. metadata +3 -2
data/bin/paratele ADDED
@@ -0,0 +1,140 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ help = File.expand_path(File.join("..", "README"), File.dirname(__FILE__))
4
+
5
+ if ARGV.empty?
6
+ exec "less #{help}"
7
+ end
8
+
9
+ require "clap"
10
+ require "json"
11
+ require "open3"
12
+
13
+ def path(*parts)
14
+ File.expand_path(File.join(*parts), ENV["TELE_HOME"])
15
+ end
16
+
17
+ def ssh(server, script)
18
+ out, status = Open3.capture2e("ssh -T -F #{path("ssh_config")} #{server} < #{script}")
19
+ [out, status.exitstatus]
20
+ end
21
+
22
+ def layout
23
+ $layout ||= JSON.parse(File.read(path("layout.json")))
24
+ end
25
+
26
+ def servers
27
+ layout["servers"]
28
+ end
29
+
30
+ def recipe_script(recipe, command)
31
+ path("recipes", recipe, "#{command}.sh")
32
+ end
33
+
34
+ def run(server, recipe, command)
35
+ script = recipe_script(recipe, command)
36
+
37
+ if File.exist?(script)
38
+ ssh(server, script)
39
+ end
40
+ end
41
+
42
+ out = Module.new do
43
+ def self.server(name)
44
+ puts name
45
+ end
46
+
47
+ def self.error
48
+ puts "\033[01;31mERROR\033[00m"
49
+ end
50
+
51
+ def self.ok
52
+ puts "\033[01;32mOK\033[00m"
53
+ end
54
+
55
+ def self.missing
56
+ puts "\033[01;33mMISSING\033[00m"
57
+ end
58
+
59
+ def self.done
60
+ puts "\033[01;32mDONE\033[00m"
61
+ end
62
+
63
+ def self.unknown
64
+ puts "?"
65
+ end
66
+ end
67
+
68
+ ###
69
+
70
+ ENV["TELE_HOME"] ||= File.join(Dir.pwd, ".tele")
71
+
72
+ verbosity = 1
73
+
74
+ commands = Clap.run ARGV,
75
+ "-h" => lambda {
76
+ exec "less #{help}"
77
+ },
78
+ "-q" => lambda {
79
+ verbosity = 0
80
+ },
81
+ "-v" => lambda {
82
+ verbosity = 2
83
+ },
84
+ "-d" => lambda {|path|
85
+ ENV["TELE_HOME"] = File.join(Dir.pwd, path)
86
+ }
87
+
88
+ Clap.run commands,
89
+ "init" => lambda {
90
+ source = File.expand_path("../templates/.tele", File.dirname(__FILE__))
91
+ target = File.expand_path(Dir.pwd)
92
+
93
+ %x{cp -r #{source} #{target}}
94
+ out.done
95
+ }
96
+
97
+ unless File.directory?(path)
98
+ $stderr.puts "Couldn't find a .tele directory"
99
+ exit 1
100
+ end
101
+
102
+ Clap.run commands,
103
+ "run" => lambda {|command|
104
+ if commands.size == 3
105
+ selected = commands.last.split(",")
106
+ servers.select! {|server| selected.include?(server)}
107
+ end
108
+
109
+ exit_status = 0
110
+
111
+ servers.each do |server, recipes|
112
+ out.server(server)
113
+
114
+ recipes.each do |recipe|
115
+ print " #{recipe}: "
116
+
117
+ if File.exists?(path("recipes", recipe))
118
+ stdout, status = run(server, recipe, command)
119
+
120
+ case status
121
+ when nil
122
+ out.unknown
123
+ when 0
124
+ out.ok
125
+ $stderr.print stdout if verbosity >= 2
126
+ else
127
+ out.error
128
+ $stderr.print stdout if verbosity >= 1
129
+ exit_status = 1
130
+ break
131
+ end
132
+ else
133
+ out.unknown
134
+ exit 1
135
+ end
136
+ end
137
+ end
138
+
139
+ exit exit_status
140
+ }
data/paratele.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "paratele"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.summary = "Provisioning at a distance"
5
5
  s.description = "Tele is a small provisioning framework that allows you to run bash scripts on remote servers over SSH."
6
6
  s.authors = ["Damian Janowski", "Michel Martens"]
@@ -11,5 +11,5 @@ Gem::Specification.new do |s|
11
11
 
12
12
  s.add_dependency("clap")
13
13
 
14
- s.files = ["LICENSE", "README", "Rakefile", "bin/tele", "templates/.tele/layout.json", "templates/.tele/ssh_config", "paratele.gemspec", "tele.gemspec", "test/tele.rb"]
14
+ s.files = ["LICENSE", "README", "Rakefile", "bin/paratele", "bin/tele", "templates/.tele/layout.json", "templates/.tele/ssh_config", "paratele.gemspec", "tele.gemspec", "test/tele.rb"]
15
15
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Damian Janowski
@@ -45,6 +45,7 @@ files:
45
45
  - LICENSE
46
46
  - README
47
47
  - Rakefile
48
+ - bin/paratele
48
49
  - bin/tele
49
50
  - templates/.tele/layout.json
50
51
  - templates/.tele/ssh_config