automatically installs virtio-drivers on windose. far from perfect, but

it does it's job and I dont't care. It's just windose...
This commit is contained in:
Peter V. Beck 2017-11-11 00:32:56 +01:00
parent 25b86e94ca
commit 86485f564e
8 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>kvm-virtio-drivers</id>
<version>0.1.141</version>
<title>KVM Virtio Drivers for Windows</title>
<authors>Red Hat</authors>
<owners>foo.li systeme + software</owners>
<licenseUrl>https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html</licenseUrl>
<projectUrl>https://fedoraproject.org/wiki/Windows_Virtio_Drivers</projectUrl>
<iconUrl>https://raw.githubusercontent.com/peterbeck/chocolatey/master/icons/kvm.png</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>virtio drivers for Windows virtual machines running on KVM, and additional software agents for Windows VMs.
This package will download the latest stable drivers, unzip them and tries automatically to update/install needed drivers.
Note: for the QEMU guest agent there is a separate package available (which already uses this package as dependency).</description>
<summary>KVM Virtio Drivers</summary>
<releaseNotes>upgrade to 0.1.141</releaseNotes>
<tags>virtualisation kvm virtio guest-agents drivers</tags>
</metadata>
</package>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,108 @@
# Virtio Drivers for Windows VMs running on KVM
# 2011-2017 foo.li systeme + software
# 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'
$version = '0.1.141'
$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'
$checksum = '43AEFA812C37342CFEFC48EC0DD7F1E56A930FCD'
$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 }
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
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
} catch {
throw $_.Exception
}

View File

@ -0,0 +1,18 @@
# Spice Guest Tools Removal
# 2017 foo.li systeme + software
$packageName = 'kvm-virito-drivers'
$version = '0.1.126'
$virtioPath = "$env:SystemDrive" + "\Virtio_" + $version
try {
if (Test-Path $virtioPath) {
Write-Host 'removing directory ' $virtioPath
Remove-Item $virtioPath -Recurse -Force
} else {
Write-Host 'could not detect ' $virtioPath ' files.'
}
Write-Host '[NOTE]: this does not remove any installed drivers, just the sourcefiles.'
} catch {
throw $_.Exception
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" ?>
<dpinst>
<search>
<subDirectory>*</subDirectory>
</search>
</dpinst>

Binary file not shown.

Binary file not shown.