module Promotion::Generator::Profile

Constants

PROFILE

Public Class Methods

check(specs) click to toggle source

Writes the system profile

# File lib/promotion/generator/profile.rb, line 8
def self.check(specs)
  system("touch #{PROFILE}") unless File.exists?(PROFILE)
  contents = IO.readlines(PROFILE).collect!{ |s| s.strip() }
  proposals = []
  specs.each { |spec|
    spec.elements.each("/Specification/Environment") { |env|
      env.elements.each("Variable") { |var|
        t = var.cdatas.length > 0 ? var.cdatas[0].to_s() : var.text()
        needed = "export #{var.attributes["Name"]}=\"#{t}\""
        unless contents.include?(needed.strip())
          proposals << needed
        end
      }
      env.elements.each("Alias") { |ali|
        contents << "# #{ali.attributes["Comment"]}\n" if ali.attributes["Comment"]
        t = ali.cdatas.length > 0 ? ali.cdatas[0].to_s() : ali.text()
        needed = "alias #{ali.attributes["Name"]}='#{t}'"
        unless contents.include?(needed.strip())
          proposals << needed
        end
      }
    }
  }
  puts("\nSuggested changes to /etc/profile:", proposals.join("\n"), "\n") if proposals.size > 0
end