central 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/central +4 -4
- data/lib/central.rb +187 -213
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c48d4b6cb13b63e3ba6896942008ae004fad3af
|
4
|
+
data.tar.gz: 37dc1ea33c1ed5e8521972c46c3d09df02c3aed6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69a3728b2832dc452ed34d8b88141efe9ea17287fe2555ac5b985e6c89b34122fa0a4037b49701563639fad3442d4894d9a3be671ae449bbded21b78d636dbc9
|
7
|
+
data.tar.gz: 3773b38f6bc059f9cddfa576017fd67b1628ed7dbf90702618988b2537f59e31e691e57d0c9134689737e17eb918520cc00728f567ceb9da655ba3ab43714deb
|
data/bin/central
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# -------------------------------------------------------------------------
|
5
5
|
# # central - dot files manager licensed under LGPLv3 (see LICENSE file) |
|
@@ -8,13 +8,13 @@
|
|
8
8
|
|
9
9
|
require 'central'
|
10
10
|
|
11
|
-
|
11
|
+
unless ARGV.empty?
|
12
12
|
if ARGV[0] == '-v' || ARGV[0] == '--version' || ARGV[0] == '-version'
|
13
|
-
puts
|
13
|
+
puts 'central v0.2.5'
|
14
14
|
exit 0
|
15
15
|
end
|
16
16
|
if ARGV[0] == '-h' || ARGV[0] == '--help' || ARGV[0] == '-help'
|
17
|
-
puts
|
17
|
+
puts 'central [path/to/configuration.rb]'
|
18
18
|
exit 0
|
19
19
|
end
|
20
20
|
end
|
data/lib/central.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# -------------------------------------------------------------------------
|
3
2
|
# # central - dot files manager licensed under LGPLv3 (see LICENSE file) |
|
4
3
|
# # written in Ruby by Dmitry Geurkov (d.geurkov@gmail.com) |
|
@@ -9,6 +8,33 @@ require 'socket'
|
|
9
8
|
require 'open3'
|
10
9
|
require 'fileutils'
|
11
10
|
|
11
|
+
# cli colors
|
12
|
+
COLOR_RED = 31
|
13
|
+
COLOR_GREEN = 32
|
14
|
+
|
15
|
+
# putsc, puts with color
|
16
|
+
def color(message, color)
|
17
|
+
"\e[#{color}m#{message}\e[0m"
|
18
|
+
end
|
19
|
+
|
20
|
+
# info
|
21
|
+
def info(message, param = nil)
|
22
|
+
puts color(message, COLOR_GREEN) +
|
23
|
+
(param.nil? ? '' : ': ' + param)
|
24
|
+
end
|
25
|
+
|
26
|
+
# error
|
27
|
+
def error(message, param = nil)
|
28
|
+
puts color(message, COLOR_RED) +
|
29
|
+
(param.nil? ? '' : ': ' + param)
|
30
|
+
end
|
31
|
+
|
32
|
+
# fail, print message to stderr and exit with 1
|
33
|
+
def fail(message, param = nil)
|
34
|
+
error message, param
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
|
12
38
|
# get hostname
|
13
39
|
def hostname
|
14
40
|
Socket.gethostname
|
@@ -17,114 +43,106 @@ end
|
|
17
43
|
# get operating system
|
18
44
|
def os
|
19
45
|
if RUBY_PLATFORM.include?('linux')
|
20
|
-
|
46
|
+
'linux'
|
21
47
|
elsif RUBY_PLATFORM.include?('darwin')
|
22
|
-
|
48
|
+
'osx'
|
23
49
|
elsif RUBY_PLATFORM.include?('freebsd')
|
24
|
-
|
50
|
+
'freebsd'
|
25
51
|
elsif RUBY_PLATFORM.include?('solaris')
|
26
|
-
|
52
|
+
'solaris'
|
27
53
|
end
|
28
54
|
end
|
29
55
|
|
30
56
|
def linux?
|
31
|
-
|
57
|
+
os == 'linux'
|
32
58
|
end
|
33
59
|
|
34
60
|
def osx?
|
35
|
-
|
61
|
+
os == 'osx'
|
36
62
|
end
|
37
63
|
|
38
64
|
def freebsd?
|
39
|
-
|
65
|
+
os == 'freebsd'
|
40
66
|
end
|
41
67
|
|
42
68
|
def solaris?
|
43
|
-
|
69
|
+
os == 'solaris'
|
44
70
|
end
|
45
71
|
|
46
|
-
# run shell command and get output, optionaly can print command running
|
47
|
-
|
48
|
-
def shell(command,verbose: false, silent: true)
|
49
|
-
|
72
|
+
# run shell command and get output, optionaly can print command running
|
73
|
+
# if verbose and if not silent will also print to stdout and stderr
|
74
|
+
def shell(command, verbose: false, silent: true)
|
75
|
+
info 'Executing', command if verbose
|
76
|
+
exit_code = nil
|
50
77
|
stdout = ''
|
51
78
|
stdout_line = ''
|
52
79
|
stderr = ''
|
53
80
|
stderr_line = ''
|
54
|
-
Open3.popen3(command) do |
|
81
|
+
Open3.popen3(command) do |_, o, e, t|
|
55
82
|
stdout_open = true
|
56
83
|
stderr_open = true
|
57
|
-
while stdout_open
|
84
|
+
while stdout_open || stderr_open
|
58
85
|
if stdout_open
|
59
86
|
begin
|
60
87
|
ch = o.read_nonblock(1)
|
61
|
-
stdout.insert(-1,ch)
|
88
|
+
stdout.insert(-1, ch)
|
62
89
|
unless silent
|
63
|
-
stdout_line.insert(-1,ch)
|
90
|
+
stdout_line.insert(-1, ch)
|
64
91
|
if ch == "\n"
|
65
92
|
STDOUT.puts stdout_line
|
66
93
|
stdout_line = ''
|
67
94
|
end
|
68
95
|
end
|
69
96
|
rescue IO::WaitReadable
|
70
|
-
IO.select([o],nil,nil,0.
|
97
|
+
IO.select([o], nil, nil, 0.01) unless stderr_open
|
71
98
|
rescue EOFError
|
72
99
|
stdout_open = false
|
73
100
|
end
|
74
101
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
102
|
+
next unless stderr_open
|
103
|
+
|
104
|
+
begin
|
105
|
+
ch = e.read_nonblock(1)
|
106
|
+
stderr.insert(-1, ch)
|
107
|
+
unless silent
|
108
|
+
stderr_line.insert(-1, ch)
|
109
|
+
if ch == "\n"
|
110
|
+
STDERR.puts stderr_line
|
111
|
+
stderr_line = ''
|
85
112
|
end
|
86
|
-
rescue IO::WaitReadable
|
87
|
-
IO.select([e],nil,nil,0.1) unless stdout_open
|
88
|
-
rescue EOFError
|
89
|
-
stderr_open = false
|
90
113
|
end
|
114
|
+
rescue IO::WaitReadable
|
115
|
+
IO.select([e], nil, nil, 0.01) unless stdout_open
|
116
|
+
rescue EOFError
|
117
|
+
stderr_open = false
|
91
118
|
end
|
92
119
|
end
|
93
|
-
|
94
|
-
end
|
95
|
-
if stderr == ''
|
96
|
-
return stdout
|
97
|
-
else
|
98
|
-
return stdout, stderr
|
120
|
+
exit_code = t.value
|
99
121
|
end
|
122
|
+
[exit_code, stdout, stderr]
|
100
123
|
end
|
101
124
|
|
102
125
|
# run shell command with sudo prefix, acts same as shell
|
103
|
-
def sudo(command,verbose:,silent:)
|
104
|
-
|
126
|
+
def sudo(command, verbose:, silent:)
|
127
|
+
shell('sudo ' + command, verbose: verbose, silent: silent)
|
105
128
|
end
|
106
129
|
|
107
130
|
# function used to check that system has all required tools installed
|
108
|
-
def check_tool(name,check)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
STDERR.puts "#{name} not found, please install it to use central"
|
113
|
-
exit 1
|
114
|
-
end
|
115
|
-
rescue Errno::ENOENT
|
116
|
-
STDERR.puts "#{name} not found, please install it to use central"
|
117
|
-
exit 1
|
131
|
+
def check_tool(name, check)
|
132
|
+
_, output, = shell(check + ' 2>&1')
|
133
|
+
if output == '' || output.downcase.include?('command not found')
|
134
|
+
fail "#{name} not found, please install it to use central"
|
118
135
|
end
|
136
|
+
rescue Errno::ENOENT
|
137
|
+
fail "#{name} not found, please install it to use central"
|
119
138
|
end
|
120
139
|
|
121
|
-
check_tool('file','file --version')
|
122
|
-
check_tool('grep','grep --version')
|
123
|
-
check_tool('ln','ln --version')
|
124
|
-
check_tool('readlink','readlink --version')
|
125
|
-
check_tool('git','git --version')
|
126
|
-
check_tool('curl','curl --version')
|
127
|
-
|
140
|
+
check_tool('file', 'file --version')
|
141
|
+
check_tool('grep', 'grep --version')
|
142
|
+
check_tool('ln', 'ln --version')
|
143
|
+
check_tool('readlink', 'readlink --version')
|
144
|
+
check_tool('git', 'git --version')
|
145
|
+
check_tool('curl', 'curl --version')
|
128
146
|
|
129
147
|
# current working directory
|
130
148
|
def pwd
|
@@ -133,7 +151,7 @@ end
|
|
133
151
|
|
134
152
|
# absolute path
|
135
153
|
def abs(path)
|
136
|
-
|
154
|
+
File.absolute_path(File.expand_path(path))
|
137
155
|
end
|
138
156
|
|
139
157
|
# change current working directory
|
@@ -165,80 +183,70 @@ end
|
|
165
183
|
|
166
184
|
# get full path of symlink
|
167
185
|
def symlink_path(symlink)
|
168
|
-
shell("readlink \"#{abs(symlink)}\" 2>&1")
|
186
|
+
_, out, = shell("readlink -f \"#{abs(symlink)}\" 2>&1")
|
187
|
+
out.strip
|
169
188
|
end
|
170
189
|
|
171
190
|
# make directory including intermediate directories
|
172
191
|
def mkdir(path)
|
173
192
|
path = abs(path)
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
puts "Created directory: #{path}"
|
193
|
+
return if dir_exists?(path)
|
194
|
+
|
195
|
+
exit_code, out, = shell("mkdir -p \"#{path}\" 2>&1")
|
196
|
+
unless exit_code.success?
|
197
|
+
error out
|
198
|
+
fail "Couldn't create directory", path
|
182
199
|
end
|
200
|
+
info 'Created directory', path
|
183
201
|
end
|
184
202
|
|
185
203
|
# remove file/directory
|
186
|
-
def rm(path,recursive: false)
|
204
|
+
def rm(path, recursive: false)
|
187
205
|
path = abs(path)
|
188
|
-
|
189
|
-
recursive = '-R '
|
190
|
-
else
|
191
|
-
recursive = ''
|
192
|
-
end
|
206
|
+
recursive = recursive ? '-R ' : ''
|
193
207
|
is_dir = dir_exists?(path)
|
194
208
|
is_symlink = symlink?(path)
|
195
|
-
out = shell("rm #{recursive}-f \"#{path}\" 2>&1")
|
196
|
-
unless
|
197
|
-
|
198
|
-
|
199
|
-
exit 1
|
209
|
+
exit_code, out, = shell("rm #{recursive}-f \"#{path}\" 2>&1")
|
210
|
+
unless exit_code.success?
|
211
|
+
error out
|
212
|
+
fail "Couldn't remove path", path
|
200
213
|
end
|
201
214
|
if is_dir
|
202
|
-
|
215
|
+
info 'Removed directory', path
|
203
216
|
elsif is_symlink
|
204
|
-
|
217
|
+
info 'Removed symlink', path
|
205
218
|
else
|
206
|
-
|
219
|
+
info 'Removed file', path
|
207
220
|
end
|
208
221
|
end
|
209
222
|
|
210
223
|
# remove directory recursively
|
211
224
|
def rmdir(path)
|
212
|
-
rm(path,recursive: true)
|
225
|
+
rm(path, recursive: true)
|
213
226
|
end
|
214
227
|
|
215
228
|
# touch file
|
216
229
|
def touch(path)
|
217
230
|
path = abs(path)
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
225
|
-
puts "Touched file: #{path}"
|
231
|
+
return if file_exists?(path)
|
232
|
+
|
233
|
+
exit_code, out, = shell("touch \"#{path}\" 2>&1")
|
234
|
+
unless exit_code.success?
|
235
|
+
error out
|
236
|
+
fail "Couldn't touch file", path
|
226
237
|
end
|
238
|
+
info 'Touched file', path
|
227
239
|
end
|
228
240
|
|
229
241
|
# change file permissions
|
230
|
-
def chmod(path,permissions,recursive: false)
|
242
|
+
def chmod(path, permissions, recursive: false)
|
231
243
|
path = abs(path)
|
232
|
-
|
233
|
-
recursive = '-R '
|
234
|
-
else
|
235
|
-
recursive = ''
|
236
|
-
end
|
244
|
+
recursive = recursive ? '-R ' : ''
|
237
245
|
shell("chmod #{recursive}#{permissions} \"#{path}\"")
|
238
246
|
end
|
239
247
|
|
240
248
|
# symlink path
|
241
|
-
def symlink(from,to)
|
249
|
+
def symlink(from, to)
|
242
250
|
from = abs(from)
|
243
251
|
to = abs(to)
|
244
252
|
if symlink?(from)
|
@@ -247,187 +255,156 @@ def symlink(from,to)
|
|
247
255
|
symlink from, to
|
248
256
|
end
|
249
257
|
elsif file_exists?(from)
|
250
|
-
|
251
|
-
exit 1
|
258
|
+
fail "File #{from} exists in place of symlink..."
|
252
259
|
elsif dir_exists?(from)
|
253
|
-
|
254
|
-
exit 1
|
260
|
+
fail "Directory #{from} exists in place of symlink..."
|
255
261
|
else
|
256
|
-
out = shell("ln -s \"#{to}\" \"#{from}\" 2>&1")
|
257
|
-
unless
|
258
|
-
|
259
|
-
|
260
|
-
exit 1
|
262
|
+
exit_code, out, = shell("ln -s \"#{to}\" \"#{from}\" 2>&1")
|
263
|
+
unless exit_code.success?
|
264
|
+
error out
|
265
|
+
fail "Couldn't create symlink", "#{from} → #{to}"
|
261
266
|
end
|
262
|
-
|
267
|
+
info 'Created symlink', "#{from} → #{to}"
|
263
268
|
end
|
264
269
|
end
|
265
270
|
|
266
271
|
# git clone url into a path
|
267
|
-
def git(url,path,branch: nil,silent:
|
272
|
+
def git(url, path, branch: nil, silent: true, depth: nil)
|
268
273
|
path = abs(path)
|
269
274
|
if dir_exists?(path) && dir_exists?("#{path}/.git")
|
270
|
-
cwd = pwd
|
275
|
+
cwd = pwd
|
271
276
|
chdir path
|
272
277
|
out = nil
|
273
278
|
if branch
|
274
|
-
out = shell('git fetch 2>&1',
|
275
|
-
if out.size
|
276
|
-
|
277
|
-
end
|
278
|
-
out = shell("git checkout #{branch} 2>&1",{:silent => silent})
|
279
|
+
_, out, = shell('git fetch 2>&1', silent: silent)
|
280
|
+
puts out if silent && out.size.positive?
|
281
|
+
_, out, = shell("git checkout #{branch} 2>&1", silent: silent)
|
279
282
|
unless out.downcase.include? 'is now at'
|
280
283
|
puts out if silent
|
281
284
|
end
|
282
|
-
out = shell("git pull origin #{branch} 2>&1",
|
285
|
+
_, out, = shell("git pull origin #{branch} 2>&1", silent: silent)
|
283
286
|
else
|
284
|
-
out = shell('git pull 2>&1',
|
287
|
+
_, out, = shell('git pull 2>&1', silent: silent)
|
285
288
|
end
|
286
|
-
unless out.downcase.include?
|
289
|
+
unless out.downcase.include? 'already up-to-date'
|
287
290
|
puts out if silent
|
288
|
-
|
291
|
+
info 'Git repository pulled', "#{url} → #{path}"
|
289
292
|
end
|
290
293
|
chdir cwd
|
291
294
|
else
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
end
|
297
|
-
if depth
|
298
|
-
depth = '--depth '+depth.to_s+' '
|
299
|
-
else
|
300
|
-
depth = ''
|
301
|
-
end
|
302
|
-
out = shell("git clone #{depth}#{branch}#{url} \"#{path}\" 2>&1",{:silent => silent})
|
295
|
+
branch = branch ? "-b #{branch} " : ''
|
296
|
+
depth = depth ? "--depth #{depth} " : ''
|
297
|
+
_, out, = shell("git clone #{depth}#{branch}#{url} \"#{path}\" 2>&1",
|
298
|
+
silent: silent)
|
303
299
|
puts out if silent
|
304
|
-
|
300
|
+
info 'Git repository cloned', "#{url} → #{path}"
|
305
301
|
end
|
306
302
|
end
|
307
303
|
|
308
304
|
# download url into a path using curl
|
309
|
-
def curl(url,path, verbose: false)
|
305
|
+
def curl(url, path, verbose: false)
|
310
306
|
path = abs(path)
|
311
|
-
|
312
|
-
output = shell("curl -s -S \"#{url}\"",
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
307
|
+
info 'Downloading', "#{url} → #{path}"
|
308
|
+
exit_code, output, = shell("curl -s -S \"#{url}\"",
|
309
|
+
verbose: verbose, silent: true)
|
310
|
+
unless exit_code.success?
|
311
|
+
error output
|
312
|
+
fail "Couldn't download file from", url
|
317
313
|
end
|
318
|
-
File.write(path,output)
|
319
|
-
|
314
|
+
File.write(path, output)
|
315
|
+
info 'Downloaded', "#{url} → #{path}"
|
320
316
|
end
|
321
317
|
|
322
318
|
# read content of a file
|
323
319
|
def read(file)
|
324
320
|
file = abs(file)
|
325
|
-
if file_exists?(file)
|
326
|
-
|
327
|
-
|
328
|
-
STDERR.puts "Couldn't read file #{file}..."
|
329
|
-
exit 1
|
330
|
-
end
|
321
|
+
return File.read(file) if file_exists?(file)
|
322
|
+
|
323
|
+
fail "Couldn't read file", file
|
331
324
|
end
|
332
325
|
|
333
326
|
# write content into a file
|
334
|
-
def write(file,content)
|
327
|
+
def write(file, content)
|
335
328
|
file = abs(file)
|
336
|
-
File.write(file,content)
|
329
|
+
File.write(file, content)
|
337
330
|
end
|
338
331
|
|
339
332
|
# source file in sh/bash/zsh script
|
340
|
-
def source(file,source)
|
333
|
+
def source(file, source)
|
341
334
|
file = abs(file)
|
342
335
|
source = abs(source)
|
343
336
|
source_line = "source \"#{source}\""
|
344
|
-
out = shell("grep -Fx '#{source_line}' \"#{file}\"")
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
337
|
+
_, out, = shell("grep -Fx '#{source_line}' \"#{file}\"")
|
338
|
+
return unless out == ''
|
339
|
+
|
340
|
+
shell("echo '#{source_line}' >> \"#{file}\"")
|
341
|
+
info 'Added source', "#{source} line to #{file}"
|
349
342
|
end
|
350
343
|
|
351
344
|
# list directory content
|
352
|
-
def ls(path,dotfiles: false, grep: '', dir: true, file: true)
|
345
|
+
def ls(path, dotfiles: false, grep: '', dir: true, file: true)
|
353
346
|
path = abs(path)
|
354
|
-
|
355
|
-
dotfiles = '-a '
|
356
|
-
else
|
357
|
-
dotfiles = ''
|
358
|
-
end
|
347
|
+
dotfiles = dotfiles ? '-a ' : ''
|
359
348
|
command = "ls -1 #{dotfiles}\"#{path}\" 2>&1"
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
output = shell(command)
|
349
|
+
command += " | grep #{grep}" unless grep.empty?
|
350
|
+
|
351
|
+
_, output, = shell(command)
|
364
352
|
if output.downcase.end_with?('no such file or directory')
|
365
|
-
|
366
|
-
exit 1
|
353
|
+
fail "Couldn't ls directory", path
|
367
354
|
end
|
355
|
+
|
368
356
|
ls = output.split("\n")
|
369
|
-
unless dir
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
357
|
+
ls = ls.keep_if { |f| !File.directory?("#{path}/#{f}") } unless dir
|
358
|
+
ls = ls.keep_if { |f| !File.file?("#{path}/#{f}") } unless file
|
359
|
+
ls
|
360
|
+
end
|
361
|
+
|
362
|
+
# copy_file
|
363
|
+
def copy_file(from, to)
|
364
|
+
fail "Couldn't access file", from unless file_exists?(from)
|
365
|
+
|
366
|
+
return if file_exists?(to) && FileUtils.compare_file(from, to)
|
367
|
+
|
368
|
+
FileUtils.copy_file(from, to)
|
369
|
+
info 'Copied file', "#{from} → #{to}"
|
376
370
|
end
|
377
371
|
|
378
372
|
# copy
|
379
|
-
def copy(from,to)
|
373
|
+
def copy(from, to)
|
380
374
|
from = abs(from)
|
381
375
|
to = abs(to)
|
382
376
|
if dir_exists?(from)
|
383
|
-
(Dir.entries(from).select { |f| f !=
|
377
|
+
(Dir.entries(from).select { |f| f != '.' && f != '..' }).each do |f|
|
384
378
|
FileUtils.mkdir_p(to)
|
385
|
-
copy("#{from}/#{f}","#{to}/#{f}")
|
379
|
+
copy("#{from}/#{f}", "#{to}/#{f}")
|
386
380
|
end
|
387
381
|
else
|
388
|
-
|
389
|
-
STDERR.puts "Couldn't access file #{from}..."
|
390
|
-
exit 1
|
391
|
-
end
|
392
|
-
if !file_exists?(to) or !FileUtils.compare_file(from,to)
|
393
|
-
FileUtils.copy_file(from,to)
|
394
|
-
puts "Copied file: #{from} → #{to}"
|
395
|
-
end
|
382
|
+
copy_file(from, to)
|
396
383
|
end
|
397
384
|
end
|
398
385
|
|
399
386
|
# process erb template into an output_file
|
400
|
-
def erb(file,output_file = nil)
|
387
|
+
def erb(file, output_file = nil)
|
401
388
|
file = abs(file)
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
output_file = file+'.out'
|
407
|
-
end
|
408
|
-
end
|
409
|
-
if file_exists?(file)
|
410
|
-
output = ERB.new(File.read(file)).result
|
411
|
-
if File.exist?(output_file) && File.read(output_file) == output
|
412
|
-
return
|
413
|
-
end
|
414
|
-
File.write(output_file,output)
|
415
|
-
puts "Processed erb #{file} → #{output_file}"
|
416
|
-
else
|
417
|
-
STDERR.puts "Couldn't process erb file #{file}..."
|
418
|
-
exit 1
|
389
|
+
fail 'No erb file found', file unless file_exists?(file)
|
390
|
+
|
391
|
+
if output_file.nil?
|
392
|
+
output_file = file.end_with?('.erb') ? file[0...-4] : file + '.out'
|
419
393
|
end
|
394
|
+
out = ERB.new(File.read(file)).result
|
395
|
+
return if File.exist?(output_file) && File.read(output_file) == out
|
396
|
+
|
397
|
+
File.write(output_file, out)
|
398
|
+
info 'Processed erb', "#{file} → #{output_file}"
|
420
399
|
end
|
421
400
|
|
422
401
|
# run configuration.rb file
|
423
402
|
def run(file)
|
424
|
-
cwd = pwd
|
403
|
+
cwd = pwd
|
425
404
|
file = abs(file)
|
426
|
-
unless file_exists?(file)
|
427
|
-
|
428
|
-
|
429
|
-
end
|
430
|
-
puts "Running configuration: "+file
|
405
|
+
fail 'No configuration file found', file unless file_exists?(file)
|
406
|
+
|
407
|
+
info 'Running configuration', file
|
431
408
|
file_cwd = file_dir(file)
|
432
409
|
chdir file_cwd
|
433
410
|
load file
|
@@ -436,19 +413,16 @@ end
|
|
436
413
|
|
437
414
|
# run configuration.rb file only if it exists
|
438
415
|
def run_if_exists(file)
|
439
|
-
if file_exists?(file)
|
440
|
-
run file
|
441
|
-
end
|
416
|
+
run file if file_exists?(file)
|
442
417
|
end
|
443
418
|
|
444
419
|
# run central configuration
|
445
420
|
def central(configurations)
|
446
|
-
if configurations.instance_of?(Array) && configurations.
|
447
|
-
configurations.each {|configuration| run configuration }
|
421
|
+
if configurations.instance_of?(Array) && !configurations.empty?
|
422
|
+
configurations.each { |configuration| run configuration }
|
448
423
|
elsif configurations.instance_of?(String)
|
449
424
|
run configurations
|
450
425
|
else
|
451
426
|
run 'configuration.rb'
|
452
427
|
end
|
453
428
|
end
|
454
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: central
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Geurkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: central dotfile management system
|
14
14
|
email: d.geurkov@gmail.com
|
@@ -31,7 +31,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
34
|
+
version: '2.0'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|