Sha256: c9520378daaf4479fd9be8f593a646100731371b1c51e90f4390854f970be40b
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 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 initialize(env={}) @env = env end def info(msg) @env[:ui].info("[landrush] #{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 "Momentarily 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! 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
landrush-1.0.0 | lib/landrush/resolver_config.rb |