Class: XcodeInstall::Simulator
- Inherits:
-
Object
- Object
- XcodeInstall::Simulator
- Defined in:
- lib/xcode/install.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#xcode ⇒ Object
readonly
Returns the value of attribute xcode.
Instance Method Summary collapse
- #apply_variables(template) ⇒ Object
- #dmg_path ⇒ Object
- #download(progress, progress_block = nil, retry_download_count = 3) ⇒ Object
-
#initialize(downloadable) ⇒ Simulator
constructor
A new instance of Simulator.
- #install(progress, should_install) ⇒ Object
- #installed? ⇒ Boolean
- #installed_string ⇒ Object
- #pkg_path ⇒ Object
- #prepare_package ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(downloadable) ⇒ Simulator
Returns a new instance of Simulator.
518 519 520 521 522 523 524 |
# File 'lib/xcode/install.rb', line 518 def initialize(downloadable) @version = Gem::Version.new(downloadable['version']) @install_prefix = apply_variables(downloadable['userInfo']['InstallPrefix']) @name = apply_variables(downloadable['name']) @identifier = apply_variables(downloadable['identifier']) @source = apply_variables(downloadable['source']) end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
514 515 516 |
# File 'lib/xcode/install.rb', line 514 def identifier @identifier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
513 514 515 |
# File 'lib/xcode/install.rb', line 513 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
515 516 517 |
# File 'lib/xcode/install.rb', line 515 def source @source end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
512 513 514 |
# File 'lib/xcode/install.rb', line 512 def version @version end |
#xcode ⇒ Object (readonly)
Returns the value of attribute xcode.
516 517 518 |
# File 'lib/xcode/install.rb', line 516 def xcode @xcode end |
Instance Method Details
#apply_variables(template) ⇒ Object
606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/xcode/install.rb', line 606 def apply_variables(template) variable_map = { '$(DOWNLOADABLE_VERSION_MAJOR)' => version.to_s.split('.')[0], '$(DOWNLOADABLE_VERSION_MINOR)' => version.to_s.split('.')[1], '$(DOWNLOADABLE_IDENTIFIER)' => identifier, '$(DOWNLOADABLE_VERSION)' => version.to_s }.freeze variable_map.each do |key, value| next unless template.include?(key) template.sub!(key, value) end template end |
#dmg_path ⇒ Object
598 599 600 |
# File 'lib/xcode/install.rb', line 598 def dmg_path CACHE_DIR + Pathname.new(source).basename end |
#download(progress, progress_block = nil, retry_download_count = 3) ⇒ Object
547 548 549 550 551 552 553 554 555 556 |
# File 'lib/xcode/install.rb', line 547 def download(progress, progress_block = nil, retry_download_count = 3) result = Curl.new.fetch( url: source, directory: CACHE_DIR, progress: progress, progress_block: progress_block, retry_download_count: retry_download_count ) result ? dmg_path : nil end |
#install(progress, should_install) ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/xcode/install.rb', line 558 def install(progress, should_install) dmg_path = download(progress) fail Informative, "Failed to download #{@name}." if dmg_path.nil? return unless should_install prepare_package unless pkg_path.exist? puts "Please authenticate to install #{name}..." `sudo installer -pkg #{pkg_path} -target /` fail Informative, "Could not install #{name}, please try again" unless installed? source_receipts_dir = '/private/var/db/receipts' target_receipts_dir = "#{@install_prefix}/System/Library/Receipts" FileUtils.mkdir_p(target_receipts_dir) FileUtils.cp("#{source_receipts_dir}/#{@identifier}.bom", target_receipts_dir) FileUtils.cp("#{source_receipts_dir}/#{@identifier}.plist", target_receipts_dir) puts "Successfully installed #{name}" end |
#installed? ⇒ Boolean
526 527 528 529 |
# File 'lib/xcode/install.rb', line 526 def installed? # FIXME: use downloadables' `InstalledIfAllReceiptsArePresentOrNewer` key File.directory?(@install_prefix) end |
#installed_string ⇒ Object
531 532 533 |
# File 'lib/xcode/install.rb', line 531 def installed_string installed? ? 'installed' : 'not installed' end |
#pkg_path ⇒ Object
602 603 604 |
# File 'lib/xcode/install.rb', line 602 def pkg_path CACHE_DIR + "#{identifier}.pkg" end |
#prepare_package ⇒ Object
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/xcode/install.rb', line 577 def prepare_package puts 'Mounting DMG' mount_location = Installer.new.mount(dmg_path) puts 'Expanding pkg' = CACHE_DIR + identifier FileUtils.rm_rf() `pkgutil --expand #{mount_location}/*.pkg #{}` puts "Expanded pkg into #{}" puts 'Unmounting DMG' `umount #{mount_location}` puts 'Setting package installation location' package_info_path = + 'PackageInfo' package_info_contents = File.read(package_info_path) File.open(package_info_path, 'w') do |f| f << package_info_contents.sub('pkg-info', %(pkg-info install-location="#{@install_prefix}")) end puts 'Rebuilding package' `pkgutil --flatten #{} #{pkg_path}` FileUtils.rm_rf() end |
#to_s ⇒ Object
535 536 537 |
# File 'lib/xcode/install.rb', line 535 def to_s "#{name} (#{installed_string})" end |