This repository has been archived by the owner on Aug 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplates.rb
96 lines (81 loc) · 1.84 KB
/
templates.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
meta "mkdir" do
accepts_list_for :base
accepts_value_for :target
template {
def target_directories
base.map { |b| b / target }
end
met? {
target_directories.all? { |td| td.p.dir? }
}
meet {
target_directories.each do |td|
sudo "mkdir -p #{td}"
end
}
}
end
meta "dir" do
accepts_value_for :path, :basename
template {
met? { path.p.dir? }
meet { log_shell "Creating #{path}", "mkdir -p #{path}" }
}
end
meta "symlink" do
accepts_value_for :source
accepts_value_for :target
template {
met? { target.p.readlink == source }
meet { sudo "ln -s '#{source}' '#{target}'" }
}
end
meta "render" do
accepts_value_for :target
accepts_value_for :erb
template {
def erb_path
dependency.load_path.parent / erb
end
met? { Babushka::Renderable.new(target).from?(erb_path) }
meet {
render_erb erb_path, :to => target, :sudo => true
}
}
end
meta "file" do
accepts_value_for :source
accepts_value_for :name, :basename
accepts_value_for :target
template {
met? { target.p.exist? }
meet {
Babushka::Resource.extract(source) { |archive|
Dir.glob("**/*#{name}").select {|file|
log_shell "Copying #{file} to #{target}", "cp -R #{file} #{target}"
}
}
}
}
end
meta :repo do
accepts_value_for :source
accepts_value_for :path
template {
def repo
@repo ||= Babushka::GitRepo.new(path).tap do |r|
r.repo_shell('git fetch') if r.exists?
end
end
meet do
if repo.exists?
log_block "Updating to #{repo.current_remote_branch} (#{repo.resolve(repo.current_remote_branch)})" do
repo.reset_hard!(repo.current_remote_branch)
end
else
git source, :to => path
end
end
met? { repo.exists? && !repo.behind? }
}
end