From d5dd6ef76f97de8cd89e7e706689cb1f47dbd5b1 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 22 Feb 2022 18:08:32 +0100 Subject: [PATCH 1/3] Retry installation if "upgrade" failed #11 --- Winget-AutoUpdate/winget-upgrade.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index 1246b3f..a7bf8fd 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -9,7 +9,7 @@ function Init { $Log | Write-host try{ #Logs initialisation - [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 + [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $LogPath = "$WorkingDir\logs" if (!(Test-Path $LogPath)){ New-Item -ItemType Directory -Force -Path $LogPath @@ -269,9 +269,15 @@ if (Test-Network){ Start-NotifTask $Title $Message $MessageType $Balise #Winget upgrade - Write-Log "------ Winget - $($app.Name) Upgrade Starts ------" "Gray" - & $upgradecmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append - Write-Log "----- Winget - $($app.Name) Upgrade Finished -----" "Gray" + Write-Log "########## WINGET PROCESS STARTS FOR '$($app.Name)' ##########" "Gray" + & $UpgradeCmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append + $checkoutdated = Get-WingetOutdated + foreach ($checkapp in $checkoutdated){ + if ($($checkapp.Id) -eq $($app.Id)) { + $FailedToUpgrade = $true + } + } + Write-Log "########## WINGET PROCESS FINISHED FOR '$($app.Name)' ##########" "Gray" #Check installed version $checkoutdated = Get-WingetOutdated From 4fee69a5d999334ef5b96e74e70fd3713e95b4a1 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 22 Feb 2022 18:29:48 +0100 Subject: [PATCH 2/3] fix incorrect commit --- Winget-AutoUpdate/winget-upgrade.ps1 | 37 +++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index a7bf8fd..1b847ac 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -269,24 +269,27 @@ if (Test-Network){ Start-NotifTask $Title $Message $MessageType $Balise #Winget upgrade - Write-Log "########## WINGET PROCESS STARTS FOR '$($app.Name)' ##########" "Gray" - & $UpgradeCmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append - $checkoutdated = Get-WingetOutdated - foreach ($checkapp in $checkoutdated){ - if ($($checkapp.Id) -eq $($app.Id)) { - $FailedToUpgrade = $true + Write-Log "########## WINGET UPGRADE PROCESS STARTS FOR '$($app.Name)' ##########" "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-WingetOutdated + $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-WingetOutdated + foreach ($CheckApp2 in $CheckOutdated2){ + if ($($CheckApp2.Id) -eq $($app.Id)) { + $FailedToUpgrade = $true + } + } + } } - } - Write-Log "########## WINGET PROCESS FINISHED FOR '$($app.Name)' ##########" "Gray" - - #Check installed version - $checkoutdated = Get-WingetOutdated - $FailedToUpgrade = $false - foreach ($checkapp in $checkoutdated){ - if ($($checkapp.Id) -eq $($app.Id)) { - $FailedToUpgrade = $true - } - } + Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR '$($app.Name)' ##########" "Gray" #Notify installation if ($FailedToUpgrade -eq $false){ From b899e9ed2ef70231195dd621b8d1fd4a6a68a027 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 22 Feb 2022 18:33:09 +0100 Subject: [PATCH 3/3] Update winget-upgrade.ps1 --- Winget-AutoUpdate/winget-upgrade.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index 1b847ac..97af253 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -9,7 +9,7 @@ function Init { $Log | Write-host try{ #Logs initialisation - [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 + [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $LogPath = "$WorkingDir\logs" if (!(Test-Path $LogPath)){ New-Item -ItemType Directory -Force -Path $LogPath