guests/funtoo: Behave like a gentoo guest

This commit is contained in:
Seth Vargo 2016-06-22 18:31:17 -07:00
parent d9936e8808
commit 3eebff5bf3
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
4 changed files with 29 additions and 29 deletions

View File

@ -1,17 +0,0 @@
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

View File

@ -6,16 +6,11 @@ module VagrantPlugins
name "Funtoo guest"
description "Funtoo guest support."
guest(:funtoo, :linux) do
guest(:funtoo, :gentoo) do
require_relative "guest"
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

View File

@ -3,12 +3,25 @@ module VagrantPlugins
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
comm = machine.communicate
if !comm.test("hostname -f | grep '^#{name}$'")
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, "")
# Set the hostname
hostname '#{basename}'
echo "hostname=#{basename}" > /etc/conf.d/hostname
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' /etc/hosts
sed -i'' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts
mv /tmp/tmp-hosts /etc/hosts
}
EOH
end
end
end

View File

@ -0,0 +1,9 @@
#VAGRANT-BEGIN
template='interface'
ipaddr='<%= options[:ip] %>/<%= options[:netmask] %>'
<% [:gateway, :nameservers, :domain, :route, :gateway6, :route6, :mtu].each do |key| %>
<% if options[key] %>
<%= key %>='<%= options[key] %>'
<% end %>
<% end %>
#VAGRANT-END