Module: Efi

Defined in:
lib/efi.rb,
lib/efi/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.device_info(disk) ⇒ Object



5
6
7
8
# File 'lib/efi.rb', line 5

def self.device_info(disk)
  print '.'
  Plist::parse_xml(`diskutil info -plist #{disk}`)
end

.efi_partitions(plist) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/efi.rb', line 10

def self.efi_partitions(plist)
  parts = []
  plist['AllDisksAndPartitions'].select do |d|
     d['Partitions']
  end.each do |d|
    d['Partitions'].each do |p|
      next if not p['Content'] == 'EFI'
      p['DiskInfo'] = device_info(d['DeviceIdentifier'])
      p['PartitionInfo'] = device_info(p['DeviceIdentifier'])
      parts << p
    end
  end
  parts
end

.runObject



25
26
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
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/efi.rb', line 25

def self.run
  puts
  puts "Available EFI partitions:"
  print "   loading"
  ep = efi_partitions Plist::parse_xml(`diskutil list -plist`)
  print "\r"
  ep.each_with_index do |p, i|
    if p['PartitionInfo']['MountPoint'] != ""
      puts "   #{i+1}) #{p['DeviceIdentifier']} (#{p['DiskInfo']['MediaName']}) mounted on #{p['PartitionInfo']['MountPoint']}"
    else
      puts "   #{i+1}) #{p['DeviceIdentifier']} (#{p['DiskInfo']['MediaName']})"
    end
  end
  puts "   Ctrl-C) exit"
  puts
  print "Select option: "
  
  n = nil
  begin
    n = gets.to_i
  rescue SignalException => e
    puts "\rSelect option: exit"
    exit
  rescue Exception => e
    puts e
    retry
  end
  
  partition_info = ep[n.abs - 1]['PartitionInfo']
  
  if partition_info['MountPoint'].empty?
    print "Mounting partition #{partition_info['DeviceIdentifier']}.."
    `diskutil mount #{partition_info['DeviceIdentifier']}`
    partition_info = device_info ep[n.abs - 1]['DeviceIdentifier']
    puts
  end
  
  if n < 0
    puts "Unmounting #{partition_info['DeviceIdentifier']}..."
    `diskutil unmount #{partition_info['DeviceIdentifier']}`
  else
    puts "Opening #{partition_info['MountPoint']} in Finder..."
    `open '#{partition_info['MountPoint']}'`
  end
  
  puts "Done"
end