module Promotion::Generator::Rcconf
Public Class Methods
check(specs)
click to toggle source
Writes the system file /etc/rc.conf.local
# File lib/promotion/generator/rcconf.rb, line 6 def self.check(specs) contents = IO.readlines("/etc/rc.conf.local").collect!{ |s| s.strip() } proposals = [] # Extract package scripts and sort them by increasing priority daemonSpecs = specs.reject {|s| s.elements["/Specification/Daemon"].nil? } daemonSpecs.sort!() { |a, b| ap = a.elements["/Specification/Daemon"].attributes["Priority"].to_i || 10 bp = b.elements["/Specification/Daemon"].attributes["Priority"].to_i || 10 ap <=> bp } pkgScripts = [] daemonSpecs.each { |spec| spec.each_element("Daemon") { |d| # allow for multiple daemons in a spec # Name defaults to the name of the spec, but may be overridden by the optional Name attribute name = d.attributes["Name"] || spec.attributes["Name"] flags = d.attributes["Flags"] needed = "#{name}_flags=\"#{flags}\"" proposals << needed unless contents.include?(needed.strip()) pkgScripts << name } } if proposals.size > 0 or contents.join("\n") !~ /pkg_scripts.*#{pkgScripts.join(" ")}/ puts("\nSuggested changes to /etc/rc.conf.local:", proposals.join("\n")) puts("\npkg_scripts=\"#{pkgScripts.join(" ")}\" ") puts("") end end