Class: VagrantDNS::Installers::Linux
- Inherits:
-
Object
- Object
- VagrantDNS::Installers::Linux
- Defined in:
- lib/vagrant-dns/installers/linux.rb
Constant Summary collapse
- EXEC_STYLES =
%i{sudo}
- RESOLVED_CONFIG =
"vagrant-dns.conf"
Instance Attribute Summary collapse
-
#exec_style ⇒ Object
Returns the value of attribute exec_style.
-
#install_path ⇒ Object
Returns the value of attribute install_path.
-
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
Class Method Summary collapse
-
.resolver_files(ip, port, tlds) {|filename, content| ... } ⇒ Object
Generate the resolved config.
Instance Method Summary collapse
- #exec(*commands) ⇒ Object
-
#initialize(tmp_path, options = {}) ⇒ Linux
constructor
A new instance of Linux.
- #install! ⇒ Object
- #purge! ⇒ Object
- #uninstall! ⇒ Object
Constructor Details
#initialize(tmp_path, options = {}) ⇒ Linux
Returns a new instance of Linux.
9 10 11 12 13 |
# File 'lib/vagrant-dns/installers/linux.rb', line 9 def initialize(tmp_path, = {}) self.tmp_path = tmp_path self.install_path = .fetch(:install_path, "/etc/systemd/resolved.conf.d") self.exec_style = .fetch(:exec_style, :sudo) end |
Instance Attribute Details
#exec_style ⇒ Object
Returns the value of attribute exec_style.
7 8 9 |
# File 'lib/vagrant-dns/installers/linux.rb', line 7 def exec_style @exec_style end |
#install_path ⇒ Object
Returns the value of attribute install_path.
7 8 9 |
# File 'lib/vagrant-dns/installers/linux.rb', line 7 def install_path @install_path end |
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
7 8 9 |
# File 'lib/vagrant-dns/installers/linux.rb', line 7 def tmp_path @tmp_path end |
Class Method Details
.resolver_files(ip, port, tlds) {|filename, content| ... } ⇒ Object
Generate the resolved config.
20 21 22 23 24 25 26 27 28 |
# File 'lib/vagrant-dns/installers/linux.rb', line 20 def self.resolver_files(ip, port, tlds) contents = "# This file is generated by vagrant-dns\n" \ "[Resolve]\n" \ "DNS=#{ip}:#{port}\n" \ "Domains=~#{tlds.join(' ~')}\n" yield "vagrant-dns.conf", contents end |
Instance Method Details
#exec(*commands) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vagrant-dns/installers/linux.rb', line 59 def exec(*commands) return if !commands || commands.empty? case exec_style when :sudo commands.each do |c| system 'sudo', *c end else raise ArgumentError, "Unsupported execution style: #{exec_style}. Use one of #{EXEC_STYLES.map(&:inspect).join(' ')}" end end |
#install! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vagrant-dns/installers/linux.rb', line 30 def install! require 'fileutils' src = File.join(tmp_path, "resolver", RESOLVED_CONFIG) dest = File.join(install_path, RESOLVED_CONFIG) commands = [ ['install', '-D', '-m', '0644', '-T', src.shellescape, dest.shellescape], ['systemctl', 'reload-or-restart', 'systemd-resolved.service'] ] exec(*commands) end |
#purge! ⇒ Object
53 54 55 56 57 |
# File 'lib/vagrant-dns/installers/linux.rb', line 53 def purge! require 'fileutils' uninstall! FileUtils.rm_r(tmp_path) end |
#uninstall! ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/vagrant-dns/installers/linux.rb', line 44 def uninstall! commands = [ ['rm', File.join(install_path, RESOLVED_CONFIG)], ['systemctl', 'reload-or-restart', 'systemd-resolved.service'] ] exec(*commands) end |