central 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/central +9 -0
  3. data/lib/central.rb +43 -29
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef3bac32fa508e44dc3d48d1dabb4b29bdf6e55e
4
- data.tar.gz: 1e6a45c9cdf4fa3cc46f547e91a3512f73bb73f9
3
+ metadata.gz: 40c3c1a6118599140ca0da2b5efbd531b0eb45aa
4
+ data.tar.gz: 1cb733800e425bec33f90c9d7a015dcd612827f3
5
5
  SHA512:
6
- metadata.gz: 2bbfc1d14c95b8702d6d91c679ef1d005603046fdfca7f00895f198c00ef6102f2069ad634dbe2ee213070fd823bd74fe1dd71595346e5eb1f18c0ac9cb35677
7
- data.tar.gz: 181ee4734b7ab716b2a6fb66c230d4478ee377a6ada8e46787b08941545aebc47c6e1272ad4607aa6ce718b4bd28007ee94624e0d068a52f3b40936aad7e601b
6
+ metadata.gz: 0b37e52fd86ac446273f675ea8958637b6e3779e552f70090b9201f038e4557b48703bf487f8022bcbe51372d8f3755d640b4f8d9b0bc94e12a856feafa1a29f
7
+ data.tar.gz: f581da8f4f9a6252188040d7ee1a26fd4e9465939dc98dfa6ed88b0888888856fb3aa9a021b80cbea15a6145f3fd28b85dacc9d32de1002706b302cdcbb4249a
data/bin/central CHANGED
@@ -8,4 +8,13 @@
8
8
 
9
9
  require 'central'
10
10
 
11
+ if ARGV.length > 0
12
+ if ARGV[0] == '-v' || ARGV[0] == '--version' || ARGV[0] == '-version'
13
+ puts "central v0.2.1"
14
+ end
15
+ if ARGV[0] == '-h' || ARGV[0] == '--help' || ARGV[0] == '-help'
16
+ puts "central [path/to/configuration.rb]"
17
+ end
18
+ exit 0
19
+ end
11
20
  central(ARGV)
data/lib/central.rb CHANGED
@@ -106,21 +106,14 @@ end
106
106
  # function used to check that system has all required tools installed
107
107
  def check_tool(name,check)
108
108
  begin
109
- output = shell(check)
110
- if output.kind_of?(String)
111
- output = output.downcase
112
- if output == '' or output.include?('command not found')
113
- STDERR.puts "#{name} not found, please install it to use central"
114
- exit 1
115
- end
116
- elsif output.kind_of?(Array)
117
- if output[0] == '' and output[1] == ''
118
- STDERR.puts "#{name} not found, please install it to use central"
119
- exit 1
120
- end
109
+ output = shell(check+' 2>&1').downcase
110
+ if output == '' or output.include?('command not found')
111
+ STDERR.puts "#{name} not found, please install it to use central"
112
+ exit 1
121
113
  end
122
114
  rescue Errno::ENOENT
123
115
  STDERR.puts "#{name} not found, please install it to use central"
116
+ exit 1
124
117
  end
125
118
  end
126
119
 
@@ -171,14 +164,19 @@ end
171
164
 
172
165
  # get full path of symlink
173
166
  def symlink_path(symlink)
174
- shell("readlink \"#{abs(symlink)}\"").strip
167
+ shell("readlink \"#{abs(symlink)}\" 2>&1").strip
175
168
  end
176
169
 
177
170
  # make directory including intermediate directories
178
171
  def mkdir(path)
179
172
  path = abs(path)
180
173
  unless dir_exists?(path)
181
- out = shell("mkdir -p \"#{path}\"")
174
+ out = shell("mkdir -p \"#{path}\" 2>&1")
175
+ unless $shell_return_value.success?
176
+ STDERR.puts out
177
+ STDERR.puts "Couldn't create directory: #{path}"
178
+ exit 1
179
+ end
182
180
  puts "Created directory: #{path}"
183
181
  end
184
182
  end
@@ -193,7 +191,12 @@ def rm(path,recursive=false)
193
191
  end
194
192
  is_dir = dir_exists?(path)
195
193
  is_symlink = symlink?(path)
196
- out = shell("rm #{recursive}-f \"#{path}\"")
194
+ out = shell("rm #{recursive}-f \"#{path}\" 2>&1")
195
+ unless $shell_return_value.success?
196
+ STDERR.puts out
197
+ STDERR.puts "Couldn't remove path: #{path}"
198
+ exit 1
199
+ end
197
200
  if is_dir
