/
provision-guest-tools-qemu-kvm.ps1
91 lines (88 loc) · 4.15 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
}
function Get-GuestTool($filename) {
# try to find it in a drive.
$path = Get-PSDrive -PSProvider FileSystem | ForEach-Object {
$p = Join-Path $_.Root $filename
if (Test-Path $p) {
$p
}
} | Select-Object -First 1
# otherwise, download it from the packer http server.
if (!$path) {
$url = "http://$env:PACKER_HTTP_ADDR/drivers/$filename"
$path = "$env:TEMP\$filename"
Write-Host "Downloading $url..."
Invoke-WebRequest $url -OutFile $path
}
return $path
}
# install the guest tools.
$guestTools = Get-GuestTool virtio-win-guest-tools.exe
Write-Host 'Installing the guest tools...'
$guestToolsLog = "$env:TEMP\$(Split-Path -Leaf $guestTools).log"
&$guestTools /install /norestart /quiet /log $guestToolsLog | Out-String -Stream
if ($LASTEXITCODE) {
throw "failed to install guest tools with exit code $LASTEXITCODE"
}
Write-Host "Asserting that the QEMU-GA (QEMU Guest Agent) service exists"
Get-Service QEMU-GA
Write-Host "Done installing the guest tools."
# install the spice guest tools.
Write-Host "Trusting the spice guest tools code sign certificate..."
$spiceGuestToolsCodeSignPath = "$env:TEMP\spice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A6
Ly9zZi5zeW1jYi5jb20vc2YuY3JsMGEGA1UdIARaMFgwVgYGZ4EMAQQBMEwwIwYI
KwYBBQUHAgEWF2h0dHBzOi8vZC5zeW1jYi5jb20vY3BzMCUGCCsGAQUFBwICMBkM
F2h0dHBzOi8vZC5zeW1jYi5jb20vcnBhMBMGA1UdJQQMMAoGCCsGAQUFBwMDMFcG
CCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYTaHR0cDovL3NmLnN5bWNkLmNvbTAm
BggrBgEFBQcwAoYaaHR0cDovL3NmLnN5bWNiLmNvbS9zZi5jcnQwHwYDVR0jBBgw
FoAUz5mp6nsm9EvJjo/X8AUm7+PSp50wHQYDVR0OBBYEFL/39F5yNDVDib3B3Uk3
I8XJSrxaMA0GCSqGSIb3DQEBBQUAA4IBAQDWtaW0Dar82t1AdSalPEXshygnvh87
Rce6PnM2/6j/ijo2DqwdlJBNjIOU4kxTFp8jEq8oM5Td48p03eCNsE23xrZl5qim
xguIfHqeiBaLeQmxZavTHPNM667lQWPAfTGXHJb3RTT4siowcmGhxwJ3NGP0gNKC
PHW09x3CdMNCIBfYw07cc6h9+Vm2Ysm9MhqnVhvROj+AahuhvfT9K0MJd3IcEpjX
Z7aMX78Vt9/vrAIUR8EJ54YGgQsF/G9Adzs6fsfEw5Nrk8R0pueRMHRTMSroTe0V
Ae2nvuUU6rVI30q8+UjQCxu/ji1/JnitNkUyOPyC46zL+kfHYSnld8U1
-----END CERTIFICATE-----
'@
Import-Certificate `
-FilePath $spiceGuestToolsCodeSignPath `
-CertStoreLocation Cert:\LocalMachine\TrustedPublisher `
| Out-Null
$spiceGuestTools = Get-GuestTool spice-guest-tools.exe
Write-Host 'Installing the spice guest tools...'
&$spiceGuestTools /S | Out-String -Stream
if ($LASTEXITCODE) {
throw "failed to install spice guest tools with exit code $LASTEXITCODE"
}
Write-Host "Asserting that the vdservice (SPICE Agent) service exists"
Get-Service vdservice
Write-Host "Done installing the spice guest tools."