danarchy_deploy 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.asdf_versions.json +5 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +9 -8
- data/danarchy_deploy.gemspec +4 -4
- data/lib/danarchy_deploy/groups.rb +0 -1
- data/lib/danarchy_deploy/services/init/openrc.rb +10 -6
- data/lib/danarchy_deploy/services/init.rb +28 -18
- data/lib/danarchy_deploy/services.rb +0 -1
- data/lib/danarchy_deploy/system/centos.rb +7 -0
- data/lib/danarchy_deploy/system/debian.rb +6 -0
- data/lib/danarchy_deploy/system/gentoo.rb +83 -23
- data/lib/danarchy_deploy/system/opensuse.rb +6 -0
- data/lib/danarchy_deploy/system.rb +22 -10
- data/lib/danarchy_deploy/templater.rb +26 -9
- data/lib/danarchy_deploy/users.rb +50 -42
- data/lib/danarchy_deploy/version.rb +1 -1
- data/lib/danarchy_deploy.rb +61 -19
- data/templates/applications/nginx/domain.conf.erb +38 -0
- data/templates/applications/php/phpfpm.conf.erb +19 -0
- data/templates/applications/php/user.conf.erb +19 -0
- data/templates/applications/wordpress/mysql_user_privileges.sql.erb +2 -0
- data/templates/applications/wordpress/wp-config.php.erb +82 -0
- data/templates/asdf/asdf.sh.erb +52 -0
- data/templates/deploy_template.json +76 -50
- data/templates/distcc/distccd.erb +14 -0
- data/templates/distcc/hosts.erb +2 -0
- data/templates/portage/make.conf.erb +30 -0
- data/templates/portage/package.use/bindist +3 -0
- data/templates/portage/package.use/documentation +3 -0
- data/templates/services/memcached/memcached.erb +40 -0
- data/templates/services/mysql/my.cnf.erb +143 -0
- data/templates/services/mysql/root_my.cnf.erb +11 -0
- data/templates/services/mysql/user_db_grants.sql.erb +33 -0
- data/templates/services/mysql/user_db_grants.sql.erb_cleanupUsers +52 -0
- data/templates/services/nginx/nginx.conf.erb +48 -0
- data/templates/services/php/php-fpm.conf.erb +2 -0
- data/templates/services/postfix/localmail.initial_setup.sh +19 -0
- data/templates/services/postfix/localmail.main.cf.erb +41 -0
- data/templates/services/postfix/mailname.erb +1 -0
- data/templates/services/postfix/mailrelayhost_main.cf.erb +33 -0
- data/templates/services/postfix/main.cf.erb +28 -0
- data/templates/services/postfix/master.cf.erb +124 -0
- data/templates/services/postfix/mysql-virtual-alias-maps.cf.erb +5 -0
- data/templates/services/postfix/mysql-virtual-mailbox-domains.cf.erb +5 -0
- data/templates/services/postfix/mysql-virtual-mailbox-maps.cf.erb +5 -0
- data/templates/system/authorized_keys.erb +5 -0
- data/templates/system/crontab.erb +8 -0
- data/templates/system/dmcrypt.erb +17 -0
- data/templates/system/exports.erb +4 -0
- data/templates/system/fstab.erb +4 -0
- data/templates/system/sudoers.erb +5 -0
- metadata +44 -11
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- /data/bin/{setup → setup-dd} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 637fb3a1e9810606d864cbc0acab785194ce1fd101c1d74b1135cda4cf489229
|
4
|
+
data.tar.gz: 8886abdb6002348b7fe4fe1d9b27e90766bfd568b30513d246460b2c2dadd188
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bd45a91ea250c523e7ddaca5f8b06e91f8ebd52ede360389fb612354e383720b316f9652aa94400d6ec1204b02205b3556dcabf47842a17350e04c46389b1e9
|
7
|
+
data.tar.gz: 74283e5e2b7ee9d6d3abb15791fc9a742c1e8329eba28d680185380e4682799749b13c848923f3c6b77b2c9ed3fa8585f3f8b0619289aecd11eae363737f9e12
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.2.2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
patch_0.2.8
|
2
|
+
- Switch support from RVM to ASDF
|
3
|
+
- users.rb: use Templater to handle authorized_users and sudoers
|
4
|
+
- danarchy_deploy.rb: ignore WARNs in gem install
|
5
|
+
- danarchy_deploy.rb: use sudo -i to load environment
|
6
|
+
- Templater: add builtin templates
|
7
|
+
- Gentoo: wait_for_sync
|
8
|
+
- System::Init: OpenRC runlevel support
|
9
|
+
|
10
|
+
patch_0.2.7
|
11
|
+
- Patch Templater ERB.new for Ruby versions higher than 2.6
|
12
|
+
- Allow builtin:: templates in Templater
|
13
|
+
- System: allow :system:updates in template to control what to install/update
|
14
|
+
- System: do not return if :system is not defined in template
|
15
|
+
|
1
16
|
patch_0.2.6
|
2
17
|
- DanarchyDeploy: gem install --bindir
|
3
18
|
- DanarchyDeploy: return from each class if not defined in a deployment
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danarchy_deploy (0.2.
|
4
|
+
danarchy_deploy (0.2.8)
|
5
5
|
danarchy_couchdb (~> 0.1)
|
6
|
-
mongo (~> 2.
|
6
|
+
mongo (~> 2.20)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
bson (
|
11
|
+
bson (5.0.1)
|
12
12
|
danarchy_couchdb (0.1.3)
|
13
|
-
mongo (2.
|
14
|
-
bson (>= 4.
|
15
|
-
rake (13.
|
13
|
+
mongo (2.20.1)
|
14
|
+
bson (>= 4.14.1, < 6.0.0)
|
15
|
+
rake (13.2.1)
|
16
16
|
|
17
17
|
PLATFORMS
|
18
|
+
ruby
|
18
19
|
x86_64-linux
|
19
20
|
|
20
21
|
DEPENDENCIES
|
21
|
-
bundler (~> 2.
|
22
|
+
bundler (~> 2.5)
|
22
23
|
danarchy_deploy!
|
23
24
|
rake (~> 13.0)
|
24
25
|
|
25
26
|
BUNDLED WITH
|
26
|
-
2.
|
27
|
+
2.5.11
|
data/danarchy_deploy.gemspec
CHANGED
@@ -28,10 +28,10 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
-
spec.add_dependency
|
31
|
+
spec.add_dependency 'danarchy_couchdb', '~> 0.1'
|
32
32
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.5'
|
34
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
35
35
|
|
36
|
-
spec.add_runtime_dependency
|
36
|
+
spec.add_runtime_dependency 'mongo', '~> 2.20'
|
37
37
|
end
|
@@ -3,9 +3,10 @@ module DanarchyDeploy
|
|
3
3
|
module Services
|
4
4
|
class Init
|
5
5
|
class Openrc
|
6
|
-
def initialize(service, options)
|
7
|
-
@service
|
8
|
-
@
|
6
|
+
def initialize(service, runlevel, options)
|
7
|
+
@service = service
|
8
|
+
@runlevel = runlevel
|
9
|
+
@options = options
|
9
10
|
end
|
10
11
|
|
11
12
|
def status
|
@@ -58,13 +59,16 @@ module DanarchyDeploy
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def enable
|
61
|
-
cmd = "rc-update add #{@service}
|
62
|
+
cmd = "rc-update add #{@service} #{@runlevel}"
|
62
63
|
DanarchyDeploy::Helpers.run_command(cmd, @options)
|
63
64
|
end
|
64
65
|
|
65
66
|
def disable
|
66
|
-
|
67
|
-
|
67
|
+
Dir["/etc/runlevels/*/#{@service}"].each do |svc|
|
68
|
+
runlevel, service = svc.split('/')[3,4]
|
69
|
+
cmd = "rc-update del #{service} #{runlevel}"
|
70
|
+
DanarchyDeploy::Helpers.run_command(cmd, @options)
|
71
|
+
end
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
@@ -10,42 +10,52 @@ module DanarchyDeploy
|
|
10
10
|
|
11
11
|
deployment[:services].each do |service, params|
|
12
12
|
next if ! params[:init]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
if params[:init].class == Array
|
14
|
+
# one-time update for :init to new format
|
15
|
+
params[:init] = if deployment[:os] == 'gentoo'
|
16
|
+
{ runlevel: 'default', actions: params[:init] }
|
17
|
+
else
|
18
|
+
{ actions: params[:init] }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
init_manager(deployment[:os], service, params[:init][:runlevel], options)
|
23
|
+
puts "\n > Init actions for #{service}: #{params[:init][:actions].join(', ')}"
|
24
|
+
params[:init][:actions].each do |action|
|
25
|
+
puts " |> Taking action: #{action} on #{service}"
|
17
26
|
if options[:pretend]
|
18
|
-
puts "
|
27
|
+
puts " |- Fake run: #{action} #{service}"
|
19
28
|
else
|
20
|
-
|
29
|
+
init_run(action)
|
21
30
|
end
|
22
31
|
end
|
23
|
-
|
24
|
-
params[:init] = orig_actions
|
25
32
|
end
|
26
33
|
|
27
34
|
deployment
|
28
35
|
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
private
|
38
|
+
def self.init_manager(os, service, runlevel='default', options)
|
39
|
+
@init = if os == 'gentoo'
|
40
|
+
DanarchyDeploy::Services::Init::Openrc.new(service, runlevel, options)
|
41
|
+
else
|
42
|
+
DanarchyDeploy::Services::Init::Systemd.new(service, options)
|
43
|
+
end
|
44
|
+
end
|
36
45
|
|
37
|
-
|
46
|
+
def self.init_run(action)
|
47
|
+
init_result = @init.send(action)
|
38
48
|
|
39
49
|
if stderr = init_result[:stderr]
|
40
50
|
if stderr.include?('unknown function')
|
41
|
-
puts " ! Action: #{action} not available for service
|
51
|
+
puts " ! Action: #{action} not available for service.\n" +
|
42
52
|
" ! A restart may be needed! Otherwise, remove this action from the deployment.\n" +
|
43
53
|
" ! Not taking any action here.\n"
|
44
54
|
else
|
45
|
-
abort(" ! Action: #{action}
|
55
|
+
abort(" ! Action: #{action} failed!")
|
46
56
|
end
|
47
57
|
else
|
48
|
-
puts " |+ Action: #{action}
|
58
|
+
puts " |+ Action: #{action} succeeded."
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
@@ -6,12 +6,19 @@ module DanarchyDeploy
|
|
6
6
|
puts "\n" + self.name
|
7
7
|
puts "#{deployment[:os].capitalize} detected! Using yum."
|
8
8
|
# needs more testing
|
9
|
+
|
10
|
+
set_hostname(deployment[:hostname]) if !options[:pretend]
|
9
11
|
installer = 'yum install -y '
|
10
12
|
updater = 'yum upgrade -y'
|
11
13
|
cleaner = 'yum clean all'
|
12
14
|
|
13
15
|
[installer, updater, cleaner]
|
14
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def set_hostname(hostname)
|
20
|
+
`hostnamectl hostname #{hostname}`
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
@@ -7,6 +7,7 @@ module DanarchyDeploy
|
|
7
7
|
puts "\n" + self.name
|
8
8
|
puts "#{deployment[:os].capitalize} detected! Using apt."
|
9
9
|
|
10
|
+
set_hostname(deployment[:hostname]) if !options[:pretend]
|
10
11
|
if deployment[:apt]
|
11
12
|
if deployment[:apt][:templates]
|
12
13
|
puts "\nChecking Apt configs."
|
@@ -56,6 +57,11 @@ module DanarchyDeploy
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def set_hostname(hostname)
|
63
|
+
`hostnamectl hostname #{hostname}`
|
64
|
+
end
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|
@@ -6,12 +6,7 @@ module DanarchyDeploy
|
|
6
6
|
puts "\n" + self.name
|
7
7
|
puts 'Gentoo detected! Using emerge.'
|
8
8
|
|
9
|
-
hostname
|
10
|
-
if check_hostname(hostname) == false
|
11
|
-
puts "Setting hostname to: #{hostname}"
|
12
|
-
set_hostname(hostname)
|
13
|
-
end
|
14
|
-
|
9
|
+
set_hostname(deployment[:hostname]) if !options[:pretend]
|
15
10
|
installer = 'emerge --usepkg --buildpkg --quiet --noreplace '
|
16
11
|
# This needs cpuid2cpuflags to build make.conf; don't --pretend here.
|
17
12
|
system("qlist -I cpuid2cpuflags &>/dev/null || #{installer} cpuid2cpuflags &>/dev/null")
|
@@ -23,43 +18,108 @@ module DanarchyDeploy
|
|
23
18
|
cleaner = 'emerge --depclean --quiet '
|
24
19
|
cleaner += '--pretend ' if options[:pretend]
|
25
20
|
|
21
|
+
if emerge_sync_in_progress
|
22
|
+
puts "\n > Waiting for emerge sync to complete."
|
23
|
+
emerge_sync_wait
|
24
|
+
end
|
25
|
+
|
26
26
|
if deployment[:portage]
|
27
27
|
if deployment[:portage][:templates]
|
28
28
|
puts "\nChecking Portage configs."
|
29
29
|
DanarchyDeploy::Templater.new(deployment[:portage][:templates], options)
|
30
30
|
end
|
31
31
|
|
32
|
-
emerge_sync(
|
32
|
+
emerge_sync(deployment[:portage][:sync], options)
|
33
33
|
end
|
34
34
|
|
35
35
|
[installer, updater, cleaner]
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
39
|
+
def self.emerge_sync_in_progress
|
40
|
+
repo_path = `emerge --info | grep location`.chomp.split(': ').last
|
41
|
+
Dir.exist?(repo_path + '/.tmp-unverified-download-quarantine')
|
42
|
+
end
|
39
43
|
|
40
|
-
def self.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
DanarchyDeploy::Helpers.run_command('emerge --sync --quiet 2>/dev/null', options)
|
47
|
-
f.truncate(0)
|
48
|
-
f.write DateTime.now
|
49
|
-
end
|
44
|
+
def self.emerge_sync_wait
|
45
|
+
while emerge_sync_in_progress
|
46
|
+
sleep 3
|
47
|
+
end
|
48
|
+
puts " |> Continuing with emerge!"
|
49
|
+
end
|
50
50
|
|
51
|
-
|
51
|
+
def self.emerge_sync(sync, options)
|
52
|
+
if sync.nil?
|
53
|
+
install_cron_template(sync, options)
|
54
|
+
elsif sync == false
|
55
|
+
puts "\nNot running emerge sync; set to: #{sync}"
|
56
|
+
install_cron_template(sync, options)
|
57
|
+
elsif sync == true
|
58
|
+
File.delete('/var/spool/cron/crontabs/portage') if File.exist?('/var/spool/cron/crontabs/portage')
|
59
|
+
DanarchyDeploy::Helpers.run_command('emerge --sync &>/var/log/emerge-sync.log', options)
|
60
|
+
elsif sync =~ /([0-9]{1,2}|\*|\@[a-z]{4,7})/i
|
61
|
+
install_cron_template(sync, options)
|
62
|
+
else
|
63
|
+
puts "\nUnknown sync cron time: #{sync}. Not running emerge sync!"
|
52
64
|
end
|
53
65
|
end
|
54
66
|
|
55
67
|
def self.set_hostname(hostname)
|
56
|
-
|
57
|
-
|
58
|
-
|
68
|
+
if `hostname`.chomp != hostname
|
69
|
+
puts "Setting hostname to: #{hostname}"
|
70
|
+
confd_hostname = "hostname=\"#{hostname}\""
|
71
|
+
File.write('/etc/conf.d/hostname', confd_hostname)
|
72
|
+
`hostname #{hostname}`
|
73
|
+
end
|
59
74
|
end
|
60
75
|
|
61
|
-
def self.
|
62
|
-
|
76
|
+
def self.install_cron_template(sync, options)
|
77
|
+
templates = if sync.nil? || sync == false
|
78
|
+
[
|
79
|
+
{
|
80
|
+
target: '/var/spool/cron/crontabs/portage',
|
81
|
+
remove: true
|
82
|
+
}
|
83
|
+
]
|
84
|
+
else
|
85
|
+
[
|
86
|
+
{
|
87
|
+
source: 'builtin::system/crontab.erb',
|
88
|
+
target: '/var/spool/cron/crontabs/portage',
|
89
|
+
dir_perms: {
|
90
|
+
owner: 'root',
|
91
|
+
group: 'crontab',
|
92
|
+
mode: '1730'
|
93
|
+
},
|
94
|
+
file_perms: {
|
95
|
+
owner: 'portage',
|
96
|
+
group: 'crontab',
|
97
|
+
mode: '0600'
|
98
|
+
},
|
99
|
+
variables: {
|
100
|
+
shell: '/bin/bash',
|
101
|
+
path: '/usr/local/sbin:/usr/local/bin:/usr/bin',
|
102
|
+
env: '',
|
103
|
+
jobs: [
|
104
|
+
{
|
105
|
+
schedule: sync,
|
106
|
+
command: 'emerge --sync &>/var/log/emerge-sync.log'
|
107
|
+
},
|
108
|
+
{
|
109
|
+
schedule: '@daily',
|
110
|
+
command: 'eclean-dist &>/dev/null'
|
111
|
+
},
|
112
|
+
{
|
113
|
+
schedule: '@daily',
|
114
|
+
command: 'eclean-pkg &>/dev/null'
|
115
|
+
}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
}
|
119
|
+
]
|
120
|
+
end
|
121
|
+
|
122
|
+
DanarchyDeploy::Templater.new(templates, options)
|
63
123
|
end
|
64
124
|
end
|
65
125
|
end
|
@@ -6,6 +6,7 @@ module DanarchyDeploy
|
|
6
6
|
puts "\n" + self.name
|
7
7
|
puts "#{deployment[:os].capitalize} detected! Using zypper."
|
8
8
|
|
9
|
+
set_hostname(deployment[:hostname]) if !options[:pretend]
|
9
10
|
puts "Updating zypper repositories..."
|
10
11
|
DanarchyDeploy::Helpers.run_command('sudo zypper refresh', options)
|
11
12
|
|
@@ -17,6 +18,11 @@ module DanarchyDeploy
|
|
17
18
|
|
18
19
|
[installer, updater, cleaner]
|
19
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def set_hostname(hostname)
|
24
|
+
`hostnamectl hostname #{hostname}`
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -3,32 +3,43 @@ require_relative 'system/debian'
|
|
3
3
|
require_relative 'system/gentoo'
|
4
4
|
require_relative 'system/opensuse'
|
5
5
|
|
6
|
-
require_relative 'system/cryptsetup'
|
6
|
+
# require_relative 'system/cryptsetup'
|
7
7
|
require_relative 'system/fstab'
|
8
8
|
|
9
9
|
module DanarchyDeploy
|
10
10
|
module System
|
11
11
|
def self.new(deployment, options)
|
12
12
|
abort('Operating System not defined! Exiting!') if !deployment[:os]
|
13
|
-
return deployment if ! deployment[:system]
|
14
13
|
puts "\n" + self.name
|
15
14
|
|
16
15
|
installer, updater, cleaner = prep_operating_system(deployment, options)
|
17
|
-
install_result = nil
|
18
|
-
|
16
|
+
install_result, updater_result = nil, nil
|
17
|
+
|
18
|
+
puts "\n > Package Installation"
|
19
|
+
if [true, 'all', 'selected', nil].include?(deployment[:system][:update]) &&
|
20
|
+
deployment[:packages].any?
|
19
21
|
packages = deployment[:packages].join(' ')
|
20
|
-
puts "\
|
22
|
+
puts "\n - Installing packages..."
|
21
23
|
install_result = DanarchyDeploy::Helpers.run_command("#{installer} #{packages}", options)
|
22
24
|
puts install_result[:stdout] if install_result[:stdout]
|
23
25
|
else
|
24
|
-
puts "\
|
26
|
+
puts "\n - Not installing packages."
|
27
|
+
puts " |_ Packages selected: #{deployment[:packages].count}"
|
28
|
+
puts " |_ Updates selected: #{deployment[:system][:update]}"
|
25
29
|
end
|
26
30
|
|
27
|
-
|
28
|
-
|
31
|
+
puts "\n > #{deployment[:os].capitalize} System Updates"
|
32
|
+
if [true, 'all', 'system', nil].include?(deployment[:system][:update])
|
33
|
+
puts "\n - Running system updates..."
|
29
34
|
updater_result = DanarchyDeploy::Helpers.run_command(updater, options)
|
30
35
|
puts updater_result[:stdout] if updater_result[:stdout]
|
31
|
-
|
36
|
+
else
|
37
|
+
puts "\n - Not running #{deployment[:os].capitalize} system updates."
|
38
|
+
puts " |_ Updates selected: #{deployment[:system][:update]}"
|
39
|
+
end
|
40
|
+
|
41
|
+
if install_result || updater_result
|
42
|
+
puts "\n - Cleaning up unused packages..."
|
32
43
|
cleanup_result = DanarchyDeploy::Helpers.run_command(cleaner, options)
|
33
44
|
puts cleanup_result[:stdout] if cleanup_result[:stdout]
|
34
45
|
end
|
@@ -52,7 +63,8 @@ module DanarchyDeploy
|
|
52
63
|
DanarchyDeploy::Templater.new(deployment[:system][:templates], options)
|
53
64
|
end
|
54
65
|
|
55
|
-
|
66
|
+
# Disabled due to Init changes; re-writing and splitting LVM/CryptSetup
|
67
|
+
# DanarchyDeploy::System::Cryptsetup.new(deployment[:os], deployment[:system][:cryptsetup], options)
|
56
68
|
|
57
69
|
if deployment[:system][:fstab]
|
58
70
|
DanarchyDeploy::System::Fstab.new(deployment[:os], deployment[:system][:fstab], options)
|
@@ -3,6 +3,15 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
module DanarchyDeploy
|
5
5
|
class Templater
|
6
|
+
def self.load_source(source)
|
7
|
+
if source =~ /^builtin::/
|
8
|
+
source = File.expand_path('../../', __dir__) + '/templates/' + source.split('::').last
|
9
|
+
end
|
10
|
+
|
11
|
+
abort("Source file does not exist at: #{source}") if ! File.exist?(source)
|
12
|
+
source
|
13
|
+
end
|
14
|
+
|
6
15
|
def self.new(templates, options)
|
7
16
|
puts "\n" + self.name
|
8
17
|
|
@@ -13,12 +22,17 @@ module DanarchyDeploy
|
|
13
22
|
|
14
23
|
templates.each do |template|
|
15
24
|
next if template[:remove]
|
16
|
-
|
17
|
-
|
18
|
-
|
25
|
+
source = if !template[:target]
|
26
|
+
abort("No target destination set for template: #{template[:source]}!")
|
27
|
+
elsif template[:source].nil? && template[:data].nil?
|
28
|
+
abort("No source or data for template: #{template[:target]}")
|
29
|
+
elsif template[:data]
|
30
|
+
'-- encoded data --'
|
31
|
+
else
|
32
|
+
load_source(template[:source])
|
33
|
+
end
|
19
34
|
|
20
35
|
target = template[:target]
|
21
|
-
source = template[:source] || '-- encoded data --'
|
22
36
|
dir_perms = template[:dir_perms]
|
23
37
|
file_perms = template[:file_perms]
|
24
38
|
@variables = template[:variables] || nil
|
@@ -43,7 +57,11 @@ module DanarchyDeploy
|
|
43
57
|
end
|
44
58
|
|
45
59
|
File.open(tmpfile, 'w') do |f|
|
46
|
-
result =
|
60
|
+
result = if RUBY_VERSION >= '2.6'
|
61
|
+
ERB.new(File.read(source), trim_mode: '-').result(binding)
|
62
|
+
else
|
63
|
+
ERB.new(File.read(source), nil, '-').result(binding)
|
64
|
+
end
|
47
65
|
f.write(result)
|
48
66
|
f.close
|
49
67
|
end
|
@@ -54,7 +72,7 @@ module DanarchyDeploy
|
|
54
72
|
puts "\n - Fake Run: Not changing '#{target}'."
|
55
73
|
result[:verify_permissions][File.dirname(tmpfile)] = verify_permissions(File.dirname(tmpfile), dir_perms, options)
|
56
74
|
result[:verify_permissions][tmpfile] = verify_permissions(tmpfile, file_perms, options)
|
57
|
-
elsif
|
75
|
+
elsif files_identical?(target,tmpfile)
|
58
76
|
puts "\n - No change in '#{target}': Nothing to update here."
|
59
77
|
result[:verify_permissions][File.dirname(target)] = verify_permissions(File.dirname(target), dir_perms, options)
|
60
78
|
result[:verify_permissions][target] = verify_permissions(target, file_perms, options)
|
@@ -77,13 +95,12 @@ module DanarchyDeploy
|
|
77
95
|
chmod = nil
|
78
96
|
puts "\n > Verifying ownership and permissions for '#{target}'"
|
79
97
|
if perms
|
80
|
-
puts " |+ Setting file mode to: #{perms[:mode]}"
|
81
98
|
(owner, group, mode) = perms[:owner], perms[:group], perms[:mode]
|
82
99
|
else
|
83
100
|
if File.stat(target).mode & 07777 == '0777'.to_i(8)
|
84
101
|
puts " ! '#{target}' has 0777 permissions! Setting those to something more sane."
|
85
102
|
if File.ftype(target) == 'directory'
|
86
|
-
puts " |+ Setting
|
103
|
+
puts " |+ Setting directory mode to: 0775"
|
87
104
|
chmod = File.chmod(0775, target) ? true : false if !options[:pretend]
|
88
105
|
elsif File.ftype(target) == 'file'
|
89
106
|
puts " |+ Setting file mode to: 0644"
|
@@ -141,7 +158,7 @@ module DanarchyDeploy
|
|
141
158
|
[owner, uid, group, gid]
|
142
159
|
end
|
143
160
|
|
144
|
-
def self.
|
161
|
+
def self.files_identical?(target, tmpfile)
|
145
162
|
if File.exist?(target) && File.exist?(tmpfile)
|
146
163
|
FileUtils.identical?(target, tmpfile)
|
147
164
|
elsif File.exist?(target) && !File.exist?(tmpfile)
|