cupper 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +16 -0
- data/Gemfile +18 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/bin/cupper +1 -1
- data/cupper.gemspec +28 -0
- data/lib/cupper.rb +18 -1
- data/lib/cupper/cli.rb +63 -0
- data/lib/cupper/collect.rb +51 -0
- data/lib/cupper/cookbook.rb +71 -0
- data/lib/cupper/cookbook_file.rb +10 -0
- data/lib/cupper/cupperfile.rb +22 -0
- data/lib/cupper/entity.rb +63 -0
- data/lib/cupper/environment.rb +177 -0
- data/lib/cupper/errors.rb +84 -0
- data/lib/cupper/ohai_plugins.rb +13 -0
- data/lib/cupper/platform_collector.rb +40 -0
- data/lib/cupper/plugins/cupper/arch.rb +43 -0
- data/lib/cupper/plugins/cupper/debian.rb +48 -0
- data/lib/cupper/plugins/ohai/dpci.rb +30 -0
- data/lib/cupper/plugins/ohai/files.rb +68 -0
- data/lib/cupper/plugins/ohai/init_system.rb +14 -0
- data/lib/cupper/plugins/ohai/pacman.rb +31 -0
- data/lib/cupper/plugins/ohai/pkg_deps.rb +30 -0
- data/lib/cupper/plugins/ohai/pkg_manager.rb +31 -0
- data/lib/cupper/plugins/ohai/services.rb +20 -0
- data/lib/cupper/project.rb +40 -0
- data/lib/cupper/recipe.rb +240 -0
- data/lib/cupper/templates/CupperFile.erb +1 -0
- data/lib/cupper/templates/_cookbook_file.erb +9 -0
- data/lib/cupper/templates/_groups.erb +10 -0
- data/lib/cupper/templates/_links.erb +10 -0
- data/lib/cupper/templates/_package.erb +19 -0
- data/lib/cupper/templates/_services.erb +7 -0
- data/lib/cupper/templates/_templates.erb +11 -0
- data/lib/cupper/templates/_users.erb +10 -0
- data/lib/cupper/templates/cookbook_file.erb +1 -0
- data/lib/cupper/templates/recipe.erb +7 -0
- data/lib/cupper/version.rb +3 -0
- data/templates/locales/en.yml +17 -0
- metadata +125 -8
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
Ohai.plugin(:Pacman) do
|
3
|
+
provides 'pacman'
|
4
|
+
|
5
|
+
def from_cmd(cmd)
|
6
|
+
so = shell_out(cmd)
|
7
|
+
so.stdout.lines
|
8
|
+
end
|
9
|
+
|
10
|
+
def extract_dependencies(pkg)
|
11
|
+
pkg_infos = from_cmd("pacman -Qi #{pkg}")
|
12
|
+
infos = pkg_infos.stdout.lines
|
13
|
+
infos.each do |info|
|
14
|
+
info.slice! /Depends On\s+:/ if info.include? "Depends On"
|
15
|
+
end
|
16
|
+
info
|
17
|
+
end
|
18
|
+
|
19
|
+
collect_data(:default) do
|
20
|
+
pacman Mash.new
|
21
|
+
pkgs = from_cmd('pacman -Q')
|
22
|
+
|
23
|
+
pkgs.each do |pkg|
|
24
|
+
name, version = pkg.split
|
25
|
+
pacman[name] = {
|
26
|
+
"version" => version,
|
27
|
+
"dependecies" => info,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Ohai.plugin(:PkgDeps) do
|
2
|
+
provides 'pkg_deps'
|
3
|
+
depends 'platform_family'
|
4
|
+
|
5
|
+
def from_cmd(cmd)
|
6
|
+
so = shell_out(cmd)
|
7
|
+
so.stdout.lines
|
8
|
+
end
|
9
|
+
|
10
|
+
def all_packages
|
11
|
+
if %w{debian}.include? platform_family
|
12
|
+
from_cmd("dpkg-query -W")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def extract_dependecies(pkg)
|
17
|
+
pkg_infos = from_cmd("apt-cache showpkg #{pkg}")
|
18
|
+
pkg_infos.keep_if { |item| item.strip!.match(/^Depends:/)}
|
19
|
+
pkg_infos.each { |item| item.slice!("Depends: ") }
|
20
|
+
end
|
21
|
+
|
22
|
+
collect_data(:linux) do
|
23
|
+
pkg_deps Mash.new
|
24
|
+
if %w{debian}.include? platform_family
|
25
|
+
all_packages.each do |pkg|
|
26
|
+
pkg_deps[pkg.split.first] = extract_dependecies(pkg.split.first)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
Ohai.plugin(:PkgManager) do
|
3
|
+
provides 'pkg_manager'
|
4
|
+
|
5
|
+
def return_version(cmd)
|
6
|
+
out = shell_out("#{cmd} || true")
|
7
|
+
value out.stdout.strip
|
8
|
+
value.match(/(\d+\.)(\d+\.)(\d+)/)
|
9
|
+
end
|
10
|
+
|
11
|
+
collect_data(:linux) do
|
12
|
+
pkg_manager Mash.new
|
13
|
+
|
14
|
+
# HACK: it may be a better way to collect the default pkg manages
|
15
|
+
DEFAULT_PKG_MANAGES = [
|
16
|
+
'pacman',
|
17
|
+
'dpkg',
|
18
|
+
'apt',
|
19
|
+
'gem',
|
20
|
+
'pip',
|
21
|
+
'pip3',
|
22
|
+
]
|
23
|
+
|
24
|
+
DEFAULT_PKG_MANAGES.each do |manager|
|
25
|
+
pkg_manager[manager] = {
|
26
|
+
"version" => return_version("#{manager} --version")
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Ohai.plugin(:Services) do
|
2
|
+
provides 'services'
|
3
|
+
|
4
|
+
def from_cmd(cmd)
|
5
|
+
so = shell_out(cmd)
|
6
|
+
so.stdout.lines
|
7
|
+
end
|
8
|
+
|
9
|
+
collect_data(:default) do
|
10
|
+
services Mash.new
|
11
|
+
srvs from_cmd('systemctl list-units | grep loaded | grep active | grep running')
|
12
|
+
|
13
|
+
srvs.each do |srv|
|
14
|
+
name = srv.split.first
|
15
|
+
services[name] = {
|
16
|
+
"action" => 'restart',
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# This module prepare the Cupper project with the
|
2
|
+
# defaults files and dirs. All the files created are
|
3
|
+
# just samples and must to be changed by the user
|
4
|
+
require 'cupper/entity'
|
5
|
+
|
6
|
+
module Cupper
|
7
|
+
class Structure
|
8
|
+
include Entity
|
9
|
+
def initialize(name,dest_path, erb_file = nil, type = nil)
|
10
|
+
super(name, dest_path, erb_file, type)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Project
|
15
|
+
attr_reader :name
|
16
|
+
attr_reader :dir
|
17
|
+
|
18
|
+
def initialize(project_name, directory = nil)
|
19
|
+
@name = project_name
|
20
|
+
@dir = directory.nil? ? Dir.getwd : directory
|
21
|
+
@subdirs = [
|
22
|
+
'cookbooks'
|
23
|
+
]
|
24
|
+
@files = [
|
25
|
+
'CupperFile'
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
# Root project directory
|
31
|
+
struct = Structure.new(@name, @dir, nil, Entity::DIR)
|
32
|
+
struct.create
|
33
|
+
|
34
|
+
@subdirs.zip(@files).each do |dir, file|
|
35
|
+
Structure.new(dir, "#{@dir}/#{@name}", nil, Entity::DIR).create
|
36
|
+
Structure.new(file, "#{@dir}/#{@name}", file).create
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
|
2
|
+
module Cupper
|
3
|
+
# Represents the recipe of the cookbook
|
4
|
+
class Recipe
|
5
|
+
include Entity
|
6
|
+
def initialize(dest_path, collector, erb_file = nil, recipe_name = 'default', recipe_deps = nil)
|
7
|
+
@recipe_deps = recipe_deps
|
8
|
+
@packages = Array.new
|
9
|
+
@services = Array.new
|
10
|
+
@templates = Array.new
|
11
|
+
@users = Array.new
|
12
|
+
@groups = Array.new
|
13
|
+
@execute = Array.new
|
14
|
+
@links = Array.new
|
15
|
+
@directories = Array.new
|
16
|
+
@files = Array.new
|
17
|
+
@collector = collector
|
18
|
+
super(recipe_name, dest_path, erb_file, nil, '.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
@sources_list = expand_sources_list(@collector.extract 'files')
|
23
|
+
@packages = expand_packages(@collector.extract 'packages')
|
24
|
+
@services = expand_services(@collector.extract 'services')
|
25
|
+
@users = expand_users(@collector.extract 'users')
|
26
|
+
@groups = expand_groups(@collector.extract 'groups')
|
27
|
+
@links = expand_links(@collector.extract 'files')
|
28
|
+
@files = expand_files(@collector.extract 'files')
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def expand_sources_list(files)
|
33
|
+
att = Array.new
|
34
|
+
files.each do |attr|
|
35
|
+
# TODO: Doesn't works for arch, this should be a plugin responsability
|
36
|
+
if attr[0].include?("/etc/apt/sources.list") and (convert_mode(attr[1]['mode']) != 'Unknown') and text_type?(attr)
|
37
|
+
path = attr[0]
|
38
|
+
group = attr[1]['group']
|
39
|
+
mode = attr[1]['mode']
|
40
|
+
owner = attr[1]['owner']
|
41
|
+
att.push(new_file(group, mode, owner, path))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
att
|
45
|
+
end
|
46
|
+
|
47
|
+
def expand_packages(packages)
|
48
|
+
att = Array.new
|
49
|
+
packages.each do |attr|
|
50
|
+
pkg = attr[0]
|
51
|
+
version = attr[1]['version']
|
52
|
+
|
53
|
+
att.push(new_package(pkg,version))
|
54
|
+
end
|
55
|
+
att
|
56
|
+
end
|
57
|
+
|
58
|
+
def link_type?(file)
|
59
|
+
(file[1]['type'].split.first(2).join(' ').match('symbolic link'))
|
60
|
+
end
|
61
|
+
|
62
|
+
def dir_type?(file)
|
63
|
+
file[1]['type'].match('directory')
|
64
|
+
end
|
65
|
+
|
66
|
+
def text_type?(file)
|
67
|
+
file[1]['type'].match('text') or file[1]['type'].match('ASCII')
|
68
|
+
end
|
69
|
+
|
70
|
+
# TODO: this should be on ohai plugin
|
71
|
+
def convert_mode(mode)
|
72
|
+
return 'ERROR' if not mode
|
73
|
+
result = case mode.split('').last(9).join # Common modes
|
74
|
+
when 'rwxrwxrwx' then '777'
|
75
|
+
when 'rwxr-xr-x' then '755'
|
76
|
+
when 'rwx------' then '700'
|
77
|
+
when 'rw-rw-rw-' then '666'
|
78
|
+
when 'rw-r--r--' then '644'
|
79
|
+
when 'rw-------' then '600'
|
80
|
+
else 'Unknown'
|
81
|
+
end
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
85
|
+
def expand_services(services)
|
86
|
+
att = Array.new
|
87
|
+
services.each do |attr|
|
88
|
+
srv = attr[0]
|
89
|
+
action = attr[1]['action']
|
90
|
+
|
91
|
+
att.push(new_service(srv,action))
|
92
|
+
end
|
93
|
+
att
|
94
|
+
end
|
95
|
+
|
96
|
+
def expand_links(links)
|
97
|
+
att = Array.new
|
98
|
+
links.each do |attr|
|
99
|
+
if link_type?(attr)
|
100
|
+
target = attr[0]
|
101
|
+
to = attr[1]['type'].split.last(1).join
|
102
|
+
group = attr[1]['group']
|
103
|
+
mode = attr[1]['mode']
|
104
|
+
owner = attr[1]['owner']
|
105
|
+
|
106
|
+
att.push(new_link(group, mode, owner, target, to))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
att
|
110
|
+
end
|
111
|
+
|
112
|
+
def expand_users(users)
|
113
|
+
att = Array.new
|
114
|
+
users.each do |attr|
|
115
|
+
usr = attr[0]
|
116
|
+
uid = attr[1]['uid']
|
117
|
+
gid = attr[1]['gid']
|
118
|
+
dir = attr[1]['dir']
|
119
|
+
shell = attr[1]['shell']
|
120
|
+
|
121
|
+
att.push(new_user(usr, uid, gid, dir, shell))
|
122
|
+
end
|
123
|
+
att
|
124
|
+
end
|
125
|
+
|
126
|
+
def expand_groups(groups)
|
127
|
+
att = Array.new
|
128
|
+
groups.each do |attr|
|
129
|
+
grp = attr[0]
|
130
|
+
gid = attr[1]['gid']
|
131
|
+
members = attr[1]['members']
|
132
|
+
|
133
|
+
att.push(new_group(grp, gid, members))
|
134
|
+
end
|
135
|
+
att
|
136
|
+
end
|
137
|
+
|
138
|
+
def expand_files(files)
|
139
|
+
att = Array.new
|
140
|
+
files.each do |attr|
|
141
|
+
if text_type?(attr) and !(attr[1]['related'].nil?)
|
142
|
+
path = attr[0]
|
143
|
+
group = attr[1]['group']
|
144
|
+
mode = attr[1]['mode']
|
145
|
+
owner = attr[1]['owner']
|
146
|
+
|
147
|
+
att.push(new_file(group, mode, owner, path))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
att
|
151
|
+
end
|
152
|
+
|
153
|
+
# Every attribute object is created dynamic
|
154
|
+
def new_package(name, version)
|
155
|
+
package = Attribute.new
|
156
|
+
class << package
|
157
|
+
attr_accessor :name
|
158
|
+
attr_accessor :version
|
159
|
+
end
|
160
|
+
package.name = name
|
161
|
+
package.version = version
|
162
|
+
package
|
163
|
+
end
|
164
|
+
|
165
|
+
def new_service(name, action)
|
166
|
+
service = Attribute.new
|
167
|
+
class << service
|
168
|
+
attr_accessor :name
|
169
|
+
attr_accessor :action
|
170
|
+
end
|
171
|
+
service.name = name
|
172
|
+
service.action = action
|
173
|
+
service
|
174
|
+
end
|
175
|
+
|
176
|
+
def new_link(group, mode, owner, target_file, to)
|
177
|
+
link = Attribute.new
|
178
|
+
class << link
|
179
|
+
attr_accessor :group
|
180
|
+
attr_accessor :mode
|
181
|
+
attr_accessor :owner
|
182
|
+
attr_accessor :target_file
|
183
|
+
attr_accessor :to
|
184
|
+
end
|
185
|
+
link.group = group
|
186
|
+
link.mode = convert_mode(mode)
|
187
|
+
link.owner = owner
|
188
|
+
link.target_file = target_file
|
189
|
+
link.to = to
|
190
|
+
link
|
191
|
+
end
|
192
|
+
|
193
|
+
def new_user(name, uid, gid, dir, shell)
|
194
|
+
user = Attribute.new
|
195
|
+
class << user
|
196
|
+
attr_accessor :name
|
197
|
+
attr_accessor :uid
|
198
|
+
attr_accessor :gid
|
199
|
+
attr_accessor :dir
|
200
|
+
attr_accessor :shell
|
201
|
+
end
|
202
|
+
user.name = name
|
203
|
+
user.uid = uid
|
204
|
+
user.gid = gid
|
205
|
+
user.dir = dir
|
206
|
+
user.shell = shell
|
207
|
+
user
|
208
|
+
end
|
209
|
+
|
210
|
+
def new_group(name, gid, members)
|
211
|
+
group = Attribute.new
|
212
|
+
class << group
|
213
|
+
attr_accessor :name
|
214
|
+
attr_accessor :gid
|
215
|
+
attr_accessor :members
|
216
|
+
end
|
217
|
+
group.name = name
|
218
|
+
group.gid = gid
|
219
|
+
group.members = members
|
220
|
+
group
|
221
|
+
end
|
222
|
+
|
223
|
+
def new_file(group, mode, owner, path, source='')
|
224
|
+
file = Attribute.new
|
225
|
+
class << file
|
226
|
+
attr_accessor :path
|
227
|
+
attr_accessor :source
|
228
|
+
attr_accessor :group
|
229
|
+
attr_accessor :mode
|
230
|
+
attr_accessor :owner
|
231
|
+
end
|
232
|
+
file.path = path
|
233
|
+
file.source = source
|
234
|
+
file.group = group
|
235
|
+
file.mode = convert_mode(mode)
|
236
|
+
file.owner = owner
|
237
|
+
file
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Cupper config file
|