chocolatey/packages/kvm-virtio-drivers/tools/chocolateyinstall.ps1

118 lines
6.1 KiB
PowerShell
Raw Normal View History

# Virtio Drivers for Windows VMs running on KVM
2022-02-14 01:02:45 +01:00
# 2011-2022 foo.li systeme + software
2020-05-10 15:53:10 +02:00
# export installed redhat certificate to a file with win7
# $CertToExport = dir cert:\LocalMachine -Recurse | where {$_.ThumbPrint -eq "66ED6843B0F6DC9B636C6814E53A26983EF32B4E"}
# $CertToExportInBytesForCERFile = $CertToExport.export("Cert")
# [system.IO.file]::WriteAllBytes("C:\Temp\RedHat.cer", $CertToExportInBytesForCERFile)
$packageName = 'kvm-virtio-drivers'
2022-02-14 01:02:45 +01:00
$version = '0.1.215'
$url = 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso'
$url64 = $url
$virtioPath = "$env:SystemDrive" + "\Virtio_" + $version
$scriptPath = $(Split-Path $MyInvocation.MyCommand.Path)
$dpinst = Join-Path $scriptPath 'dpinstX86.exe'
$dpinst64 = Join-Path $scriptPath 'dpinstX64.exe'
$dpinstxml = Join-Path $scriptPath 'dpinst.xml'
$cleanupdrv = Join-Path $scriptPath 'cleanfolder.ps1'
2022-02-14 01:02:45 +01:00
$checksum = '38364f050257b7c34b9f0c4b5d234c4c2cc5929d'
$checksumType = 'sha1'
$checksum64 = $checksum
$checksumType64 = $checksumType
$cert = ls cert: -Recurse | ? { $_.Thumbprint -eq '66ED6843B0F6DC9B636C6814E53A26983EF32B4E' }
if (!$cert) {
Write-Debug 'adding RedHat certificate to TrustedPublishers'
$toolsPath = Split-Path $MyInvocation.MyCommand.Definition
Start-ChocolateyProcessAsAdmin "certutil -addstore 'TrustedPublisher' '$toolsPath\RedHat.cer'"
}
if ([System.Environment]::Is64BitProcess) {
#if ($env:PROCESSOR_ARCHICTECTURE -eq 'AMD64') { #does not work when run in choco ?!
$dpinstsrc = $dpinst64
$dpinstbin = "${virtioPath}\${dpinst64}"
$dpinstaller = "${virtioPath}\dpinstX64.exe"
$arch = 'amd64'
} else {
$dpinstsrc = $dpinst
$dpinstbin = "${virtioPath}\${dpinst}"
$dpinstaller = "${virtioPath}\dpinstX86.exe"
$arch = 'x86'
}
try {
if (!(Test-Path $virtioPath)) {
New-Item $virtioPath -ItemType Directory
}
Write-Host 'unzipping files to ' $virtioPath
Write-Host "[INFO]: use the package 'qemu-guest-agent' to install the QEMU Guest Agent."
Install-ChocolateyZipPackage -PackageName $packageName -Url $url -UnzipLocation $virtioPath `
-checksum $checksum -checksumType $checksumType -checksum64 -$checksum64 -checksumType64 $checksumType64
Copy-Item -Path $dpinstsrc -Destination $virtioPath #-ErrorAction SilentlyContinue
Copy-Item -Path $dpinstxml -Destination $virtioPath #-ErrorAction SilentlyContinue
#Remove unneeded architectures and os first to avoid installing wrong drivers and safe space
$lvl1 = (Get-ChildItem -Path $virtioPath -Exclude qemupciserial | ?{ $_.PSIsContainer } | % { $_.FullName })
$OS = (Get-WmiObject -class Win32_OperatingSystem).Caption
switch -wildcard -casesensitive ($OS) {
"*Windows 7*" { Write-Host "Windows 7 detected";$d="w7";break}
"*Windows 10*" { Write-Host "Windows 10 detected";$d="w10";break }
"*Server 2003*" { Write-Host "Server 2003 detected";$d="2k3";break }
"*Server 2008 R2*" { Write-Host "Server 2008 R2 detected";$d="2k8R2";break }
"*Server* 2008*" { Write-Host "Server 2008 detected";$d="2k8";break } #copyright logo, really ?! fucking windows world
"*Server 2012 R2*" { Write-Host "Server 2012 R2 detected";$d="2k12R2";break }
"*Server 2012*" { Write-Host "Server 2012 detected";$d="2k12";break }
"*Server 2016*" { Write-Host "Server 2016 detected";$d="2k16";break }
2020-08-23 11:41:09 +02:00
"*Server 2019*" { Write-Host "Server 2019 detected";$d="2k19";break }
default {"unknown/unsupported os"; exit 1 }
}
#os detection/removal currently tested with: win7x64,win10x64,2008,2008R2,2012R2,2016
$wrongos = (Get-ChildItem -Path $lvl1 -Recurse -Exclude $d| ?{ $_.PSIsContainer -and $_.FullName -notlike "*$d*" })
if (!($wrongos -eq $null)) { #do not run a second time when there is nothing to do
Write-Host "removing unneeded Operating Systems.."
foreach ($dir in $wrongos) {
Remove-Item $dir.FullName -Recurse -Force -ea SilentlyContinue
}
}
$wrongarch = (Get-ChildItem -Path $lvl1 -Recurse | ?{ $_.PSIsContainer -and $_.FullName -notlike "*$arch*" -and $_.FullName -notlike "*$d" })
if (!($wrongarch -eq $null)) { #do not run a second time when there is nothing to do
Write-Host "removing unneeded architecture..."
foreach ($archdir in $wrongarch) {
foreach ($ad in $archdir) {
if ($ad -notlike "*$arch*") {
Remove-Item $ad.FullName -Recurse -Force -ea SilentlyContinue
}
}
}
}
#we do not need virtual floppy images, save some space ;-)
Remove-Item -Path "${virtioPath}\virtio-win-${version}_amd64.vfd" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "${virtioPath}\virtio-win-${version}_x86.vfd" -Force -ErrorAction SilentlyContinue
Write-Host 'trying to install drivers from' $virtioPath '.This may take a while...'
$cleanupdrv
Write-Host 'even the package setup finishes successfully,'
Write-Host 'the driver wizard will still run for quiet some time.'
#Start-ChocolateyProcessAsAdmin -Statements "/q /se /sw /sa /path $virtioPath" -ExeToRun $dpinstaller
& $dpinstaller /S /SA /SE /SW /PATH $virtioPath
2020-05-10 15:53:10 +02:00
Write-Host '[INFO]: The Logfile for the driver installations is %windir%\DPINST.LOG'
Write-Host '[INFO]: removing previous virtio-driver versions'
Remove-Item "${env:SystemDrive}\Virtio_0.1.126" -Force -Recurse -ErrorAction SilentlyContinue
2020-05-10 15:53:10 +02:00
Remove-Item "${env:SystemDrive}\Virtio_0.1.141" -Force -Recurse -ErrorAction SilentlyContinue
2020-08-23 11:41:09 +02:00
Remove-Item "${env:SystemDrive}\Virtio_0.1.171" -Force -Recurse -ErrorAction SilentlyContinue
2021-12-30 13:39:23 +01:00
Remove-Item "${env:SystemDrive}\Virtio_0.1.185" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item "${env:SystemDrive}\Virtio_0.1.189" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item "${env:SystemDrive}\Virtio_0.1.190" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item "${env:SystemDrive}\Virtio_0.1.196" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item "${env:SystemDrive}\Virtio_0.1.204" -Force -Recurse -ErrorAction SilentlyContinue
2022-02-14 01:02:45 +01:00
Remove-Item "${env:SystemDrive}\Virtio_0.1.208" -Force -Recurse -ErrorAction SilentlyContinue
} catch {
throw $_.Exception
}