configmonkey_cli 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/bin/configmonkey +9 -0
- data/bin/configmonkey.sh +14 -0
- data/configmonkey_cli.gemspec +27 -0
- data/lib/configmonkey_cli.rb +43 -0
- data/lib/configmonkey_cli/application.rb +159 -0
- data/lib/configmonkey_cli/application/colorize.rb +22 -0
- data/lib/configmonkey_cli/application/configuration.rb +38 -0
- data/lib/configmonkey_cli/application/configuration.tpl +0 -0
- data/lib/configmonkey_cli/application/core.rb +78 -0
- data/lib/configmonkey_cli/application/dispatch.rb +81 -0
- data/lib/configmonkey_cli/application/manifest.rb +316 -0
- data/lib/configmonkey_cli/application/manifest_actions/base.rb +90 -0
- data/lib/configmonkey_cli/application/manifest_actions/chmod.rb +40 -0
- data/lib/configmonkey_cli/application/manifest_actions/copy.rb +38 -0
- data/lib/configmonkey_cli/application/manifest_actions/custom.rb +52 -0
- data/lib/configmonkey_cli/application/manifest_actions/inplace.rb +28 -0
- data/lib/configmonkey_cli/application/manifest_actions/invoke.rb +45 -0
- data/lib/configmonkey_cli/application/manifest_actions/link.rb +46 -0
- data/lib/configmonkey_cli/application/manifest_actions/mkdir.rb +41 -0
- data/lib/configmonkey_cli/application/manifest_actions/remove.rb +46 -0
- data/lib/configmonkey_cli/application/manifest_actions/rsync.rb +112 -0
- data/lib/configmonkey_cli/application/manifest_actions/rtfm.rb +32 -0
- data/lib/configmonkey_cli/application/manifest_actions/sync_links.rb +60 -0
- data/lib/configmonkey_cli/application/manifest_actions/template.rb +38 -0
- data/lib/configmonkey_cli/application/output_helper.rb +30 -0
- data/lib/configmonkey_cli/helper.rb +62 -0
- data/lib/configmonkey_cli/version.rb +4 -0
- metadata +162 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
module ConfigmonkeyCli
|
2
|
+
class Application
|
3
|
+
module ManifestAction
|
4
|
+
class Rtfm < Base
|
5
|
+
def init directory, opts = {}
|
6
|
+
@directory = directory
|
7
|
+
@opts = opts.reverse_merge({
|
8
|
+
name: "__THIS_IS_A_GIT_BASED_CONFIG__",
|
9
|
+
symbolic: true,
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare
|
14
|
+
@actual_directory = expand_dst(@directory)
|
15
|
+
@link = File.join(@actual_directory, @opts[:name])
|
16
|
+
end
|
17
|
+
|
18
|
+
def simulate
|
19
|
+
if thor.options[:pretend]
|
20
|
+
destructive
|
21
|
+
else
|
22
|
+
status :fake, :black, rel(@link)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def destructive
|
27
|
+
thor.create_link(@link, manifest.directory)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ConfigmonkeyCli
|
2
|
+
class Application
|
3
|
+
module ManifestAction
|
4
|
+
class SyncLinks < Base
|
5
|
+
def init hargs_and_opts = {}
|
6
|
+
@args, @opts = args_and_opts(hargs_and_opts)
|
7
|
+
@opts = @opts.reverse_merge({
|
8
|
+
prefix: nil,
|
9
|
+
map: "d:dp",
|
10
|
+
hard: false,
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
def prepare
|
15
|
+
@opts[:force] = app.opts[:default_yes]
|
16
|
+
@opts[:symbolic] = !@opts[:hard]
|
17
|
+
|
18
|
+
#-----------------
|
19
|
+
@source = @args[0]
|
20
|
+
@destination = @args[1]
|
21
|
+
map = @opts[:map].split(":")
|
22
|
+
|
23
|
+
# prefix source
|
24
|
+
@source = File.join(map[0]["d"] ? thor.destination_root : manifest.directory, @source)
|
25
|
+
@destination = File.join(map[1]["d"] ? thor.destination_root : manifest.directory, @destination)
|
26
|
+
|
27
|
+
@sources = Dir[@source]
|
28
|
+
@sources = Dir["#{@sources[0]}/*"] if @sources.length == 1 && FileTest.directory?(@sources[0])
|
29
|
+
|
30
|
+
# prefix target link
|
31
|
+
if(@opts[:prefix] && map[1].downcase["p"])
|
32
|
+
@prefix = "cm--#{manifest.checksum(@opts[:prefix], soft: !map[1]["H"])}--"
|
33
|
+
@purge = map[1]["P"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def simulate
|
38
|
+
status :fake, :black, rel(@destination)
|
39
|
+
destructive if thor.options[:pretend]
|
40
|
+
end
|
41
|
+
|
42
|
+
def destructive
|
43
|
+
prefixed_sources = @sources.map do |src|
|
44
|
+
File.join(@destination, "#{@prefix}#{File.basename(src)}")
|
45
|
+
end
|
46
|
+
|
47
|
+
if @purge
|
48
|
+
(Dir["#{File.join(@destination, @prefix)}*"] - prefixed_sources).each do |f|
|
49
|
+
thor.remove_file(f)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
@sources.each do |src|
|
54
|
+
thor.create_link("#{@destination}/#{@prefix}#{File.basename(src)}", src, @opts)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ConfigmonkeyCli
|
2
|
+
class Application
|
3
|
+
module ManifestAction
|
4
|
+
class Template < Base
|
5
|
+
def init hargs_and_opts = {}
|
6
|
+
@args, @opts = args_and_opts(hargs_and_opts)
|
7
|
+
end
|
8
|
+
|
9
|
+
def prepare
|
10
|
+
@opts[:force] = app.opts[:default_yes]
|
11
|
+
@source = @args[0]
|
12
|
+
@destination = File.join(thor.destination_root, @args[1])
|
13
|
+
end
|
14
|
+
|
15
|
+
def simulate
|
16
|
+
if thor.options[:pretend]
|
17
|
+
destructive
|
18
|
+
else
|
19
|
+
status :fake, :black, rel(@destination)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def destructive
|
24
|
+
absolute_source = File.join(thor.source_paths[0], @source)
|
25
|
+
if FileTest.directory?(absolute_source)
|
26
|
+
status :invalid, :red, "directory not allowed for template", :red
|
27
|
+
else
|
28
|
+
thor.template(@source, @destination, @opts.merge(context: binding))
|
29
|
+
if @opts[:chmod] && File.exist?(absolute_source) && File.exist?(@destination)
|
30
|
+
mode = @opts[:chmod] == true ? File.stat(absolute_source).mode - 0100000 : @opts[:chmod]
|
31
|
+
thor.chmod(@destination, mode) unless mode == File.stat(@destination).mode - 0100000
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ConfigmonkeyCli
|
2
|
+
class Application
|
3
|
+
module OutputHelper
|
4
|
+
def puts *a
|
5
|
+
sync { @opts[:stdout].send(:puts, *a) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def print *a
|
9
|
+
sync { @opts[:stdout].send(:print, *a) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def warn *a
|
13
|
+
sync { @opts[:stdout].send(:warn, *a) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def debug msg, lvl = 1
|
17
|
+
puts c("[DEBUG] #{msg}", :black) if @opts[:debug] && @opts[:debug] >= lvl
|
18
|
+
end
|
19
|
+
|
20
|
+
def abort msg, exit_code = 1
|
21
|
+
puts c("[ABORT] #{msg}", :red)
|
22
|
+
exit(exit_code)
|
23
|
+
end
|
24
|
+
|
25
|
+
def error msg
|
26
|
+
warn c(msg, :red)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module ConfigmonkeyCli
|
2
|
+
module Helper
|
3
|
+
BYTE_UNITS = %W(TiB GiB MiB KiB B).freeze
|
4
|
+
|
5
|
+
def human_filesize(s)
|
6
|
+
s = s.to_f
|
7
|
+
i = BYTE_UNITS.length - 1
|
8
|
+
while s > 512 && i > 0
|
9
|
+
i -= 1
|
10
|
+
s /= 1024
|
11
|
+
end
|
12
|
+
((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s) + ' ' + BYTE_UNITS[i]
|
13
|
+
end
|
14
|
+
|
15
|
+
def human_number(n)
|
16
|
+
n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
|
17
|
+
end
|
18
|
+
|
19
|
+
def human_seconds secs
|
20
|
+
secs = secs.to_i
|
21
|
+
t_minute = 60
|
22
|
+
t_hour = t_minute * 60
|
23
|
+
t_day = t_hour * 24
|
24
|
+
t_week = t_day * 7
|
25
|
+
t_month = t_day * 30
|
26
|
+
t_year = t_month * 12
|
27
|
+
"".tap do |r|
|
28
|
+
if secs >= t_year
|
29
|
+
r << "#{secs / t_year}y "
|
30
|
+
secs = secs % t_year
|
31
|
+
end
|
32
|
+
|
33
|
+
if secs >= t_month
|
34
|
+
r << "#{secs / t_month}m "
|
35
|
+
secs = secs % t_month
|
36
|
+
end
|
37
|
+
|
38
|
+
if secs >= t_week
|
39
|
+
r << "#{secs / t_week}w "
|
40
|
+
secs = secs % t_week
|
41
|
+
end
|
42
|
+
|
43
|
+
if secs >= t_day || !r.blank?
|
44
|
+
r << "#{secs / t_day}d "
|
45
|
+
secs = secs % t_day
|
46
|
+
end
|
47
|
+
|
48
|
+
if secs >= t_hour || !r.blank?
|
49
|
+
r << "#{secs / t_hour}h "
|
50
|
+
secs = secs % t_hour
|
51
|
+
end
|
52
|
+
|
53
|
+
if secs >= t_minute || !r.blank?
|
54
|
+
r << "#{secs / t_minute}m "
|
55
|
+
secs = secs % t_minute
|
56
|
+
end
|
57
|
+
|
58
|
+
r << "#{secs}s" unless r.include?("d")
|
59
|
+
end.strip
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configmonkey_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sven Pachnit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Basically chef/puppet for the brainless
|
98
|
+
email:
|
99
|
+
- sven@bmonkeys.net
|
100
|
+
executables:
|
101
|
+
- configmonkey
|
102
|
+
- configmonkey.sh
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- VERSION
|
112
|
+
- bin/configmonkey
|
113
|
+
- bin/configmonkey.sh
|
114
|
+
- configmonkey_cli.gemspec
|
115
|
+
- lib/configmonkey_cli.rb
|
116
|
+
- lib/configmonkey_cli/application.rb
|
117
|
+
- lib/configmonkey_cli/application/colorize.rb
|
118
|
+
- lib/configmonkey_cli/application/configuration.rb
|
119
|
+
- lib/configmonkey_cli/application/configuration.tpl
|
120
|
+
- lib/configmonkey_cli/application/core.rb
|
121
|
+
- lib/configmonkey_cli/application/dispatch.rb
|
122
|
+
- lib/configmonkey_cli/application/manifest.rb
|
123
|
+
- lib/configmonkey_cli/application/manifest_actions/base.rb
|
124
|
+
- lib/configmonkey_cli/application/manifest_actions/chmod.rb
|
125
|
+
- lib/configmonkey_cli/application/manifest_actions/copy.rb
|
126
|
+
- lib/configmonkey_cli/application/manifest_actions/custom.rb
|
127
|
+
- lib/configmonkey_cli/application/manifest_actions/inplace.rb
|
128
|
+
- lib/configmonkey_cli/application/manifest_actions/invoke.rb
|
129
|
+
- lib/configmonkey_cli/application/manifest_actions/link.rb
|
130
|
+
- lib/configmonkey_cli/application/manifest_actions/mkdir.rb
|
131
|
+
- lib/configmonkey_cli/application/manifest_actions/remove.rb
|
132
|
+
- lib/configmonkey_cli/application/manifest_actions/rsync.rb
|
133
|
+
- lib/configmonkey_cli/application/manifest_actions/rtfm.rb
|
134
|
+
- lib/configmonkey_cli/application/manifest_actions/sync_links.rb
|
135
|
+
- lib/configmonkey_cli/application/manifest_actions/template.rb
|
136
|
+
- lib/configmonkey_cli/application/output_helper.rb
|
137
|
+
- lib/configmonkey_cli/helper.rb
|
138
|
+
- lib/configmonkey_cli/version.rb
|
139
|
+
homepage: https://github.com/2called-chaos/configmonkey_cli
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubygems_version: 3.1.2
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Configmonkey CLI - dead simple helper for git based server configs
|
162
|
+
test_files: []
|