Class: IESD::DMG::InstallESD

Inherits:
HDIUtil::DMG show all
Defined in:
lib/iesd/InstallESD/InstallESD.dmg.rb

Overview

InstallESD.dmg

The installer DMG for OS X Lion and later. It contains a BaseSystem.dmg, which is used to install the OS X Recovery.

Defined Under Namespace

Classes: BaseSystem

Constant Summary collapse

PACKAGES =

The relative path to the Packages.

File.join %w[ Packages ]

Instance Attribute Summary

Attributes inherited from HDIUtil::DMG

#url

Instance Method Summary collapse

Methods inherited from HDIUtil::DMG

#edit, #initialize, #show, #update, #valid?

Constructor Details

This class inherits a constructor from HDIUtil::DMG

Instance Method Details

#export(options) ⇒ Object

Export to a new DMG.

options - The Dictionary of the export options



18
19
20
21
22
23
24
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
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
# File 'lib/iesd/InstallESD/InstallESD.dmg.rb', line 18

def export options
  case options[:type]
  when :BaseSystem
    options = {
      :hdiutil => {
        :resize => {
          :grow => 0,
        }
      }
    }.merge(options)
    options[:hdiutil][:resize][:grow] += ( `/usr/bin/env hdiutil resize -limits #{@url.shellescape}`.chomp.split.map { |s| s.to_i } ).first

    show { |installesd|
      IESD::DMG::BaseSystem.new(File.join(installesd, "BaseSystem.dmg")).export(options) { |basesystem|
        installesd_packages = File.join installesd, PACKAGES
        basesystem_packages = File.join basesystem, IESD::DMG::BaseSystem::PACKAGES
        oh1 "Copying #{installesd_packages}"
        system("/usr/bin/env", "rm", basesystem_packages)
        system("/usr/bin/env", "ditto", installesd_packages, basesystem_packages)
        puts "Copied: #{basesystem_packages}"

        installesd_mach_kernel = File.join installesd, "mach_kernel"
        basesystem_mach_kernel = File.join basesystem, "mach_kernel"
        if File.exist? installesd_mach_kernel
          oh1 "Copying #{installesd_mach_kernel}"
          system("/usr/bin/env", "ditto", installesd_mach_kernel, basesystem_mach_kernel)
          system("/usr/bin/env", "chflags", "hidden", basesystem_mach_kernel)
          puts "Copied: #{basesystem_mach_kernel}"
        end
      }
    }
  when :InstallESD, nil
    Dir.mktmpdir { |tmp|
      HDIUtil.write(@url, (tmpfile = File.join(tmp, File.basename(@url))), options[:hdiutil]) { |installesd|
        options[:extensions][:up_to_date] = (options[:extensions][:uninstall].empty? and options[:extensions][:install].empty?)
        options[:mach_kernel] = File.exist? File.join(installesd, "mach_kernel") if options[:mach_kernel].nil?

        yield installesd if block_given?

        pre_update_extension installesd, options

        basesystem_options = options.clone
        basesystem_options[:input] = basesystem_options[:output] = File.join(installesd, "BaseSystem.dmg")
        basesystem_flags = `/usr/bin/env ls -lO #{basesystem_options[:input].shellescape}`.split[4]
        IESD::DMG::InstallESD::BaseSystem.new(File.join(basesystem_options[:input])).export(basesystem_options) { |basesystem|
          installesd_mach_kernel = File.join installesd, "mach_kernel"
          basesystem_mach_kernel = File.join basesystem, "mach_kernel"
          if File.exist? installesd_mach_kernel
            oh1 "Copying #{installesd_mach_kernel}"
            system("/usr/bin/env", "ditto", installesd_mach_kernel, basesystem_mach_kernel)
            system("/usr/bin/env", "chflags", "hidden", basesystem_mach_kernel)
            puts "Copied: #{basesystem_mach_kernel}"
          end
        }
        system("/usr/bin/env", "chflags", basesystem_flags, basesystem_options[:output]) unless basesystem_flags == "-"

        if File.exist? (kextcache = File.join(installesd, "kernelcache"))
          IESD::DMG::InstallESD::BaseSystem.new(File.join(basesystem_options[:output])).show { |basesystem|
            oh1 "Updating Kextcache"
            system("/usr/bin/env", "ditto", File.join(basesystem, *KextCache::KERNELCACHE), kextcache)
            system("/usr/bin/env", "chflags", "hidden", kextcache)
            puts "Updated: #{kextcache}"
          }
        end

        post_update_extension installesd, options

        if options[:interactive]
          oh1 "Starting Interactive Shell"
          puts "Environment: InstallESD"
          HDIUtil.shell installesd
        end
      }
      system("/usr/bin/env", "mv", tmpfile, options[:output])
    }
  else
    raise "invalid output type"
  end
end