From 3559c0808607e90237c3f86c750404b97e7a531c Mon Sep 17 00:00:00 2001 From: Seginoviax Date: Tue, 31 Dec 2013 00:54:32 -0800 Subject: [PATCH] Add funtoo guest support. Based heavily on https://github.com/mitchellh/vagrant/pull/1840 --- plugins/guests/funtoo/cap/change_host_name.rb | 17 ++++++++ .../guests/funtoo/cap/configure_networks.rb | 43 +++++++++++++++++++ plugins/guests/funtoo/guest.rb | 9 ++++ plugins/guests/funtoo/plugin.rb | 25 +++++++++++ templates/guests/funtoo/network_dhcp.erb | 4 ++ templates/guests/funtoo/network_static.erb | 6 +++ 6 files changed, 104 insertions(+) create mode 100644 plugins/guests/funtoo/cap/change_host_name.rb create mode 100644 plugins/guests/funtoo/cap/configure_networks.rb create mode 100644 plugins/guests/funtoo/guest.rb create mode 100644 plugins/guests/funtoo/plugin.rb create mode 100644 templates/guests/funtoo/network_dhcp.erb create mode 100644 templates/guests/funtoo/network_static.erb 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