dqscore 1.0.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.
- checksums.yaml +7 -0
- data/lib/dqscore.rb +276 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b2eee2dda7cbfe3497bfd259534be9031a1af33
|
4
|
+
data.tar.gz: c7ec0987d94049ee9c9648f9bff056c7b7b095da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b679b2f090442bc9e8aa1af5a6e3eeca26012dbab7be520541adaf2f4393581d32d3846690f37bf1fbe9aef91bc9fc15edbd178f6b08e5a75bf34d0dc6907bc9
|
7
|
+
data.tar.gz: 5b0c8992c5ece07b0bcf85676fa9bd65ddcbb5dfc788927f747d180f2bb97a5517518393d5a1c7010a6e8e72eb0029c46791ad73f60b23b210be7b8924743975
|
data/lib/dqscore.rb
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
# Module that controls the colors used
|
2
|
+
module Tty extend self
|
3
|
+
|
4
|
+
def black; bold 30; end
|
5
|
+
def red; bold 31; end
|
6
|
+
def green; bold 32; end
|
7
|
+
def yellow; bold 33; end
|
8
|
+
def blue; bold 34; end
|
9
|
+
def purple; bold 35; end
|
10
|
+
def cyan; bold 36; end
|
11
|
+
def white; bold 39; end
|
12
|
+
def grey; bold 38; end
|
13
|
+
def reset; escape 0; end
|
14
|
+
def bold n; escape "1;#{n}" end
|
15
|
+
def underline n; escape "4;#{n}" end
|
16
|
+
def escape n; "\033[#{n}m" if STDOUT.tty? end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
# Core Module
|
21
|
+
module DQS
|
22
|
+
|
23
|
+
class CheckDependencies
|
24
|
+
|
25
|
+
### Instance variables...
|
26
|
+
@@dpkg = '/usr/bin/dpkg'
|
27
|
+
@@aptitude = '/usr/bin/aptitude'
|
28
|
+
@@grep = '/bin/grep --color -i -e'
|
29
|
+
@@gem = '/usr/bin/gem'
|
30
|
+
@@awk = '/usr/bin/awk'
|
31
|
+
|
32
|
+
# Check gems
|
33
|
+
def dependences_gems(gems)
|
34
|
+
begin
|
35
|
+
gems.each do |dep|
|
36
|
+
unless system("#{@@gem} list -i #{dep} >> /dev/null")
|
37
|
+
puts "#{Tty.white}Installing #{Tty.blue} ==> #{Tty.green} #{dep} #{Tty.reset}"
|
38
|
+
#unless system("#{@@gem} install #{dep} --no-ri --no-rdoc")
|
39
|
+
unless system("#{@@gem} install #{dep}")
|
40
|
+
puts "#{Tty.red} Error: Installing #{Tty.blue}==>#{Tty.red} #{dep}!#{Tty.reset}"
|
41
|
+
exit!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
rescue Exception => e
|
46
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
47
|
+
exit!
|
48
|
+
end
|
49
|
+
puts "#{Tty.white}All the gems are #{Tty.blue} ==> #{Tty.green} OK #{Tty.reset}"
|
50
|
+
end
|
51
|
+
|
52
|
+
# Check gems
|
53
|
+
def dependences_deb(debs)
|
54
|
+
begin
|
55
|
+
puts "#{Tty.white}Updating #{Tty.blue} ==> #{Tty.green} Repositories #{Tty.reset}"
|
56
|
+
unless system("#{@@aptitude} update >> /dev/null")
|
57
|
+
puts "#{Tty.red} Error: Installing #{Tty.blue}==>#{Tty.red} #{dep}!#{Tty.reset}"
|
58
|
+
exit!
|
59
|
+
end
|
60
|
+
puts "#{Tty.white}Repositories #{Tty.blue} ==> #{Tty.green} Updated #{Tty.reset}"
|
61
|
+
|
62
|
+
debs.each do |dep|
|
63
|
+
unless system("#{@@dpkg} -l | #{@@grep} #{dep} | #{@@awk} {'print $2}' | #{@@grep} \"^#{dep}$\" >> /dev/null")
|
64
|
+
puts "#{Tty.white}Installing #{Tty.blue} ==> #{Tty.green} #{dep} #{Tty.reset}"
|
65
|
+
unless system("#{@@aptitude} install #{dep} -y >> /dev/null")
|
66
|
+
puts "#{Tty.red} Error: Installing #{Tty.blue}==>#{Tty.red} #{dep}!#{Tty.reset}"
|
67
|
+
exit!
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
rescue Exception => e
|
72
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
73
|
+
exit!
|
74
|
+
end
|
75
|
+
puts "#{Tty.white}All the deb packages are #{Tty.blue} ==> #{Tty.green} OK #{Tty.reset}"
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
class Core
|
81
|
+
|
82
|
+
### Instance variables...
|
83
|
+
@@dpkg = '/usr/bin/dpkg'
|
84
|
+
@@aptitude = '/usr/bin/aptitude'
|
85
|
+
@@mknod = '/bin/mknod'
|
86
|
+
@@grep = '/bin/grep --color -i -e'
|
87
|
+
@@systemctl = '/bin/systemctl'
|
88
|
+
@@awk = '/usr/bin/awk'
|
89
|
+
|
90
|
+
### Handling block creation.
|
91
|
+
def create_block(device,opt)
|
92
|
+
begin
|
93
|
+
if File.exists?(device)
|
94
|
+
puts "#{Tty.white}Device #{Tty.blue} ==> #{Tty.white} #{device} #{Tty.blue} ==> #{Tty.green} Already Exists #{Tty.reset}"
|
95
|
+
elsif system("#{@@mknod} #{device} #{opt}")
|
96
|
+
puts "#{Tty.white}Created device #{Tty.blue} ==> #{Tty.green} #{device} #{Tty.reset}"
|
97
|
+
end
|
98
|
+
rescue Exception => e
|
99
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
100
|
+
exit!
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
### Handling directory creation...
|
106
|
+
def create_dir(dir)
|
107
|
+
begin
|
108
|
+
if Dir.exists?(dir)
|
109
|
+
puts "#{Tty.white}Directory #{Tty.blue} ==> #{Tty.white} #{dir} #{Tty.blue} ==> #{Tty.green} Already Exists #{Tty.reset}"
|
110
|
+
elsif FileUtils.mkdir_p(dir)
|
111
|
+
puts "#{Tty.white}Created directory #{Tty.blue} ==> #{Tty.green} #{dir} #{Tty.reset}"
|
112
|
+
end
|
113
|
+
rescue Exception => e
|
114
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
115
|
+
exit!
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
### Handling move files
|
120
|
+
def mv(src,dst)
|
121
|
+
begin
|
122
|
+
FileUtils.cp_r("#{src}","#{dst}", :preserve => true)
|
123
|
+
FileUtils.rm_rf("#{src}")
|
124
|
+
rescue Exception => e
|
125
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
126
|
+
exit!
|
127
|
+
end
|
128
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{src} #{Tty.blue} ==> #{Tty.white} moved to: #{dst} #{Tty.blue} ==> #{Tty.green} Moved #{Tty.reset}"
|
129
|
+
end
|
130
|
+
|
131
|
+
### Handling move files
|
132
|
+
def cp(src,dst)
|
133
|
+
begin
|
134
|
+
FileUtils.cp_r("#{src}","#{dst}", :preserve => true)
|
135
|
+
rescue Exception => e
|
136
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
137
|
+
exit!
|
138
|
+
end
|
139
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{src} #{Tty.blue} ==> #{Tty.white} copied to: #{dst} #{Tty.blue} ==> #{Tty.green} Copied #{Tty.reset}"
|
140
|
+
end
|
141
|
+
|
142
|
+
### Handling commands
|
143
|
+
def exec_cmd(command)
|
144
|
+
begin
|
145
|
+
system("#{command} >> /dev/null")
|
146
|
+
rescue Exception => e
|
147
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
148
|
+
exit!
|
149
|
+
end
|
150
|
+
puts "#{Tty.white}Command #{Tty.blue} ==> #{Tty.white} #{command} #{Tty.blue} ==> #{Tty.green} Executed #{Tty.reset}"
|
151
|
+
end
|
152
|
+
|
153
|
+
### Handling move files
|
154
|
+
def rm(path)
|
155
|
+
begin
|
156
|
+
FileUtils.rm_rf("#{path}")
|
157
|
+
rescue Exception => e
|
158
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
159
|
+
exit!
|
160
|
+
end
|
161
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{path} #{Tty.blue} ==> #{Tty.green} Removed #{Tty.reset}"
|
162
|
+
end
|
163
|
+
|
164
|
+
### Handling move files
|
165
|
+
def ln_s(src,dst)
|
166
|
+
begin
|
167
|
+
FileUtils.ln_s("#{src}","#{dst}")
|
168
|
+
rescue Exception => e
|
169
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
170
|
+
exit!
|
171
|
+
end
|
172
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{src} #{Tty.blue} ==> #{Tty.white} linked to: #{dst} #{Tty.blue} ==> #{Tty.green} Linked #{Tty.reset}"
|
173
|
+
end
|
174
|
+
|
175
|
+
### Handling move files
|
176
|
+
def ln(src,dst)
|
177
|
+
begin
|
178
|
+
FileUtils.ln("#{src}","#{dst}")
|
179
|
+
rescue Exception => e
|
180
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
181
|
+
exit!
|
182
|
+
end
|
183
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{src} #{Tty.blue} ==> #{Tty.white} linked to: #{dst} #{Tty.blue} ==> #{Tty.green} Linked #{Tty.reset}"
|
184
|
+
end
|
185
|
+
|
186
|
+
### Handling chmod permissions
|
187
|
+
def chmod(path,perm)
|
188
|
+
str_perm = perm.to_s(8)
|
189
|
+
begin
|
190
|
+
if Dir.exists?(path) || File.exists?(path)
|
191
|
+
if FileUtils.chmod_R(perm,"#{path}")
|
192
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{path} #{Tty.blue} ==> #{Tty.white} permission changed to: #{str_perm} #{Tty.blue} ==> #{Tty.green} permission Changed #{Tty.reset}"
|
193
|
+
end
|
194
|
+
end
|
195
|
+
rescue Exception => e
|
196
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
197
|
+
exit!
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
### Handling chown permissions
|
202
|
+
def chown(path,owner=nil,group=nil)
|
203
|
+
begin
|
204
|
+
if Dir.exists?(path) || File.exists?(path)
|
205
|
+
if FileUtils.chown_R(owner, group, "#{path}")
|
206
|
+
if group.nil?
|
207
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{path} #{Tty.blue} ==> #{Tty.white} changed to: owner: #{owner} #{Tty.blue} ==> #{Tty.green} Changed #{Tty.reset}"
|
208
|
+
else
|
209
|
+
puts "#{Tty.white}Path #{Tty.blue} ==> #{Tty.white} #{path} #{Tty.blue} ==> #{Tty.white} changed to: owner: #{owner}, group: #{group} #{Tty.blue} ==> #{Tty.green} Changed #{Tty.reset}"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
rescue Exception => e
|
214
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
215
|
+
exit!
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
### Save files
|
220
|
+
def save_file(content,path)
|
221
|
+
begin
|
222
|
+
file = File.new("#{path}",'w')
|
223
|
+
file.write content
|
224
|
+
file.close
|
225
|
+
rescue Exception => e
|
226
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
227
|
+
exit!
|
228
|
+
end
|
229
|
+
puts "#{Tty.white}File #{Tty.blue} ==> #{Tty.white} #{path} #{Tty.blue} ==> #{Tty.green} Saved #{Tty.reset}"
|
230
|
+
end
|
231
|
+
|
232
|
+
### Handling the service actions such as stop/start/restart
|
233
|
+
def handle_service(service=nil,action=nil)
|
234
|
+
service_name = service.split('.').first
|
235
|
+
begin
|
236
|
+
if action.nil?
|
237
|
+
puts "#{Tty.white}Executing service #{Tty.blue} ==> #{Tty.green} #{service_name.upcase} #{Tty.reset}"
|
238
|
+
system("#{@@systemctl} #{service}")
|
239
|
+
else
|
240
|
+
puts "#{Tty.white}Executing service #{Tty.blue} ==> #{Tty.white} #{service_name} #{Tty.blue} ==> #{Tty.green} #{action.upcase} #{Tty.reset}"
|
241
|
+
system("#{@@systemctl} #{action} #{service}")
|
242
|
+
end
|
243
|
+
rescue Exception => e
|
244
|
+
puts "#{Tty.red} Error: #{Tty.blue}==>#{Tty.red} #{e.message}!#{Tty.reset}"
|
245
|
+
exit!
|
246
|
+
end
|
247
|
+
if action.nil?
|
248
|
+
puts "#{Tty.white}Service #{Tty.blue} ==> #{Tty.green} #{service_name.upcase} #{Tty.reset}"
|
249
|
+
else
|
250
|
+
puts "#{Tty.white}Service #{Tty.blue} ==> #{Tty.white} #{service_name} #{Tty.blue} ==> #{Tty.green} #{action.upcase} #{Tty.reset}"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
### Handle configuration files
|
255
|
+
def load_conf(path=nil)
|
256
|
+
parsed = begin
|
257
|
+
YAML.load(File.open("#{path}"))
|
258
|
+
rescue Exception => e
|
259
|
+
puts "Could not parse YAML: #{e.message}"
|
260
|
+
end
|
261
|
+
return to_ostruct(parsed)
|
262
|
+
end
|
263
|
+
|
264
|
+
def to_ostruct(object)
|
265
|
+
case object
|
266
|
+
when Hash
|
267
|
+
OpenStruct.new(Hash[object.map {|k, v| [k, to_ostruct(v)] }])
|
268
|
+
when Array
|
269
|
+
object.map {|x| to_ostruct(x) }
|
270
|
+
else
|
271
|
+
object
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dqscore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Douglas Quintiliano dos Santos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: DQS Core methods and classes
|
14
|
+
email: douglas.q.santos@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/dqscore.rb
|
20
|
+
homepage: https://github.com/douglasqsantos/dqscore
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: DQS Core Module
|
44
|
+
test_files: []
|