11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/vagrant-guest-msys2/cap/change_host_name.rb', line 11
def self.change_host_name_and_wait(machine, name, sleep_timeout)
escaped_name = name.gsub("'", "''")
return if machine.communicate.test(Util::CapHelpers.wrap_powershell("if ([System.Net.Dns]::GetHostName() -eq '#{escaped_name}') { exit 0 } exit 1"))
script = <<-EOH.gsub(/^ {14}/, '')
$computer = Get-WmiObject -Class Win32_ComputerSystem
$retval = $computer.rename('#{escaped_name}').returnvalue
if ($retval -eq 0) {
shutdown -r -t 5 -f -d p:4:1 -c "Vagrant Rename Computer"
}
exit $retval
EOH
machine.ui.info I18n.t("vagrant-guest-msys2.info.run_change_host_name", host: name)
machine.communicate.execute(Util::CapHelpers.wrap_powershell(script))
machine.ui.info I18n.t("vagrant-guest-msys2.info.run_wait_for_reboot", host: name)
sleep(sleep_timeout)
end
|