Class: VagrantRubydns::ResolverConfig
- Inherits:
-
Object
- Object
- VagrantRubydns::ResolverConfig
- Defined in:
- lib/vagrant-rubydns/resolver_config.rb
Class Method Summary collapse
- .config_file ⇒ Object
- .contents_match? ⇒ Boolean
- .desired_contents ⇒ Object
- .ensure_config_exists ⇒ Object
- .osx? ⇒ Boolean
- .puts(str) ⇒ Object
- .write_config ⇒ Object
Class Method Details
.config_file ⇒ Object
16 17 18 |
# File 'lib/vagrant-rubydns/resolver_config.rb', line 16 def self.config_file Pathname('/etc/resolver/vagrant.dev') end |
.contents_match? ⇒ Boolean
20 21 22 |
# File 'lib/vagrant-rubydns/resolver_config.rb', line 20 def self.contents_match? config_file.exist? && File.read(config_file) == desired_contents end |
.desired_contents ⇒ Object
5 6 7 8 9 10 |
# File 'lib/vagrant-rubydns/resolver_config.rb', line 5 def self.desired_contents; <<-EOS.gsub(/^ /, '') # Generated by vagrant-rubydns nameserver 127.0.0.1 port 10053 EOS end |
.ensure_config_exists ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vagrant-rubydns/resolver_config.rb', line 35 def self.ensure_config_exists unless osx? puts "Not an OSX machine, so skipping host DNS resolver config." return end if contents_match? puts "Host DNS resolver config looks good." else puts "Need to configure the host." write_config end end |
.osx? ⇒ Boolean
12 13 14 |
# File 'lib/vagrant-rubydns/resolver_config.rb', line 12 def self.osx? `uname`.chomp == 'Darwin' end |
.puts(str) ⇒ Object
49 50 51 |
# File 'lib/vagrant-rubydns/resolver_config.rb', line 49 def self.puts(str) Kernel.puts("[vagrant-rubydns] #{str}") end |
.write_config ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant-rubydns/resolver_config.rb', line 24 def self.write_config puts "Mometarily using sudo to put the host config in place..." Tempfile.open('vagrant_rubydns_host_config') do |f| f.write(desired_contents) f.close `sudo cp #{f.path} /etc/resolver/vagrant.dev` `sudo chown root:wheel /etc/resolver/vagrant.dev` `sudo chmod 644 /etc/resolver/vagrant.dev` end end |