Sha256: 4cf805c7b9a7db65f7c9abb68213f7bfc208953e309cd069397bc331d3176b6d

Contents?: true

Size: 971 Bytes

Versions: 4

Compression:

Stored size: 971 Bytes

Contents

class UpgradeMacOS
  include RunCommand

  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} (Yes / No)"
  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-3.1.0 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb
renuo-cli-3.0.0 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb
renuo-cli-2.0.0 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb
renuo-cli-1.8.0 lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb