Class: Machinery::Autoyast

Inherits:
Exporter show all
Defined in:
lib/autoyast.rb

Overview

Copyright © 2013-2016 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.

To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com

Instance Attribute Summary collapse

Attributes inherited from Exporter

#system_description

Instance Method Summary collapse

Methods inherited from Exporter

#quote

Constructor Details

#initialize(description) ⇒ Autoyast

Returns a new instance of Autoyast.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/autoyast.rb', line 21

def initialize(description)
  @name = "autoyast"
  @chroot_scripts = []
  @system_description = description
  @system_description.assert_scopes(
    "os",
    "packages"
  )
  check_exported_os
  unless description.users
    Machinery::Ui.puts(
      "\nWarning: Exporting a description without the scope 'users' as AutoYaST" \
      " profile will result in a root account without a password which prevents" \
      " logging in.\n" \
      "So either inspect or add the scope 'users' before the export or" \
      " add a section for the root user to the AutoYaST profile."
    )
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/autoyast.rb', line 19

def name
  @name
end

Instance Method Details

#export_nameObject



63
64
65
# File 'lib/autoyast.rb', line 63

def export_name
  "#{@system_description.name}-autoyast"
end

#outgoing_ipObject



105
106
107
108
# File 'lib/autoyast.rb', line 105

def outgoing_ip
  output = Cheetah.run("ip", "route", "get", "8.8.8.8", stdout: :capture)
  output[/ src ([\d\.:]+)\s*$/, 1] || "<ip>"
end

#profileObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/autoyast.rb', line 67

def profile
  xml = Builder::XmlMarkup.new(indent: 2)
  xml.instruct! :xml
  xml.declare! :DOCTYPE, :profile
  xml.profile(
    "xmlns" => "http://www.suse.com/1.0/yast2ns",
    "xmlns:config" => "http://www.suse.com/1.0/configns"
  ) do
    apply_non_interactive_mode(xml)
    apply_basic_network(xml)
    apply_repositories(xml)
    xml.software do
      apply_software_settings(xml)
      apply_packages(xml)
      apply_patterns(xml)
    end
    apply_users(xml)
    apply_groups(xml)
    apply_services(xml)

    apply_changed_files("changed_config_files")
    apply_changed_files("changed_managed_files")
    apply_unmanaged_files
    xml.scripts do
      apply_url_extraction(xml)
      xml.tag!("chroot-scripts", "config:type" => "list") do
        xml.script do
          xml.source do
            xml.cdata! @chroot_scripts.join("\n")
          end
        end
      end
    end
  end

  xml.target!
end

#write(output_dir) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/autoyast.rb', line 41

def write(output_dir)
  FileUtils.cp(
    File.join(Machinery::ROOT, "export_helpers/unmanaged_files_#{@name}_excludes"),
    output_dir
  )
  FileUtils.chmod(0600, File.join(output_dir, "unmanaged_files_#{@name}_excludes"))
  readme = File.read(File.join(Machinery::ROOT, "export_helpers/autoyast_export_readme.md"))
  readme.gsub!("<ip>", outgoing_ip)
  readme.gsub!("<path>", output_dir)
  File.write(File.join(output_dir, "README.md"), readme)
  Dir["#{@system_description.description_path}/*"].each do |content|
    FileUtils.cp_r(content, output_dir, preserve: true)
  end
  File.write(File.join(output_dir, "autoinst.xml"), profile)
  FileUtils.chmod(0600, File.join(output_dir, "autoinst.xml"))
  Machinery::Ui.puts(
    "Note: The permssions of the AutoYaST directory are restricted to be" \
      " only accessible by the current user. Further instructions are" \
      " provided by the README.md in the exported directory."
  )
end