Class: Invoker::Power::PfMigrate

Inherits:
Object
  • Object
show all
Defined in:
lib/invoker/power/pf_migrate.rb

Overview

for migrating existins users to pf

Instance Method Summary collapse

Instance Method Details

#ask_user_for_migrationObject



25
26
27
28
29
30
31
32
33
34
35
# 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.".colorize(:red)
    Invoker::CLI::Question.agree("Update Invoker configuration (y/n) :")
  else
    true
  end
end

#check_firewall_file?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
# 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_userObject



48
49
50
# 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?Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# 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

#migrateObject



13
14
15
16
17
18
19
20
21
22
23
# 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.".colorize(:red)
    exit(-1)
  end
end

#not_already_root?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/invoker/power/pf_migrate.rb', line 44

def not_already_root?
  ENV["USER"] != "root"
end

#osx_versionObject



52
53
54
55
# 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

#sudomeObject



38
39
40
41
42
# File 'lib/invoker/power/pf_migrate.rb', line 38

def sudome
  if not_already_root?
    exec("sudo #{$0} #{ARGV.join(' ')}")
  end
end