Add files via upload

pull/2/head
Romanitho 2022-01-21 16:56:21 +01:00 committed by GitHub
parent 34c3128ae4
commit 42752d02f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 20 deletions

View File

@ -42,7 +42,7 @@ function Write-Log ($LogMsg,$LogColor = "White") {
$Log | out-file -filepath $LogFile -Append $Log | out-file -filepath $LogFile -Append
} }
function Run-NotifTask ($Title,$Message,$MessageType,$Balise) { function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
#Add XML variables #Add XML variables
[xml]$ToastTemplate = @" [xml]$ToastTemplate = @"
@ -65,8 +65,8 @@ function Run-NotifTask ($Title,$Message,$MessageType,$Balise) {
Get-ScheduledTask -TaskName "Winget Update Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue Get-ScheduledTask -TaskName "Winget Update Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
#Wait for notification to display #Wait for notification to display
while ((Get-ScheduledTask -TaskName "Winget Update Notify").State -ne 'Ready') { while ((Get-ScheduledTask -TaskName "Winget Update Notify").State -ne 'Ready') {
echo "Waiting on scheduled task..." Write-Output "Waiting on scheduled task..."
Sleep 3 Start-Sleep 3
} }
} }
@ -83,7 +83,7 @@ function Test-Network {
return return
} }
catch{ catch{
sleep 10 Start-Sleep 10
$timeout += 10 $timeout += 10
Write-Log "Checking internet connection. $($timeout)s." "Yellow" Write-Log "Checking internet connection. $($timeout)s." "Yellow"
} }
@ -94,7 +94,7 @@ function Test-Network {
$Message = $NotifLocal.local.outputs.output[0].message $Message = $NotifLocal.local.outputs.output[0].message
$MessageType = "warning" $MessageType = "warning"
$Balise = "connection" $Balise = "connection"
Run-NotifTask $Title $Message $MessageType $Balise n $Title $Message $MessageType $Balise
} }
} }
return $ping return $ping
@ -115,11 +115,11 @@ function Get-WingetOutdated {
} }
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe"){ elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe"){
#WinGet < 1.17 #WinGet < 1.17
$script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe" | Select -ExpandProperty Path $script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe" | Select-Object -ExpandProperty Path
} }
elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"){ elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"){
#WinGet > 1.17 #WinGet > 1.17
$script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe" | Select -ExpandProperty Path $script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe" | Select-Object -ExpandProperty Path
} }
else{ else{
Write-Log "No Winget installed !" Write-Log "No Winget installed !"
@ -132,11 +132,12 @@ function Get-WingetOutdated {
#Get list of available upgrades on winget format #Get list of available upgrades on winget format
$upgradeResult = & $upgradecmd upgrade | Out-String $upgradeResult = & $upgradecmd upgrade | Out-String
#Start Convertion of winget format to an array #Start Convertion of winget format to an array. Check if "-----" exists
if (!($upgradeResult -match "-----")){ if (!($upgradeResult -match "-----")){
return return
} }
#Split winget output to lines
$lines = $upgradeResult.Split([Environment]::NewLine) $lines = $upgradeResult.Split([Environment]::NewLine)
# Find the line that starts with "------" # Find the line that starts with "------"
@ -197,13 +198,11 @@ $ping = Test-Network
if ($ping){ if ($ping){
#Exclude apps (auto update) #Get exclude apps list
$toSkip = Get-ExcludedApps $toSkip = Get-ExcludedApps
#Get outdated packages #Get outdated Winget packages
Write-Log "Checking available updates..." "yellow" Write-Log "Checking available updates..." "yellow"
#Get outdated apps
$outdated = Get-WingetOutdated $outdated = Get-WingetOutdated
#Log list of app to update #Log list of app to update
@ -224,13 +223,11 @@ if ($ping){
#Send available update notification #Send available update notification
Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan" Write-Log "Updating $($app.Name) from $($app.Version) to $($app.AvailableVersion)..." "Cyan"
#Send Notif
$Title = $NotifLocal.local.outputs.output[2].title -f $($app.Name) $Title = $NotifLocal.local.outputs.output[2].title -f $($app.Name)
$Message = $NotifLocal.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion) $Message = $NotifLocal.local.outputs.output[2].message -f $($app.Version), $($app.AvailableVersion)
$MessageType = "info" $MessageType = "info"
$Balise = $($app.Name) $Balise = $($app.Name)
Run-NotifTask $Title $Message $MessageType $Balise n $Title $Message $MessageType $Balise
#Install update #Install update
$Log = "#--- Winget - $($app.Name) Upgrade Starts ---" $Log = "#--- Winget - $($app.Name) Upgrade Starts ---"
@ -239,7 +236,7 @@ if ($ping){
#Winget upgrade #Winget upgrade
& $upgradecmd upgrade -e --id $($app.Id) --accept-package-agreements --accept-source-agreements -h & $upgradecmd upgrade -e --id $($app.Id) --accept-package-agreements --accept-source-agreements -h
Sleep 3 Start-Sleep 3
$Log = "#--- Winget - $($app.Name) Upgrade Finished ---" $Log = "#--- Winget - $($app.Name) Upgrade Finished ---"
$Log | Write-host -ForegroundColor Gray $Log | Write-host -ForegroundColor Gray
@ -264,7 +261,7 @@ if ($ping){
$Message = $NotifLocal.local.outputs.output[3].message -f $($app.AvailableVersion) $Message = $NotifLocal.local.outputs.output[3].message -f $($app.AvailableVersion)
$MessageType = "success" $MessageType = "success"
$Balise = $($app.Name) $Balise = $($app.Name)
Run-NotifTask $Title $Message $MessageType $Balise n $Title $Message $MessageType $Balise
$InstallOK += 1 $InstallOK += 1
} }
@ -277,7 +274,7 @@ if ($ping){
$Message = $NotifLocal.local.outputs.output[4].message $Message = $NotifLocal.local.outputs.output[4].message
$MessageType = "error" $MessageType = "error"
$Balise = $($app.Name) $Balise = $($app.Name)
Run-NotifTask $Title $Message $MessageType $Balise n $Title $Message $MessageType $Balise
} }
} }
else{ else{
@ -299,6 +296,6 @@ else{
$Message = $NotifLocal.local.outputs.output[1].message $Message = $NotifLocal.local.outputs.output[1].message
$MessageType = "error" $MessageType = "error"
$Balise = "connection" $Balise = "connection"
Run-NotifTask $Title $Message $MessageType $Balise n $Title $Message $MessageType $Balise
} }
Write-Log "End of process!" "Cyan" Write-Log "End of process!" "Cyan"