class Invoker::Power::PfMigrate

for migrating existins users to pf

Public Instance Methods

ask_user_for_migration() click to toggle source
# File lib/invoker/power/pf_migrate.rb, line 25
def ask_user_for_migration
  if not_already_root?
    Invoker::Logger.puts "Invoker has detected you are running OSX 10.10 "\
      " but your invoker configuration does not support it."
    Invoker::Logger.puts "Invoker can update its configuration automaticaly"\
      " but it will require a system reboot.".color(:red)
    Invoker::CLI::Question.agree("Update Invoker configuration (y/n) :")
  else
    true
  end
end
check_firewall_file?() click to toggle source
# File lib/invoker/power/pf_migrate.rb, line 57
def check_firewall_file?
  return false unless File.exist?(Invoker::Power::OsxSetup::FIREWALL_PLIST_FILE)
  firewall_contents = File.read(Invoker::Power::OsxSetup::FIREWALL_PLIST_FILE)
  !!firewall_contents.match(/ipfw/)
end
drop_to_normal_user() click to toggle source
# File lib/invoker/power/pf_migrate.rb, line 48
def drop_to_normal_user
  EventMachine.set_effective_user(ENV["SUDO_USER"])
end
firewall_config_requires_migration?() click to toggle source
# File lib/invoker/power/pf_migrate.rb, line 5
def firewall_config_requires_migration?
  return false if !Invoker.darwin?
  # lets not migrate on osx < 10.10
  return false if osx_version < Invoker::Version.new("14.0.0")
  # also verify if firewall config is old
  check_firewall_file?
end
migrate() click to toggle source
# File lib/invoker/power/pf_migrate.rb, line 13
def migrate
  if firewall_config_requires_migration? && ask_user_for_migration
    sudome
    osx_setup = Invoker::Power::OsxSetup.new(Invoker.config.tld)
    osx_setup.install_firewall(Invoker.config.http_port, Invoker.config.https_port)
    drop_to_normal_user
    Invoker::Logger.puts "Invoker has updated its configuration for yosemite."\
      " Please restart OSX to complete the configuration process.".color(:red)
    exit(-1)
  end
end
not_already_root?() click to toggle source
# File lib/invoker/power/pf_migrate.rb, line 44
def not_already_root?
  ENV["USER"] != "root"
end
osx_version() click to toggle source
# File lib/invoker/power/pf_migrate.rb, line 52
def osx_version
  osx_kernel_version = `uname -r`.strip
  Invoker::Version.new(osx_kernel_version)
end
sudome() click to toggle source

jimeh.me/blog/2010/02/22/built-in-sudo-for-ruby-command-line-tools/

# File lib/invoker/power/pf_migrate.rb, line 38
def sudome
  if not_already_root?
    exec("sudo #{$0} #{ARGV.join(' ')}")
  end
end