lib/kuzushi.rb in kuzushi-0.0.14 vs lib/kuzushi.rb in kuzushi-0.0.15
- old
+ new
@@ -90,11 +90,11 @@
def process_packages
@packages = get_array("packages")
task "install packages" do
shell "apt-get update && apt-get upgrade -y"
- shell "apt-get install -y #{@packages.join(" ")}" if @packages.empty?
+ shell "apt-get install -y #{@packages.join(" ")}" unless @packages.empty?
end
end
def process_local_packages(p)
package(p) do |file|
@@ -148,18 +148,21 @@
o << "noatime" if o.empty?
o.join(",")
end
def handle_tmpfs(m)
- task "mount #{m.mount}" do
- shell "mkdir -p #{m.mount} && mount -o #{mount_options(m)} -t tmpfs tmpfs #{m.mount}" unless mounted?(m.mount)
- end
+ m.format ||= "tmpfs"
+ m.device ||= "tmpfs"
end
def handle_mount(m)
task "mount #{m.mount}" do
- shell "mkdir -p #{m.mount} && mount -o #{mount_options(m)} #{m.device} #{m.mount}" unless mounted?(m.mount)
+ unless mounted?(m.mount)
+ shell "mv #{m.mount} #{m.mout}.old" if File.exists?(m.mount)
+ shell "mkdir -p #{m.mount} && mount -o #{mount_options(m)} -t #{m.format} #{m.device} #{m.mount}"
+ shell "chown -R #{m.user}:#{m.group} #{m.mount}" if m.user or m.group
+ end
end
end
def system_arch
system.kernel["machine"]
@@ -174,15 +177,27 @@
def package_arch
`dpkg --print-architecture`.chomp
end
def process_files(f)
- fetch("/templates/#{f.template}") do |file|
- task "setting up #{f.file}" do
+ if f.template
+ write_file("/templates/#{f.template}", f.file) do |file|
@system = system
t = ERB.new File.read(file), 0, '<>'
- File.open(f.file,"w") { |f| f.write(t.result(binding)) }
+ t.result(binding))
end
+ else
+ src = f.source || File.basename(f.file)
+ write_file("/files/#{src}", f.file) do |file|
+ File.read(file)
+ end
+ end
+ end
+
+ def write_file(src, dest, &blk)
+ fetch(src) do |file|
+ FileUtils.mkdir_p(File.dirname(dest))
+ File.open(f.file,"w") { |f| f.write(blk.call) }
end
end
def process_users(user)
(user.authorized_keys || []).each do |key|