diff --git a/plugins/guests/funtoo/cap/change_host_name.rb b/plugins/guests/funtoo/cap/change_host_name.rb new file mode 100644 index 000000000..298ff5b12 --- /dev/null +++ b/plugins/guests/funtoo/cap/change_host_name.rb @@ -0,0 +1,17 @@ +module VagrantPlugins + module GuestFuntoo + module Cap + class ChangeHostName + def self.change_host_name(machine, name) + machine.communicate.tap do |comm| + if !comm.test("sudo hostname --fqdn | grep '#{name}'") + comm.sudo("echo 'hostname=#{name.split('.')[0]}' > /etc/conf.d/hostname") + comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts") + comm.sudo("hostname #{name.split('.')[0]}") + end + end + end + end + end + end +end diff --git a/plugins/guests/funtoo/cap/configure_networks.rb b/plugins/guests/funtoo/cap/configure_networks.rb new file mode 100644 index 000000000..9fe51c1f9 --- /dev/null +++ b/plugins/guests/funtoo/cap/configure_networks.rb @@ -0,0 +1,43 @@ +require "tempfile" + +require "vagrant/util/template_renderer" + +module VagrantPlugins + module GuestFuntoo + module Cap + class ConfigureNetworks + include Vagrant::Util + + def self.configure_networks(machine, networks) + machine.communicate.tap do |comm| + # Configure each network interface + networks.each do |network| + # http://www.funtoo.org/Funtoo_Linux_Networking + # dhcpcd generally runs on all interfaces by default + # in the future we can change this, dhcpcd has lots of features + # it would be nice to expose more of its capabilities... + if not /dhcp/i.match(network[:type]) + line = "denyinterfaces eth#{network[:interface]}" + cmd = "grep '#{line}' /etc/dhcpcd.conf; if [ $? -ne 0 ]; then echo '#{line}' >> /etc/dhcpcd.conf ; fi" + comm.sudo(cmd) + ifFile = "netif.eth#{network[:interface]}" + entry = TemplateRenderer.render("guests/funtoo/network_#{network[:type]}", + :options => network) + # Upload the entry to a temporary location + temp = Tempfile.new("vagrant") + temp.binmode + temp.write(entry) + temp.close + comm.upload(temp.path, "/tmp/vagrant-network-entry-#{ifFile}") + comm.sudo("cp /tmp/vagrant-#{ifFile} /etc/conf.d/#{ifFile}") + comm.sudo("chmod 0644 /etc/conf.d/#{ifFile}") + comm.sudo("ln -fs /etc/init.d/netif.tmpl /etc/init.d/#{ifFile}") + comm.sudo("/etc/init.d/#{ifFile} start") + end + end + end + end + end + end + end +end diff --git a/plugins/guests/funtoo/guest.rb b/plugins/guests/funtoo/guest.rb new file mode 100644 index 000000000..adffd194e --- /dev/null +++ b/plugins/guests/funtoo/guest.rb @@ -0,0 +1,9 @@ +module VagrantPlugins + module GuestFuntoo + class Guest < Vagrant.plugin("2", :guest) + def detect?(machine) + machine.communicate.test("grep Funtoo /etc/gentoo-release") + end + end + end +end diff --git a/plugins/guests/funtoo/plugin.rb b/plugins/guests/funtoo/plugin.rb new file mode 100644 index 000000000..7e3227df5 --- /dev/null +++ b/plugins/guests/funtoo/plugin.rb @@ -0,0 +1,25 @@ +require "vagrant" + +module VagrantPlugins + module GuestFuntoo + class Plugin < Vagrant.plugin("2") + name "Funtoo guest" + description "Funtoo guest support." + + guest("funtoo", "linux") do + require File.expand_path("../guest", __FILE__) + Guest + end + + guest_capability("funtoo", "change_host_name") do + require_relative "cap/change_host_name" + Cap::ChangeHostName + end + + guest_capability("funtoo", "configure_networks") do + require_relative "cap/configure_networks" + Cap::ConfigureNetworks + end + end + end +end diff --git a/templates/guests/funtoo/network_dhcp.erb b/templates/guests/funtoo/network_dhcp.erb new file mode 100644 index 000000000..43fb093bf --- /dev/null +++ b/templates/guests/funtoo/network_dhcp.erb @@ -0,0 +1,4 @@ +#VAGRANT-BEGIN +# The contents below are automatically generated by Vagrant. Do not modify. +template='dhcp' +#VAGRANT-END diff --git a/templates/guests/funtoo/network_static.erb b/templates/guests/funtoo/network_static.erb new file mode 100644 index 000000000..ab6a09d10 --- /dev/null +++ b/templates/guests/funtoo/network_static.erb @@ -0,0 +1,6 @@ +#VAGRANT-BEGIN +# The contents below are automatically generated by Vagrant. Do not modify. +template='interface' +ipaddr='<%= options[:ip] %>/<%= options[:netmask] %>' +<%= [:gateway, :nameservers, :domain, :route, :gateway6, :route6, :mtu].reduce([]) { |a,i| a.push("#{i}=#{options[i]}") if options[i]; a }.join("\n") %> +#VAGRANT-END