foreman-export-initscript/lib/foreman/export/initscript.rb

21 lines
738 B
Ruby
Raw Normal View History

2012-04-18 04:03:28 +00:00
require "erb"
require "foreman/export"
class Foreman::Export::Initscript < Foreman::Export::Base
def export
2012-09-11 18:15:08 +00:00
error("Must specify a location") unless location
FileUtils.mkdir_p(location) rescue error("Could not create: #{location}")
2012-04-18 04:03:28 +00:00
2012-09-11 18:15:08 +00:00
name = "initscript/master.erb"
name_without_first = name.split("/")[1..-1].join("/")
matchers = []
matchers << File.join(options[:template], name_without_first) if options[:template]
matchers << File.expand_path("~/.foreman/templates/#{name}")
matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
path = File.read(matchers.detect { |m| File.exists?(m) })
compiled = ERB.new(path).result(binding)
write_file "#{app}", compiled
2012-04-18 04:03:28 +00:00
end
end