Sha256: 03b3ba06d921819c25b6beccac04b119b2cf4552ab8efaf985ad2046baa9b4da

Contents?: true

Size: 994 Bytes

Versions: 4

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

class UpgradeMacOS
  include CommandHelper

  def run
    find_software_upgrades
    return unless upgrade_available?

    return if reboot_required_and_not_agreed_to?

    execute_upgrade
  end

  def reboot_required?
    @output.downcase.include? 'restart'
  end

  private

  def find_software_upgrades
    say "\nUpdating  macOS.\nFinding available software (this may take a while)".yellow

    @output = `softwareupdate --list 2>&1`
    say @output
  end

  def upgrade_available?
    @output.include? 'Software Update found'
  end

  def reboot_required_and_not_agreed_to?
    reboot_required? && !agree_for_reboot?
  end

  def agree_for_reboot?
    agree "\nYour Mac needs to be rebooted, Still continue?".red.to_s
  end

  def execute_upgrade
    run_command 'softwareupdate --install --all'
    reboot if reboot_required?
  end

  def reboot
    say 'Rebooting Now'.white.on_red
    say `osascript -e 'tell app "System Events" to restart'`
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
renuo-cli-4.5.0 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb
renuo-cli-4.3.0 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb
renuo-cli-4.2.1 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb
renuo-cli-4.2.0 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb