Add funtoo guest support. Based heavily on https://github.com/mitchellh/vagrant/pull/1840
This commit is contained in:
parent
f89c4412b2
commit
3559c08086
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
||||||
|
#VAGRANT-BEGIN
|
||||||
|
# The contents below are automatically generated by Vagrant. Do not modify.
|
||||||
|
template='dhcp'
|
||||||
|
#VAGRANT-END
|
|
@ -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
|
Loading…
Reference in New Issue