central 0.3.1 → 0.3.3
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 +4 -4
- data/bin/central +1 -1
- data/lib/central.rb +34 -25
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 562fdc501fa3f7d9b74a949f4d1ca5b62014dffbe0bc0c9e7906c834081b122a
|
4
|
+
data.tar.gz: e7972ea4c6e1f552252ea227aa5e5f298b6dbeb47ce07304b5d1030a7d6e6cc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c20230fb3d4617e3386299dacc13bace1f909d079e3ce103cdb7fe0f5f7ea575225b90dd2ba926badc2154518209d8e74b2f21a79a4d186c61cdf0e4d1ce4723
|
7
|
+
data.tar.gz: 57f70c6468a316a1fc7a5d713d647dda9509350d03d484677a317935245196d2b30fdc3a35bc45c5ea407b9319238debcb1bb3136c83bebd2f41a47f2d2a0680
|
data/bin/central
CHANGED
data/lib/central.rb
CHANGED
@@ -105,24 +105,16 @@ def shell(command, verbose: false, silent: true)
|
|
105
105
|
info 'Executing', command if verbose
|
106
106
|
exit_code = nil
|
107
107
|
stdout = String.new
|
108
|
-
stdout_line = String.new
|
109
108
|
stderr = String.new
|
110
|
-
stderr_line = String.new
|
111
109
|
Open3.popen3(command) do |_, o, e, t|
|
112
110
|
stdout_open = true
|
113
111
|
stderr_open = true
|
114
112
|
while stdout_open || stderr_open
|
115
113
|
if stdout_open
|
116
114
|
begin
|
117
|
-
|
118
|
-
stdout
|
119
|
-
unless silent
|
120
|
-
stdout_line += ch
|
121
|
-
if ch == "\n"
|
122
|
-
STDOUT.puts stdout_line
|
123
|
-
stdout_line = ''
|
124
|
-
end
|
125
|
-
end
|
115
|
+
buffer = o.read_nonblock(4096)
|
116
|
+
stdout << buffer
|
117
|
+
STDOUT.write(buffer) unless silent
|
126
118
|
rescue IO::WaitReadable
|
127
119
|
IO.select([o], nil, nil, 0.01) unless stderr_open
|
128
120
|
rescue EOFError
|
@@ -132,15 +124,9 @@ def shell(command, verbose: false, silent: true)
|
|
132
124
|
next unless stderr_open
|
133
125
|
|
134
126
|
begin
|
135
|
-
|
136
|
-
stderr
|
137
|
-
unless silent
|
138
|
-
stderr_line += ch
|
139
|
-
if ch == "\n"
|
140
|
-
STDERR.puts stderr_line
|
141
|
-
stderr_line = ''
|
142
|
-
end
|
143
|
-
end
|
127
|
+
buffer = e.read_nonblock(4096)
|
128
|
+
stderr << buffer
|
129
|
+
STDERR.write(buffer) unless silent
|
144
130
|
rescue IO::WaitReadable
|
145
131
|
IO.select([e], nil, nil, 0.01) unless stdout_open
|
146
132
|
rescue EOFError
|
@@ -335,6 +321,29 @@ def symlink(from, to)
|
|
335
321
|
end
|
336
322
|
end
|
337
323
|
|
324
|
+
# extract archive, supports tar, zip, 7z
|
325
|
+
def extract(path, todir)
|
326
|
+
path = abs(path)
|
327
|
+
todir = abs(todir)
|
328
|
+
unless file_exists?(path)
|
329
|
+
fail "Archive file #{path} does not exists"
|
330
|
+
end
|
331
|
+
mkdir(todir)
|
332
|
+
info 'Extracting archive', "#{path} → #{todir}"
|
333
|
+
exit_code = nil, output = nil
|
334
|
+
if path.end_with?('.zip')
|
335
|
+
exit_code, output, = shell("unzip \"#{path}\" -d \"#{todir}\" 2>&1")
|
336
|
+
elsif path.end_with?('.7z')
|
337
|
+
exit_code, output, = shell("7z x -o\"#{todir}\" \"#{path}\" 2>&1")
|
338
|
+
else
|
339
|
+
exit_code, output, = shell("tar -xf \"#{path}\" -C \"#{todir}\" 2>&1")
|
340
|
+
end
|
341
|
+
unless exit_code.success?
|
342
|
+
error output
|
343
|
+
fail "Couldn't extract archive", path
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
338
347
|
# git clone url into a path
|
339
348
|
def git(url, path, branch: nil, silent: true, depth: nil)
|
340
349
|
path = abs(path)
|
@@ -369,14 +378,14 @@ def git(url, path, branch: nil, silent: true, depth: nil)
|
|
369
378
|
end
|
370
379
|
|
371
380
|
# download url into a path using curl
|
372
|
-
def curl(url, path, content_length_check: false, verbose: false)
|
381
|
+
def curl(url, path, content_length_check: false, verbose: false, flags: '-L -s -S')
|
373
382
|
path = abs(path)
|
374
383
|
if content_length_check and file_exists?(path)
|
375
|
-
content_length = curl_headers(url, verbose: verbose)['content-length'].to_i
|
384
|
+
content_length = curl_headers(url, verbose: verbose, flags: flags)['content-length'].to_i
|
376
385
|
return if file_size(path) == content_length
|
377
386
|
end
|
378
387
|
info 'Downloading', "#{url} → #{path}"
|
379
|
-
exit_code, output, = shell("curl
|
388
|
+
exit_code, output, = shell("curl #{flags} \"#{url}\"",
|
380
389
|
verbose: verbose, silent: true)
|
381
390
|
unless exit_code.success?
|
382
391
|
error output
|
@@ -387,8 +396,8 @@ def curl(url, path, content_length_check: false, verbose: false)
|
|
387
396
|
end
|
388
397
|
|
389
398
|
# get url response headers as Hash using curl
|
390
|
-
def curl_headers(url, method: 'HEAD', verbose: false)
|
391
|
-
exit_code, output, = shell("curl -I -X #{method}
|
399
|
+
def curl_headers(url, method: 'HEAD', verbose: false, flags: '-L -s -S')
|
400
|
+
exit_code, output, = shell("curl -I -X #{method} #{flags} \"#{url}\"",
|
392
401
|
verbose: verbose, silent: true)
|
393
402
|
unless exit_code.success?
|
394
403
|
error output
|
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.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Geurkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: central dotfile management system
|
14
14
|
email: d.geurkov@gmail.com
|
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
rubygems_version: 3.2.
|
41
|
+
rubygems_version: 3.2.22
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: central dotfile management
|