198
201
  puts "Removed directory: #{path}"
199
202
  elsif is_symlink
@@ -212,7 +215,12 @@ end
212
215
  def touch(path)
213
216
  path = abs(path)
214
217
  unless file_exists?(path)
215
- out = shell("touch \"#{path}\"")
218
+ out = shell("touch \"#{path}\" 2>&1")
219
+ unless $shell_return_value.success?
220
+ STDERR.puts out
221
+ STDERR.puts "Couldn't touch file: #{path}"
222
+ exit 1
223
+ end
216
224
  puts "Touched file: #{path}"
217
225
  end
218
226
  end
@@ -244,7 +252,12 @@ def symlink(from,to)
244
252
  STDERR.puts "Directory #{from} exists in place of symlink..."
245
253
  exit 1
246
254
  else
247
- out = shell("ln -s \"#{to}\" \"#{from}\"")
255
+ out = shell("ln -s \"#{to}\" \"#{from}\" 2>&1")
256
+ unless $shell_return_value.success?
257
+ STDERR.puts out
258
+ STDERR.puts "Couldn't create symlink: #{from} → #{to}"
259
+ exit 1
260
+ end
248
261
  puts "Created symlink: #{from} → #{to}"
249
262
  end
250
263
  end
@@ -257,20 +270,20 @@ def git(url,path,branch=nil,silent=false)
257
270
  chdir path
258
271
  out = nil
259
272
  if branch
260
- out = shell('git fetch',{:silent => silent})
273
+ out = shell('git fetch 2>&1',{:silent => silent})
261
274
  if out.size > 0
262
- puts out
275
+ puts out if silent
263
276
  end
264
- out = shell("git checkout #{branch}",{:silent => silent})
277
+ out = shell("git checkout #{branch} 2>&1",{:silent => silent})
265
278
  unless out.downcase.include? 'is now at'
266
- puts out
279
+ puts out if silent
267
280
  end
268
- out = shell("git pull origin #{branch}",{:silent => silent})
281
+ out = shell("git pull origin #{branch} 2>&1",{:silent => silent})
269
282
  else
270
- out = shell('git pull',{:silent => silent})
283
+ out = shell('git pull 2>&1',{:silent => silent})
271
284
  end
272
285
  unless out.downcase.include? "already up-to-date"
273
- puts out
286
+ puts out if silent
274
287
  puts "Git repository pulled: #{url} → #{path}"
275
288
  end
276
289
  chdir cwd
@@ -280,8 +293,8 @@ def git(url,path,branch=nil,silent=false)
280
293
  else
281
294
  branch = ''
282
295
  end
283
- out = shell("git clone #{branch}#{url} \"#{path}\"",{:silent => silent})
284
- puts out
296
+ out = shell("git clone #{branch}#{url} \"#{path}\" 2>&1",{:silent => silent})
297
+ puts out if silent
285
298
  puts "Git repository cloned: #{url} → #{path}"
286
299
  end
287
300
  end
@@ -291,6 +304,7 @@ def curl(url,path,verbose=false)
291
304
  path = abs(path)
292
305
  output = shell("curl -s -S \"#{url}\"",{:verbose => verbose, :silent => true})
293
306
  unless $shell_return_value.success?
307
+ STDERR.puts output
294
308
  STDERR.puts "Couldn't download file from #{url}..."
295
309
  exit 1
296
310
  end
@@ -338,7 +352,7 @@ def ls(path,options={})
338
352
  else
339
353
  dotfiles = ''
340
354
  end
341
- command = "ls -1 #{dotfiles}\"#{path}\""
355
+ command = "ls -1 #{dotfiles}\"#{path}\" 2>&1"
342
356
  if options.key?(:grep) && options[:grep].length > 0
343
357
  command += " | grep #{options[:grep]}"
344
358
  end
@@ -393,8 +407,8 @@ def run(file)
393
407
  cwd = pwd()
394
408
  file = abs(file)
395
409
  unless file_exists?(file)
396
- puts "No configuration file: #{file} found"
397
- return
410
+ STDERR.puts "No configuration file: #{file} found"
411
+ exit 1
398
412
  end
399
413
  puts "Running configuration: "+file
400
414
  file_cwd = file_dir(file)
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.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Geurkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-06 00:00:00.000000000 Z
11
+ date: 2018-03-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: central dotfile management system
14
14
  email: d.geurkov@gmail.com