Merge pull request #166 from KnifMelti/knifdev

Knifdev - get external lists to local (UNC/Web/Local) path
pull/169/head
Romain 2022-09-24 10:53:53 +02:00 committed by GitHub
commit 3b2a54983e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 6 deletions

View File

@ -71,7 +71,7 @@ You can run the `winget-install-and-update.ps1` script with parameters :
Install Winget-AutoUpdate and prerequisites silently Install Winget-AutoUpdate and prerequisites silently
**-WingetUpdatePath** **-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** **-DoNotUpdate**
Do not run Winget-AutoUpdate after installation. By default, Winget-AutoUpdate is run just after installation. 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. Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new version is available on Github.
**-UseWhiteList** **-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** **-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** **-NotificationLevel**
Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup).

View File

@ -22,6 +22,9 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto update if new ve
.PARAMETER UseWhiteList .PARAMETER 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 "exclude_apps.txt" but "include_apps.txt"
.PARAMETER ListPath
Get Black/White List from Path (URL/UNC/Local)
.PARAMETER Uninstall .PARAMETER Uninstall
Remove scheduled tasks and scripts. Remove scheduled tasks and scripts.
@ -46,6 +49,9 @@ Run WAU on metered connection. Default No.
.EXAMPLE .EXAMPLE
.\winget-install-and-update.ps1 -Silent -UseWhiteList .\winget-install-and-update.ps1 -Silent -UseWhiteList
.EXAMPLE
.\winget-install-and-update.ps1 -Silent -ListPath https://www.domain.com/WAULists
.EXAMPLE .EXAMPLE
.\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly .\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly
@ -58,6 +64,7 @@ Run WAU on metered connection. Default No.
param( param(
[Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false, [Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false,
[Parameter(Mandatory = $False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate", [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] $DoNotUpdate = $false,
[Parameter(Mandatory = $False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory = $False)] [Switch] $DisableWAUAutoUpdate = $false,
[Parameter(Mandatory = $False)] [Switch] $RunOnMetered = $false, [Parameter(Mandatory = $False)] [Switch] $RunOnMetered = $false,
@ -200,18 +207,22 @@ function Install-WingetAutoUpdate {
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
} }
else { else {
if (!$ListPath){
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null
} }
} }
}
elseif (!(Test-Path "$WingetUpdatePath\included_apps.txt")) { elseif (!(Test-Path "$WingetUpdatePath\included_apps.txt")) {
if ((Test-Path "$PSScriptRoot\included_apps.txt")) { if ((Test-Path "$PSScriptRoot\included_apps.txt")) {
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
} }
else { else {
if (!$ListPath){
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null
} }
} }
} }
}
else { else {
if (!$NoClean) { if (!$NoClean) {
Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue Copy-Item -Path "$PSScriptRoot\excluded_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
@ -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 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 DisplayVersion -Value $WAUVersion -Force | Out-Null
New-ItemProperty $regPath -Name InstallLocation -Value $WingetUpdatePath -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 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 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 New-ItemProperty $regPath -Name NoModify -Value 1 -Force | Out-Null

View File

@ -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
}

View File

@ -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 #Get White or Black list
if ($WAUConfig.WAU_UseWhiteList -eq 1) { if ($WAUConfig.WAU_UseWhiteList -eq 1) {
Write-Log "WAU uses White List config" Write-Log "WAU uses White List config"