Add White List Option

pull/38/head
Romain 2022-04-05 15:17:18 +02:00
parent acc36bf2ad
commit 758b2608ae
8 changed files with 127 additions and 79 deletions

View File

@ -95,13 +95,14 @@ function Install-WingetAutoUpdate{
New-Item -ItemType Directory -Force -Path $WingetUpdatePath
}
Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
#White List or Black List apps
if ($UseWhiteList){
if (Test-Path "$PSScriptRoot\included_apps.txt"){
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
}
else{
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file"
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue
}
}
else {

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<app>
<name>Winget-AutoUpdate (WAU)</name>
<version>1.6.3</version>
<version>1.7.0</version>
<author>Romanitho</author>
<info>https://github.com/Romanitho/Winget-AutoUpdate</info>
</app>

View File

@ -0,0 +1,5 @@
function Get-IncludedApps{
if (Test-Path "$WorkingDir\included_apps.txt"){
return Get-Content -Path "$WorkingDir\included_apps.txt"
}
}

View File

@ -0,0 +1,14 @@
function Get-WAUConfig{
[xml]$WAUConfig = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
#Check if WAU is configured for Black or White List
if ($true -eq [System.Convert]::ToBoolean($WAUConfig.app.UseWAUWhiteList)){
Write-Log "WAU uses White List config"
$Script:UseWhiteList = $true
}
else{
Write-Log "WAU uses Black List config"
$Script:UseWhiteList = $false
}
}

View File

@ -10,15 +10,15 @@ function Get-WingetOutdatedApps {
$WingetPath = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe").Path
#Get Winget Location in User context
if ($WingetCmd){
$Script:winget = (Get-Command winget.exe -ErrorAction SilentlyContinue).Source
$Script:Winget = (Get-Command winget.exe -ErrorAction SilentlyContinue).Source
}
#Get Winget Location in System context (WinGet < 1.17)
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
$Script:winget = "$WingetPath\AppInstallerCLI.exe"
$Script:Winget = "$WingetPath\AppInstallerCLI.exe"
}
#Get Winget Location in System context (WinGet > 1.17)
elseif (Test-Path "$WingetPath\winget.exe"){
$Script:winget = "$WingetPath\winget.exe"
$Script:Winget = "$WingetPath\winget.exe"
}
else{
Write-Log "Winget not installed !" "Red"
@ -26,10 +26,10 @@ function Get-WingetOutdatedApps {
}
#Run winget to list apps and accept source agrements (necessary on first run)
& $upgradecmd list --accept-source-agreements | Out-Null
& $Winget list --accept-source-agreements | Out-Null
#Get list of available upgrades on winget format
$upgradeResult = & $upgradecmd upgrade | Out-String
$upgradeResult = & $Winget upgrade | Out-String
#Start Convertion of winget format to an array. Check if "-----" exists
if (!($upgradeResult -match "-----")){

View File

@ -0,0 +1,59 @@
Function Update-App ($app) {
#Send available update notification
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
$MessageType = "info"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
#Winget upgrade
Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
#Run Winget Upgrade command
& $Winget upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
#Check if application updated properly
$CheckOutdated = Get-WingetOutdatedApps
$FailedToUpgrade = $false
foreach ($CheckApp in $CheckOutdated){
if ($($CheckApp.Id) -eq $($app.Id)) {
#If app failed to upgrade, run Install command
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
#Check if application installed properly
$CheckOutdated2 = Get-WingetOutdatedApps
foreach ($CheckApp2 in $CheckOutdated2){
if ($($CheckApp2.Id) -eq $($app.Id)) {
$FailedToUpgrade = $true
}
}
}
}
Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
#Notify installation
if ($FailedToUpgrade -eq $false){
#Send success updated app notification
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
#Send Notif
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
$MessageType = "success"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
$InstallOK += 1
}
else {
#Send failed updated app notification
Write-Log "$($app.Name) update failed." "Red"
#Send Notif
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[4].message
$MessageType = "error"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
}
}

View File

@ -35,8 +35,14 @@ if (Test-Network){
}
}
#Get exclude apps list
#Get White or Black list
Get-WAUConfig
if ($UseWhiteList){
$toUpdate = Get-IncludedApps
}
else{
$toSkip = Get-ExcludedApps
}
#Get outdated Winget packages
Write-Log "Checking application updates on Winget Repository..." "yellow"
@ -51,69 +57,31 @@ if (Test-Network){
}
#Count good update installations
$InstallOK = 0
$Script:InstallOK = 0
#If White List
if ($UseWhiteList){
#For each app, notify and update
foreach ($app in $outdated){
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown"){
Update-App $app
}
#if current app version is unknown
elseif($($app.Version) -eq "Unknown"){
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
}
#if app is in "excluded list"
else{
Write-Log "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray"
}
}
}
#If Black List
else{
#For each app, notify and update
foreach ($app in $outdated){
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
#Send available update notification
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
$Title = $NotifLocale.local.outputs.output[2].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
$MessageType = "info"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
#Winget upgrade
Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
#Run Winget Upgrade command
& $UpgradeCmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
#Check if application updated properly
$CheckOutdated = Get-WingetOutdatedApps
$FailedToUpgrade = $false
foreach ($CheckApp in $CheckOutdated){
if ($($CheckApp.Id) -eq $($app.Id)) {
#If app failed to upgrade, run Install command
& $upgradecmd install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
#Check if application installed properly
$CheckOutdated2 = Get-WingetOutdatedApps
foreach ($CheckApp2 in $CheckOutdated2){
if ($($CheckApp2.Id) -eq $($app.Id)) {
$FailedToUpgrade = $true
}
}
}
}
Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
#Notify installation
if ($FailedToUpgrade -eq $false){
#Send success updated app notification
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"
#Send Notif
$Title = $NotifLocale.local.outputs.output[3].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[3].message -f $($app.AvailableVersion)
$MessageType = "success"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
$InstallOK += 1
}
else {
#Send failed updated app notification
Write-Log "$($app.Name) update failed." "Red"
#Send Notif
$Title = $NotifLocale.local.outputs.output[4].title -f $($app.Name)
$Message = $NotifLocale.local.outputs.output[4].message
$MessageType = "error"
$Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise
}
Update-App $app
}
#if current app version is unknown
elseif($($app.Version) -eq "Unknown"){
@ -124,6 +92,7 @@ if (Test-Network){
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
}
}
}
if ($InstallOK -gt 0){
Write-Log "$InstallOK apps updated ! No more update." "Green"

View File

@ -1,2 +1,2 @@
@echo off
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Silent'" -Verb RunAs
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -UseWhiteList -Silent'" -Verb RunAs