Module: Dory::Resolv::Macos
- Defined in:
- lib/dory/resolv/macos.rb
Class Method Summary collapse
- .clean ⇒ Object
- .configure ⇒ Object
- .configured_to_use_dinghy ⇒ Object
- .contents_has_our_nameserver?(contents) ⇒ Boolean
- .file_comment ⇒ Object
- .file_nameserver_line ⇒ Object
- .has_our_nameserver? ⇒ Boolean
- .nameserver ⇒ Object
- .port ⇒ Object
- .resolv_contents ⇒ Object
- .resolv_dir ⇒ Object
- .resolv_file_contents ⇒ Object
- .resolv_file_names ⇒ Object
- .resolv_files ⇒ Object
- .system_resolv_file ⇒ Object
- .system_resolv_file_contents ⇒ Object
Class Method Details
.clean ⇒ Object
73 74 75 76 77 78 |
# File 'lib/dory/resolv/macos.rb', line 73 def self.clean self.resolv_files.each do |filename| puts "Requesting sudo to delete '#{filename}'".green Bash.run_command("sudo rm -f #{filename}") end end |
.configure ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dory/resolv/macos.rb', line 58 def self.configure # have to use this hack cuz we don't run as root :-( unless Dir.exist?(self.resolv_dir) puts "Requesting sudo to create directory #{self.resolv_dir}".green Bash.run_command("sudo mkdir -p #{self.resolv_dir}") end self.resolv_files.each do |filename| puts "Requesting sudo to write to #{filename}".green Bash.run_command("echo -e '#{self.resolv_contents}' | sudo /usr/bin/tee #{Shellwords.escape(filename)} >/dev/null") end rescue DinghyError => e puts e..red false end |
.configured_to_use_dinghy ⇒ Object
33 34 35 |
# File 'lib/dory/resolv/macos.rb', line 33 def self.configured_to_use_dinghy Dory::Dinghy.match?(Dory::Config.settings[:dory][:resolv][:nameserver]) end |
.contents_has_our_nameserver?(contents) ⇒ Boolean
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dory/resolv/macos.rb', line 98 def self.contents_has_our_nameserver?(contents) comment_match = contents =~ /#{self.file_comment}/ port_match = contents =~ /port.#{self.port}/ if configured_to_use_dinghy !!(comment_match && port_match) else nameserver_match = contents =~ /#{self.file_nameserver_line}/ !!(comment_match && port_match && nameserver_match) end end |
.file_comment ⇒ Object
46 47 48 |
# File 'lib/dory/resolv/macos.rb', line 46 def self.file_comment '# added by dory' end |
.file_nameserver_line ⇒ Object
42 43 44 |
# File 'lib/dory/resolv/macos.rb', line 42 def self.file_nameserver_line "nameserver #{self.nameserver}" end |
.has_our_nameserver? ⇒ Boolean
88 89 90 91 92 93 94 95 96 |
# File 'lib/dory/resolv/macos.rb', line 88 def self.has_our_nameserver? self.resolv_files.all? do |filename| if File.exist?(filename) self.contents_has_our_nameserver?(File.read(filename)) else false end end end |
.nameserver ⇒ Object
37 38 39 40 |
# File 'lib/dory/resolv/macos.rb', line 37 def self.nameserver ns = Dory::Config.settings[:dory][:resolv][:nameserver] Dory::Dinghy.match?(ns) ? Dory::Dinghy.ip : ns end |
.port ⇒ Object
10 11 12 |
# File 'lib/dory/resolv/macos.rb', line 10 def self.port Dory::Config.settings[:dory][:resolv][:port] || 19323 end |
.resolv_contents ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/dory/resolv/macos.rb', line 50 def self.resolv_contents <<-EOF.gsub(' ' * 10, '') #{self.file_comment} #{self.file_nameserver_line} port #{self.port} EOF end |
.resolv_dir ⇒ Object
14 15 16 |
# File 'lib/dory/resolv/macos.rb', line 14 def self.resolv_dir '/etc/resolver' end |
.resolv_file_contents ⇒ Object
84 85 86 |
# File 'lib/dory/resolv/macos.rb', line 84 def self.resolv_file_contents File.read(self.resolv_file) end |
.resolv_file_names ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dory/resolv/macos.rb', line 18 def self.resolv_file_names # on macos the file name should match the domain if Dory::Config.settings[:dory][:dnsmasq][:domain] [Dory::Config.settings[:dory][:dnsmasq][:domain]] elsif Dory::Config.settings[:dory][:dnsmasq][:domains] Dory::Config.settings[:dory][:dnsmasq][:domains].map{ |d| d[:domain] } else ['docker'] end end |
.resolv_files ⇒ Object
29 30 31 |
# File 'lib/dory/resolv/macos.rb', line 29 def self.resolv_files self.resolv_file_names.map{ |f| "#{self.resolv_dir}/#{f}" } end |
.system_resolv_file ⇒ Object
6 7 8 |
# File 'lib/dory/resolv/macos.rb', line 6 def self.system_resolv_file '/etc/resolv.conf' end |
.system_resolv_file_contents ⇒ Object
80 81 82 |
# File 'lib/dory/resolv/macos.rb', line 80 def self.system_resolv_file_contents File.read(self.system_resolv_file) end |