Sha256: ebb15f1fedd2f5ce40914b496295bbb0340b83cbf2f4527a3fa5e3c243ababa0
Contents?: true
Size: 1.63 KB
Versions: 2
Compression:
Stored size: 1.63 KB
Contents
require 'tempfile' module Landrush class ResolverConfig class << self; attr_writer :sudo, :config_dir end def self.sudo @sudo ||= 'sudo' end def self.config_dir @config_dir ||= Pathname('/etc/resolver') end def config_dir self.class.config_dir end def initialize(env={}) @env = env end def info(msg) @env[:ui].info(msg) end def desired_contents; <<-EOS.gsub(/^ /, '') # Generated by landrush, a vagrant plugin nameserver 127.0.0.1 port #{Server.port} EOS end def osx? `uname`.chomp == 'Darwin' end def config_dir self.class.config_dir end def config_file config_dir.join(@env[:machine].config.landrush.tld) end def contents_match? config_file.exist? && File.read(config_file) == desired_contents end def write_config! info "Mometarily using sudo to put the host config in place..." system "#{self.class.sudo} mkdir #{config_dir}" unless config_dir.directory? Tempfile.open('vagrant_landrush_host_config') do |f| f.write(desired_contents) f.close system "#{sudo} cp #{f.path} #{config_file}" system "#{sudo} chmod 644 #{config_file}" end end def ensure_config_exists! unless osx? puts "Not an OSX machine, so skipping host DNS resolver config." return end if contents_match? info "Host DNS resolver config looks good." else info "Need to configure the host." write_config! end end def sudo self.class.sudo end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
landrush-0.13.1 | lib/landrush/resolver_config.rb |
landrush-0.13.0 | lib/landrush/resolver_config.rb |