alpine: Remove unneeded aliases in change_host_name
This commit is contained in:
parent
a7f09f010c
commit
39fb585295
|
@ -33,7 +33,7 @@ module VagrantPlugins
|
|||
|
||||
def fetch_current_hostname
|
||||
hostname = ''
|
||||
sudo 'hostname -f' do |type, data|
|
||||
machine.communicate.sudo 'hostname -f' do |type, data|
|
||||
hostname = data.chomp if type == :stdout && hostname.empty?
|
||||
end
|
||||
|
||||
|
@ -41,54 +41,42 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def update_etc_hostname
|
||||
sudo("echo '#{short_hostname}' > /etc/hostname")
|
||||
machine.communicate.sudo("echo '#{short_hostname}' > /etc/hostname")
|
||||
end
|
||||
|
||||
# /etc/hosts should resemble:
|
||||
# 127.0.0.1 localhost
|
||||
# 127.0.1.1 host.fqdn.com host.fqdn host
|
||||
def update_etc_hosts
|
||||
if test("grep '#{current_hostname}' /etc/hosts")
|
||||
if machine.communicate.test("grep '#{current_hostname}' /etc/hosts")
|
||||
# Current hostname entry is in /etc/hosts
|
||||
ip_address = '([0-9]{1,3}\.){3}[0-9]{1,3}'
|
||||
search = "^(#{ip_address})\\s+#{Regexp.escape(current_hostname)}(\\s.*)?$"
|
||||
replace = "\\1 #{fqdn} #{short_hostname}"
|
||||
replace = "\\1 #{new_hostname} #{short_hostname}"
|
||||
expression = ['s', search, replace, 'g'].join('@')
|
||||
|
||||
sudo("sed -ri '#{expression}' /etc/hosts")
|
||||
machine.communicate.sudo("sed -ri '#{expression}' /etc/hosts")
|
||||
else
|
||||
# Current hostname entry isn't in /etc/hosts, just append it
|
||||
sudo("echo '127.0.1.1 #{fqdn} #{short_hostname}' >>/etc/hosts")
|
||||
machine.communicate.sudo("echo '127.0.1.1 #{new_hostname} #{short_hostname}' >>/etc/hosts")
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_hostname_service
|
||||
sudo('hostname -F /etc/hostname')
|
||||
machine.communicate.sudo('hostname -F /etc/hostname')
|
||||
end
|
||||
|
||||
def update_mailname
|
||||
sudo('hostname -f > /etc/mailname')
|
||||
machine.communicate.sudo('hostname -f > /etc/mailname')
|
||||
end
|
||||
|
||||
def renew_dhcp
|
||||
sudo('ifdown -a; ifup -a; ifup eth0')
|
||||
end
|
||||
|
||||
def fqdn
|
||||
new_hostname
|
||||
machine.communicate.sudo('ifdown -a; ifup -a; ifup eth0')
|
||||
end
|
||||
|
||||
def short_hostname
|
||||
new_hostname.split('.').first
|
||||
end
|
||||
|
||||
def sudo(cmd, &block)
|
||||
machine.communicate.sudo(cmd, &block)
|
||||
end
|
||||
|
||||
def test(cmd)
|
||||
machine.communicate.test(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue