Module: Promotion::Generator::Profile
- Defined in:
- lib/promotion/generator/profile.rb
Constant Summary collapse
- PROFILE =
"/etc/profile"
Class Method Summary collapse
-
.check(specs) ⇒ Object
Writes the system profile.
Class Method Details
.check(specs) ⇒ Object
Writes the system profile
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 |
# 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 |