-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdot_files_setup.rb
47 lines (39 loc) · 1.06 KB
/
dot_files_setup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
dep('dot files setup') {
require 'digest/sha1'
def files
Dir.glob(dependency.load_path.parent / "dot_files/dot*.erb")
end
def local_to_remote_name(file)
file = File.basename(file.to_s)
file.to_s.gsub('dot_', '.').split(/\.erb$/).first
end
def dot_file_path
File.expand_path(ENV['HOME'])
end
def current_path
dot_file_path
end
def renderable(path)
Babushka::Renderable.new(path)
end
def rendered_config(local_path)
renderable(local_path).send(:render_erb, local_path, self)
end
met?{
files.all? do |file|
path = dot_file_path / local_to_remote_name(file)
File.exists?(path) &&
Digest::SHA1.hexdigest(rendered_config(file)) == renderable(path).send(:sha_of, path)
end
}
meet {
files.each do |file|
remote_path = dot_file_path / local_to_remote_name(file)
log "Rendering file #{remote_path}"
shell("cat > '#{dot_file_path / local_to_remote_name(file)}'",
:input => renderable(remote_path).send(:render_erb, file, self),
:sudo => true
)
end
}
}