forked from rgl/windows-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-guest-tools-qemu-kvm.ps1
38 lines (35 loc) · 1.43 KB
/
provision-guest-tools-qemu-kvm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Set-StrictMode -Version Latest
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
trap {
Write-Host
Write-Host "ERROR: $_"
($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1' | Write-Host
($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1' | Write-Host
Write-Host
Write-Host 'Sleeping for 60m to give you time to look around the virtual machine before self-destruction...'
Start-Sleep -Seconds (60*60)
Exit 1
}
# try to find it in a drive.
$guestToolsFilename = 'virtio-win-guest-tools.exe'
$guestTools = Get-PSDrive -PSProvider FileSystem | ForEach-Object {
$p = Join-Path $_.Root $guestToolsFilename
if (Test-Path $p) {
$p
}
} | Select-Object -First 1
# otherwise, download it from the packer http server.
if (!$guestTools) {
$guestToolsUrl = "http://$env:PACKER_HTTP_ADDR/drivers/$guestToolsFilename"
$guestTools = "$env:TEMP\$guestToolsFilename"
Write-Host "Downloading the guest tools from $guestToolsUrl..."
Invoke-WebRequest $guestToolsUrl -OutFile $guestTools
}
Write-Host 'Installing the guest tools...'
$guestToolsLog = "$env:TEMP\$guestToolsFilename.log"
&$guestTools /install /norestart /quiet /log $guestToolsLog | Out-String -Stream
if ($LASTEXITCODE) {
throw "failed to install guest tools with exit code $LASTEXITCODE"
}
Write-Host "Done installing the guest tools."