Merge pull request #176 from criticalstack/fix-selinux-permissions-on-etc-hosts

Ensure permissions on /etc/hosts stay intact
This commit is contained in:
Seth Reeser 2016-01-29 13:43:15 -05:00
commit d1ba474417
1 changed files with 2 additions and 7 deletions

View File

@ -17,17 +17,14 @@ module VagrantPlugins
if (machine.communicate.test("uname -s | grep SunOS"))
realhostfile = '/etc/inet/hosts'
move_cmd = 'mv'
elsif (machine.communicate.test("test -d $Env:SystemRoot"))
windir = ""
machine.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents|
windir << contents.gsub("\r\n", '') if type == :stdout
end
realhostfile = "#{windir}\\System32\\drivers\\etc\\hosts"
move_cmd = 'mv -force'
else
realhostfile = '/etc/hosts'
move_cmd = 'mv -f'
end
# download and modify file with Vagrant-managed entries
file = @global_env.tmp_path.join("hosts.#{machine.name}")
@ -37,11 +34,9 @@ module VagrantPlugins
# upload modified file and remove temporary file
machine.communicate.upload(file, '/tmp/hosts')
if windir
machine.communicate.sudo("#{move_cmd} /tmp/hosts/hosts.#{machine.name} #{realhostfile}")
elsif machine.communicate.test('test -f /.dockerinit')
machine.communicate.sudo("cat /tmp/hosts > #{realhostfile}")
machine.communicate.sudo("mv -force /tmp/hosts/hosts.#{machine.name} #{realhostfile}")
else
machine.communicate.sudo("#{move_cmd} /tmp/hosts #{realhostfile}")
machine.communicate.sudo("cat /tmp/hosts > #{realhostfile}")
end
end