Class: Autoyast

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

Overview

Copyright © 2013-2015 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

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
# File 'lib/autoyast.rb', line 21

def initialize(description)
  @name = "autoyast"
  @chroot_scripts = []
  @system_description = description
  @system_description.assert_scopes(
    "repositories",
    "packages"
  )
  if !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



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

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

#profileObject



66
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
# File 'lib/autoyast.rb', line 66

def profile
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.doc.create_internal_subset("profile", nil, nil)
    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_extracted_files("config_files")
      apply_extracted_files("changed_managed_files")
      apply_unmanaged_files
      xml.scripts do
        apply_url_extraction(xml)
        xml.send("chroot-scripts", "config:type" => "list") do
          xml.script do
            xml.source do
              xml.cdata @chroot_scripts.join("\n")
            end
          end
        end
      end
    end
  end

  builder.to_xml
end

#write(output_dir) ⇒ Object



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

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"))
  FileUtils.cp(
    File.join(Machinery::ROOT, "export_helpers/autoyast_export_readme.md"),
    File.join(output_dir, "README.md")
  )
  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