Module: DevDNSd::OSX

Included in:
Application
Defined in:
lib/devdnsd/osx.rb

Overview

OSX management methods.

Instance Method Summary collapse

Instance Method Details

#action_add(options) ⇒ Boolean

Adds aliases to an interface.

Parameters:

  • options (Hash)

    The options provided by the user.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



64
65
66
# File 'lib/devdnsd/osx.rb', line 64

def action_add(options)
  manage_aliases(:add, i18n.add_empty, options)
end

#action_installBoolean

Installs the application into the autolaunch.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



79
80
81
# File 'lib/devdnsd/osx.rb', line 79

def action_install
  manage_installation(launch_agent_path, resolver_path, :create_resolver, :create_agent, :load_agent)
end

#action_remove(options) ⇒ Boolean

Removes aliases from an interface.

Parameters:

  • options (Hash)

    The options provided by the user.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



72
73
74
# File 'lib/devdnsd/osx.rb', line 72

def action_remove(options)
  manage_aliases(:remove, i18n.remove_empty, options)
end

#action_uninstallBoolean

Uninstalls the application from the autolaunch.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



86
87
88
# File 'lib/devdnsd/osx.rb', line 86

def action_uninstall
  manage_installation(launch_agent_path, resolver_path, :delete_resolver, :unload_agent, :delete_agent)
end

#dns_updateBoolean

Updates DNS cache.

Returns:

  • (Boolean)

    true if command succeeded, false otherwise.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/devdnsd/osx.rb', line 37

def dns_update
  @logger.info(i18n.dns_update)

  script = Tempfile.new("devdnsd-dns-cache-script")
  script.write("dscacheutil -flushcache 2>&1 > /dev/null\n")
  script.write("killall -9 mDNSResponder 2>&1 > /dev/null\n")
  script.write("killall -9 mDNSResponderHelper 2>&1 > /dev/null\n")
  script.close

  Kernel.system("/usr/bin/osascript -e 'do shell script \"sh #{script.path}\" with administrator privileges' 2>&1 > /dev/null")
  script.unlink
end

#execute_command(command) ⇒ Boolean

Executes a shell command.

Parameters:

  • command (String)

    The command to execute.

Returns:

  • (Boolean)

    true if command succeeded, false otherwise.



30
31
32
# File 'lib/devdnsd/osx.rb', line 30

def execute_command(command)
  system("#{command} 2>&1 > /dev/null")
end

#launch_agent_path(name = "it.cowtech.devdnsd") ⇒ String

Gets the path for the launch agent file.

Parameters:

  • name (String) (defaults to: "it.cowtech.devdnsd")

    The base name for the agent.

Returns:

  • (String)

    The path for the launch agent file.



22
23
24
# File 'lib/devdnsd/osx.rb', line 22

def launch_agent_path(name = "it.cowtech.devdnsd")
  ENV["HOME"] + "/Library/LaunchAgents/#{name}.plist"
end

#osx?Boolean Also known as: is_osx?

Checks if we are running on MacOS X.

System services are only available on that platform.

Returns:

  • (Boolean)

    true if the current platform is MacOS X, false otherwise.



55
56
57
# File 'lib/devdnsd/osx.rb', line 55

def osx?
  ::RbConfig::CONFIG['host_os'] =~ /^darwin/
end

#resolver_path(tld = nil) ⇒ String

Gets the path for the resolver file.

Parameters:

  • tld (String) (defaults to: nil)

    The TLD to manage.

Returns:

  • (String)

    The path for the resolver file.



13
14
15
16
# File 'lib/devdnsd/osx.rb', line 13

def resolver_path(tld = nil)
  tld ||= @config.tld
  "/etc/resolver/#{tld}"
end