class Explorer::Setup

Constants

FIREWALL_PLIST_DST
RESOLVER_DIR_DST
RESOLVER_FILE_DST

Public Instance Methods

install() click to toggle source
# File lib/explorer/setup.rb, line 9
def install
  firewall_plist_src = File.join(Explorer::DATADIR, 'setup', 'firewall.plist')
  resolver_file_src = File.join(Explorer::DATADIR, 'setup', 'dev')

  mkdir(RESOLVER_DIR_DST)
  FileUtils.cp resolver_file_src, RESOLVER_FILE_DST
  puts Rainbow("Installed `#{RESOLVER_FILE_DST}`").color(:green).bright

  FileUtils.cp firewall_plist_src, FIREWALL_PLIST_DST
  puts Rainbow("Installed `#{FIREWALL_PLIST_DST}`").color(:green).bright

  unload_firewall
  load_firewall
  puts Rainbow('Loaded firwall rules').color(:green).bright

rescue Errno::EACCES => e
  puts Rainbow("Something went wrong installing (#{e.message})").color(:red).bright
end
installed?() click to toggle source
# File lib/explorer/setup.rb, line 42
def installed?
  return false unless File.exists? FIREWALL_PLIST_DST
  return false unless File.exists? RESOLVER_FILE_DST
  true
end
suitable?() click to toggle source
# File lib/explorer/setup.rb, line 48
def suitable?
  return false unless Etc.uname[:sysname] == 'Darwin'
  true
end
uninstall() click to toggle source
# File lib/explorer/setup.rb, line 28
def uninstall
  FileUtils.rm RESOLVER_FILE_DST
  puts Rainbow("Removed `#{RESOLVER_FILE_DST}`").color(:green).bright

  unload_firewall
  puts Rainbow("Unloaded firewall rules").color(:green).bright

  FileUtils.rm FIREWALL_PLIST_DST
  puts Rainbow("Removed `#{FIREWALL_PLIST_DST}`").color(:green).bright

rescue Errno::EACCES => e
  puts Rainbow("Something went wrong uninstalling (#{e.message})").color(:red).bright
end

Private Instance Methods

load_firewall() click to toggle source
# File lib/explorer/setup.rb, line 60
def load_firewall
  system("launchctl load -Fw #{FIREWALL_PLIST_DST} 2>/dev/null")
end
mkdir(dir) click to toggle source
# File lib/explorer/setup.rb, line 64
def mkdir(dir)
  FileUtils.mkdir(dir) unless Dir.exists? dir
end
unload_firewall() click to toggle source
# File lib/explorer/setup.rb, line 55
def unload_firewall
  system("pfctl -a com.apple/250.ExplorerFirewall -F nat 2>/dev/null")
  system("launchctl unload -w #{FIREWALL_PLIST_DST} 2>/dev/null")
end