Class: Yast::InstPreInstallClient

Inherits:
Client
  • Object
show all
Includes:
Logger
Defined in:
src/lib/installation/clients/inst_pre_install.rb

Instance Method Summary collapse

Instance Method Details

#can_read_users?Boolean (protected)

Checks whether it's possible to read the existing users databases

Returns:

  • (Boolean)

119
120
121
122
123
124
# File 'src/lib/installation/clients/inst_pre_install.rb', line 119

def can_read_users?
  @can_read_users ||= begin
    require_users_database
    defined? ::Users::UsersDatabase
  end
end

#each_mounted_device(&block) ⇒ Object (protected)


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'src/lib/installation/clients/inst_pre_install.rb', line 153

def each_mounted_device(&block)
  mnt_tmpdir = "#{Directory.tmpdir}/tmp_mnt_for_check"
  mnt_tmpdir = SystemFilesCopy.CreateDirectoryIfMissing(mnt_tmpdir)

  # CreateDirectory failed
  if mnt_tmpdir.nil?
    log.error "Error creating temporary directory"
    return
  end

  @useful_devices.each do |device|
    log.info "Mounting #{device} to #{mnt_tmpdir}"
    already_mounted = Builtins.sformat(
      "/usr/bin/grep '[\\t ]%1[\\t ]' /proc/mounts",
      String.Quote(mnt_tmpdir)
    )
    am = SCR.Execute(path(".target.bash_output"), already_mounted)
    if am["exit"] == 0 && !am["stdout"].to_s.empty?
      log.warning "#{mnt_tmpdir} is already mounted, trying to umount..."
      log.error("Cannot umount #{mnt_tmpdir}") unless SCR.Execute(path(".target.umount"),
        mnt_tmpdir)
    end
    # mounting read-only
    if !SCR.Execute(path(".target.mount"), [device, mnt_tmpdir], "-o ro,noatime")
      log.error "Mounting falied!"
      next
    end

    block.call(device, mnt_tmpdir)

    # bnc #427879
    exec = SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat("/usr/bin/fuser -v '%1' 2>&1", String.Quote(mnt_tmpdir))
    )
    log.error("Processes in #{mnt_tmpdir}: #{exec}") unless exec["stdout"].to_s.empty?
    # umounting
    log.info "Umounting #{device}"
    log.error("Umount failed!") unless SCR.Execute(path(".target.umount"), mnt_tmpdir)
  end
end

#InitializeObject


62
63
64
65
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
103
104
105
106
107
108
109
110
111
112
113
114
# File 'src/lib/installation/clients/inst_pre_install.rb', line 62

def Initialize
  Builtins.y2milestone("Evaluating all current partitions")

  # limit the number of the searched disks to 8 of each kind in order to avoid neverending
  # mounting of all partitions (fate#305873, bnc#468922)
  # FIXME: copy-pasted from partitioner, just different number of disks and added /dev/dasd
  restrict_disk_names = lambda do |disks|
    helper = lambda do |s|
      count = 0
      disks = disks.select do |dist|
        next true unless dist.start_with?(s)

        (count += 1) <= 8
      end

      nil
    end

    helper.call("/dev/sd")
    helper.call("/dev/hd")
    helper.call("/dev/cciss/")
    helper.call("/dev/dasd")

    Builtins.y2milestone("restrict_disk_names: ret %1", disks)
    deep_copy(disks)
  end

  probed = Y2Storage::StorageManager.instance.probed
  device_names = probed.disk_devices.map(&:name)
  device_names = restrict_disk_names.call(device_names)
  Builtins.foreach(device_names) do |device_name|
    device = Y2Storage::BlkDevice.find_by_name(probed, device_name)
    filesystems = device.descendants.select { |i| i.is?(:blk_filesystem) }
    filesystems.each do |filesystem|
      device = filesystem.blk_devices.first
      if !filesystem.type.root_ok?
        log.info(
          "Skipping device #{device.name}, "\
          "#{filesystem.type} is not a root filesystem"
        )
        next
      end
      @useful_devices << device.name
    end
  end
  # Duplicates can happen, e.g. if there are PVs for the same LVM VG in
  # several disks
  @useful_devices.uniq!

  Builtins.y2milestone("Possible devices: %1", @useful_devices)

  nil
end

#mainObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'src/lib/installation/clients/inst_pre_install.rb', line 27

def main
  Yast.import "Directory"
  Yast.import "SystemFilesCopy"
  Yast.import "ProductControl"
  Yast.import "String"

  # --> Variables

  # all devices that can be used as a source of data
  @useful_devices = []

  # *******************************************************************************
  # --> main()

  Initialize()

  each_mounted_device do |device, mount_point|
    read_users(device, mount_point) if can_read_users?
    read_ssh_info(device, mount_point)
  end

  # The ssh_import proposal doesn't make sense if there is no
  # configuration to import from.
  if ::Installation::SshImporter.instance.configurations.empty?
    ProductControl.DisableSubProposal("inst_initial",
      "ssh_import")
  end

  # free the memory
  @useful_devices = nil

  # at least some return
  :auto
end

#read_ssh_info(device, mount_point) ⇒ Object (protected)

Stores the SSH configuration of a given partition in the SSH importer

Parameters:

  • device (String)

    device name of the filesystem

  • mount_point (String)

    path where the filesystem is mounted

See Also:


148
149
150
151
# File 'src/lib/installation/clients/inst_pre_install.rb', line 148

def read_ssh_info(device, mount_point)
  log.info "Reading SSH information from #{device}"
  ::Installation::SshImporter.instance.add_config(mount_point, device)
end

#read_users(device, mount_point) ⇒ Object (protected)

Stores the users database (/etc/passwd and friends) of a given filesystem in UsersDatabase.all, so it can be used during the users import step

Parameters:

  • device (String)

    device name of the filesystem

  • mount_point (String)

    path where the filesystem is mounted


138
139
140
141
# File 'src/lib/installation/clients/inst_pre_install.rb', line 138

def read_users(device, mount_point)
  log.info "Reading users information from #{device}"
  ::Users::UsersDatabase.import(mount_point)
end

#require_users_databaseObject (protected)

Requires users_database if possible, not failing otherwise


127
128
129
130
131
# File 'src/lib/installation/clients/inst_pre_install.rb', line 127

def require_users_database
  require "users/users_database"
rescue LoadError
  log.error "UsersDatabase not found. YaST2-users is missing, old or broken."
end