diff --git a/README.md b/README.md index 08f1d49..a9ea4fe 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ You can run the `winget-install-and-update.ps1` script with parameters : Install Winget-AutoUpdate and prerequisites silently **-WingetUpdatePath** -Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate\` (Recommended to leave default) +Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default) **-DoNotUpdate** Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate is run just after installation. @@ -80,10 +80,13 @@ Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate i Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new version is available on Github. **-UseWhiteList** -Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt" +Use White List instead of Black List. This setting will not create the "excluded_apps.txt" but "included_apps.txt" + +**-ListPath** +Get Black/White List from Path (URL/UNC/Local) (copy/download to Winget-AutoUpdate installation location if external list is newer). **-NoClean** -Keep critical files when installing/uninstalling. This setting will keep "exclude_apps.txt", "include_apps.txt", "mods" and "logs" as they were. +Keep critical files when installing/uninstalling. This setting will keep "excluded_apps.txt", "included_apps.txt", "mods" and "logs" as they were. **-NotificationLevel** Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 68fb824..9585956 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -22,6 +22,9 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto update if new ve .PARAMETER UseWhiteList Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt" +.PARAMETER ListPath +Get Black/White List from Path (URL/UNC/Local) + .PARAMETER Uninstall Remove scheduled tasks and scripts. @@ -46,6 +49,9 @@ Run WAU on metered connection. Default No. .EXAMPLE .\winget-install-and-update.ps1 -Silent -UseWhiteList +.EXAMPLE +.\winget-install-and-update.ps1 -Silent -ListPath https://www.domain.com/WAULists + .EXAMPLE .\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly @@ -58,6 +64,7 @@ Run WAU on metered connection. Default No. param( [Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false, [Parameter(Mandatory = $False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate", + [Parameter(Mandatory = $False)] [Alias('List')] [String] $ListPath, [Parameter(Mandatory = $False)] [Switch] $DoNotUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $RunOnMetered = $false, @@ -192,7 +199,7 @@ function Install-WingetAutoUpdate { } } Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue - + #White List or Black List apps if ($UseWhiteList) { if (!$NoClean) { @@ -200,7 +207,9 @@ function Install-WingetAutoUpdate { Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue } else { - New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + if (!$ListPath){ + New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + } } } elseif (!(Test-Path "$WingetUpdatePath\included_apps.txt")) { @@ -208,7 +217,9 @@ function Install-WingetAutoUpdate { Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue } else { - New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + if (!$ListPath){ + New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null + } } } } @@ -266,6 +277,9 @@ function Install-WingetAutoUpdate { New-ItemProperty $regPath -Name DisplayIcon -Value "C:\Windows\System32\shell32.dll,-16739" -Force | Out-Null New-ItemProperty $regPath -Name DisplayVersion -Value $WAUVersion -Force | Out-Null New-ItemProperty $regPath -Name InstallLocation -Value $WingetUpdatePath -Force | Out-Null + if ($ListPath){ + New-ItemProperty $regPath -Name ListPath -Value $ListPath -Force | Out-Null + } New-ItemProperty $regPath -Name UninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WingetUpdatePath\WAU-Uninstall.ps1`"" -Force | Out-Null New-ItemProperty $regPath -Name QuietUninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WingetUpdatePath\WAU-Uninstall.ps1`"" -Force | Out-Null New-ItemProperty $regPath -Name NoModify -Value 1 -Force | Out-Null diff --git a/Winget-AutoUpdate/functions/Test-ListPath.ps1 b/Winget-AutoUpdate/functions/Test-ListPath.ps1 new file mode 100644 index 0000000..8e2a43e --- /dev/null +++ b/Winget-AutoUpdate/functions/Test-ListPath.ps1 @@ -0,0 +1,58 @@ +#Function to check Black/White List External Path + +function Test-ListPath ($ListPath, $UseWhiteList, $WingetUpdatePath) { + # URL, UNC or Local Path + if ($UseWhiteList){ + $ListType="included_apps.txt" + } + else { + $ListType="excluded_apps.txt" + } + + # Get local and external list paths + $LocalList = -join($WingetUpdatePath, "\", $ListType) + $ExternalList = -join($ListPath, "\", $ListType) + + # Check if a list exists + if (Test-Path "$LocalList") { + $dateLocal = (Get-Item "$LocalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + } + + # If path is URL + if ($ListPath -like "http*"){ + $ExternalList = -join($ListPath, "/", $ListType) + $wc = New-Object System.Net.WebClient + try { + $wc.OpenRead("$ExternalList").Close() | Out-Null + $dateExternal = ([DateTime]$wc.ResponseHeaders['Last-Modified']).ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternal -gt $dateLocal) { + try { + $wc.DownloadFile($ExternalList, $LocalList) + } + catch { + return $False + } + return $true + } + } + catch { + return $False + } + } + # If path is UNC or local + else { + if(Test-Path -Path $ExternalList -PathType leaf){ + $dateExternal = (Get-Item "$ExternalList").LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") + if ($dateExternal -gt $dateLocal) { + try { + Copy-Item $ExternalList -Destination $LocalList -Force + } + catch { + return $False + } + return $true + } + } + } + return $false +} diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index 0d700ef..9f00f44 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -58,6 +58,15 @@ if (Test-Network) { } } + #Get External ListPath + if ($WAUConfig.ListPath) { + Write-Log "WAU uses External Lists" + $NewList = Test-ListPath $WAUConfig.ListPath $WAUConfig.WAU_UseWhiteList $WAUConfig.InstallLocation + if ($NewList) { + Write-Log "Newer List downloaded to local path" + } + } + #Get White or Black list if ($WAUConfig.WAU_UseWhiteList -eq 1) { Write-Log "WAU uses White List config"