From c304b7060495be1f5b652148afc12f47774f0cf1 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 24 Nov 2023 19:33:35 +0100 Subject: [PATCH 1/4] Mod for AppID-notinstalled --- README.md | 3 ++- Winget-AutoUpdate/functions/Test-Mods.ps1 | 6 +++++- Winget-AutoUpdate/functions/Update-App.ps1 | 8 ++++++-- Winget-AutoUpdate/mods/README.md | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 70af36a..59613d1 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,8 @@ Just put the scripts in question with the **AppID** followed by the `-preinstall >- Runs before upgrade/install: `AppID-preinstall.ps1`
>- Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1`
->- Runs after upgrade/install has been confirmed: `AppID-installed.ps1` +>- Runs after upgrade/install has been confirmed: `AppID-installed.ps1`
+>- Runs after a failed upgrade/install: `AppID-notinstalled.ps1`
The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried).
`AppID-install.ps1` is recommended because it's used in **both** scenarios. diff --git a/Winget-AutoUpdate/functions/Test-Mods.ps1 b/Winget-AutoUpdate/functions/Test-Mods.ps1 index f46d4da..8d0e305 100644 --- a/Winget-AutoUpdate/functions/Test-Mods.ps1 +++ b/Winget-AutoUpdate/functions/Test-Mods.ps1 @@ -8,6 +8,7 @@ function Test-Mods ($app) { $ModsUpgrade = $null $ModsInstall = $null $ModsInstalled = $null + $ModsNotInstalled = $ null $Mods = "$WorkingDir\mods" if (Test-Path "$Mods\$app-*") { @@ -27,8 +28,11 @@ function Test-Mods ($app) { if (Test-Path "$Mods\$app-installed.ps1") { $ModsInstalled = "$Mods\$app-installed.ps1" } + if (Test-Path "$Mods\$app-notinstalled.ps1") { + $ModsNotInstalled = "$Mods\$app-notinstalled.ps1" + } } - return $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled + return $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled, $ModsNotInstalled } diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 86e4236..9296121 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -16,8 +16,8 @@ Function Update-App ($app) { $Balise = $($app.Name) Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Balise $Balise -Button1Action $ReleaseNoteURL -Button1Text $Button1Text - #Check if mods exist for preinstall/install/upgrade - $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled = Test-Mods $($app.Id) + #Check if mods exist for preinstall/override/upgrade/install/installed/notinstalled + $ModsPreInstall, $ModsOverride, $ModsUpgrade, $ModsInstall, $ModsInstalled, $ModsNotInstalled = Test-Mods $($app.Id) #Winget upgrade Write-ToLog "########## WINGET UPGRADE PROCESS STARTS FOR APPLICATION ID '$($App.Id)' ##########" "Gray" @@ -87,6 +87,10 @@ Function Update-App ($app) { & "$ModsInstalled" } } + elseif ($FailedToUpgrade -eq $true -and $ModsNotInstalled) { + Write-ToLog "Modifications for $($app.Id) after a failed upgrade/install are being applied..." "Yellow" + & "$ModsNotInstalled" + } Write-ToLog "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray" diff --git a/Winget-AutoUpdate/mods/README.md b/Winget-AutoUpdate/mods/README.md index d25361a..53be96c 100644 --- a/Winget-AutoUpdate/mods/README.md +++ b/Winget-AutoUpdate/mods/README.md @@ -7,12 +7,13 @@ Custom scripts should be placed here. A script **Template** and **Mods Functions** are included as an **example** to get you started... Scripts that are considered: -**AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1` or `-installed.ps1`. +**AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1`, `-installed.ps1` or `-notinstalled.ps1`. (`-preuninstall.ps1`, `-uninstall.ps1` or `-uninstalled.ps1` - if used together with [Winget-Install](https://github.com/Romanitho/Winget-Install)). > Runs before upgrade/install: `AppID-preinstall.ps1` > Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` > Runs after upgrade/install has been confirmed: `AppID-installed.ps1` +> Runs after a failed upgrade/install: `AppID-notinstalled.ps1` The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried). From b40a578baf380a20a3f1e99acb82e8e1f4774185 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 24 Nov 2023 19:42:20 +0100 Subject: [PATCH 2/4] Text --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 59613d1..94d01d9 100644 --- a/README.md +++ b/README.md @@ -177,12 +177,12 @@ This script executes **if the network is active/any version of Winget is install If **ExitCode** is **1** from `_WAU-mods.ps1` then **Re-run WAU**. ## Custom scripts (Mods feature for Apps) From version 1.8.0, the Mods feature allows you to run additional scripts when upgrading or installing an app. -Just put the scripts in question with the **AppID** followed by the `-preinstall`, `-upgrade`, `-install` or `-installed` suffix in the **mods** folder. +Just put the scripts in question with the **AppID** followed by the `-preinstall`, `-upgrade`, `-install`, `-installed` or `-notinstalled` suffix in the **mods** folder. ->- Runs before upgrade/install: `AppID-preinstall.ps1`
->- Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1`
->- Runs after upgrade/install has been confirmed: `AppID-installed.ps1`
->- Runs after a failed upgrade/install: `AppID-notinstalled.ps1`
+>- Runs before upgrade/install: `AppID-preinstall.ps1` +>- Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` +>- Runs after upgrade/install has been confirmed: `AppID-installed.ps1` +>- Runs after a failed upgrade/install: `AppID-notinstalled.ps1` The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried).
`AppID-install.ps1` is recommended because it's used in **both** scenarios. From 1705b8051861aa4fee490a7e6d8bc43a66280709 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 25 Nov 2023 22:39:37 +0100 Subject: [PATCH 3/4] Final --- README.md | 1 + Winget-AutoUpdate/functions/Test-Mods.ps1 | 7 ++++- Winget-AutoUpdate/functions/Update-App.ps1 | 25 +++++++++++----- Winget-AutoUpdate/mods/README.md | 14 +++++---- .../mods/_WAU-notinstalled-template.ps1 | 30 +++++++++++++++++++ 5 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 diff --git a/README.md b/README.md index 94d01d9..5766a34 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ Just put the scripts in question with the **AppID** followed by the `-preinstall >- Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` >- Runs after upgrade/install has been confirmed: `AppID-installed.ps1` >- Runs after a failed upgrade/install: `AppID-notinstalled.ps1` +>- Runs after a failed upgrade/install: `_WAU-notinstalled.ps1` (any individual `AppID-notinstalled.ps1` overrides this global one) The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried).
`AppID-install.ps1` is recommended because it's used in **both** scenarios. diff --git a/Winget-AutoUpdate/functions/Test-Mods.ps1 b/Winget-AutoUpdate/functions/Test-Mods.ps1 index 8d0e305..5153f53 100644 --- a/Winget-AutoUpdate/functions/Test-Mods.ps1 +++ b/Winget-AutoUpdate/functions/Test-Mods.ps1 @@ -8,9 +8,14 @@ function Test-Mods ($app) { $ModsUpgrade = $null $ModsInstall = $null $ModsInstalled = $null - $ModsNotInstalled = $ null + $ModsNotInstalled = $null $Mods = "$WorkingDir\mods" + + if (Test-Path "$Mods\_WAU-notinstalled.ps1") { + $ModsNotInstalled = "$Mods\_WAU-notinstalled.ps1" + } + if (Test-Path "$Mods\$app-*") { if (Test-Path "$Mods\$app-preinstall.ps1") { $ModsPreInstall = "$Mods\$app-preinstall.ps1" diff --git a/Winget-AutoUpdate/functions/Update-App.ps1 b/Winget-AutoUpdate/functions/Update-App.ps1 index 9296121..b74c803 100644 --- a/Winget-AutoUpdate/functions/Update-App.ps1 +++ b/Winget-AutoUpdate/functions/Update-App.ps1 @@ -81,15 +81,24 @@ Function Update-App ($app) { } } - if ($FailedToUpgrade -eq $false) { - if ($ModsInstalled) { - Write-ToLog "Modifications for $($app.Id) after upgrade/install are being applied..." "Yellow" - & "$ModsInstalled" + switch ($FailedToUpgrade) + { + # Upgrade/install was successful + $false + { + if ($ModsInstalled) { + Write-ToLog "Modifications for $($app.Id) after upgrade/install are being applied..." "Yellow" + & "$ModsInstalled" + } + } + # Upgrade/install was unsuccessful + $true + { + if ($ModsNotInstalled) { + Write-ToLog "Modifications for $($app.Id) after a failed upgrade/install are being applied..." "Yellow" + & "$ModsNotInstalled" + } } - } - elseif ($FailedToUpgrade -eq $true -and $ModsNotInstalled) { - Write-ToLog "Modifications for $($app.Id) after a failed upgrade/install are being applied..." "Yellow" - & "$ModsNotInstalled" } Write-ToLog "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray" diff --git a/Winget-AutoUpdate/mods/README.md b/Winget-AutoUpdate/mods/README.md index 53be96c..ff10a4c 100644 --- a/Winget-AutoUpdate/mods/README.md +++ b/Winget-AutoUpdate/mods/README.md @@ -2,7 +2,7 @@ Custom script should be placed here. A script **Template** `_WAU-mods-template.ps1` is included to get you started. Rename it to `_WAU-mods.ps1` if you want to activate/run it via `Winget-Upgrade.ps1`. -### Pre/During/Post install/uninstall: +### AppID Pre/During/Post install/uninstall: Custom scripts should be placed here. A script **Template** and **Mods Functions** are included as an **example** to get you started... @@ -10,15 +10,19 @@ Scripts that are considered: **AppID**`-preinstall.ps1`, `-upgrade.ps1`, `-install.ps1`, `-installed.ps1` or `-notinstalled.ps1`. (`-preuninstall.ps1`, `-uninstall.ps1` or `-uninstalled.ps1` - if used together with [Winget-Install](https://github.com/Romanitho/Winget-Install)). -> Runs before upgrade/install: `AppID-preinstall.ps1` -> Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` -> Runs after upgrade/install has been confirmed: `AppID-installed.ps1` -> Runs after a failed upgrade/install: `AppID-notinstalled.ps1` +>- Runs before upgrade/install: `AppID-preinstall.ps1` +>- Runs during upgrade/install (before install check): `AppID-upgrade.ps1`/`AppID-install.ps1` +>- Runs after upgrade/install has been confirmed: `AppID-installed.ps1` +>- Runs after a failed upgrade/install: `AppID-notinstalled.ps1` +>- Runs after a failed upgrade/install: `_WAU-notinstalled.ps1` (any individual `AppID-notinstalled.ps1` overrides this global one) The **-install** mod will be used for upgrades too if **-upgrade** doesn't exist (**WAU** first tries `& $Winget upgrade --id` and if the app isn't detected after that `& $Winget install --id` is tried). `AppID-install.ps1` is recommended because it's used in **both** scenarios. +A script **Template** for an all-purpose mod (`_WAU-notinstalled-template.ps1`) is included in which actions can be taken if an upgrade/install fails for any **AppID** (any individual `AppID-notinstalled.ps1` overrides this global one) +Name it `_WAU-notinstalled.ps1` for activation + ### Winget native parameters: Another finess is the **AppID** followed by the `-override` suffix as a **text file** (**.txt**). > Example: diff --git a/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 b/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 new file mode 100644 index 0000000..f7ebb30 --- /dev/null +++ b/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 @@ -0,0 +1,30 @@ +<# An all-purpose mod for doing things +if an AppID upgrade/install in WAU fails +Name it: +"$Mods\_WAU-notinstalled.ps1" + +This all-purpose mod will be overridden by any specific: +"$Mods\AppID-notinstalled.ps1" +#> + +<# FUNCTIONS #> +. $PSScriptRoot\_Mods-Functions.ps1 + +<# ARRAYS/VARIABLES #> + + +<# MAIN #> +if ($($app.Id) -eq "Microsoft.SQLServerManagementStudio") { + $ConfirmInstall = Confirm-Installation $($app.Id) $($app.AvailableVersion) + if ($ConfirmInstall -ne $true) { + try { + Write-ToLog "...succesfully done something" "Green" + } + catch { + Write-ToLog "...failed to do something" "Red" + } + } +} +else { + Write-ToLog "...nothing defined for $($app.Id)" "Yellow" +} From e56f77768d31badd42074e22438ca840d1d804f2 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 26 Nov 2023 11:07:47 +0100 Subject: [PATCH 4/4] small template change --- Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 b/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 index f7ebb30..207eec5 100644 --- a/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 +++ b/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 @@ -15,8 +15,7 @@ This all-purpose mod will be overridden by any specific: <# MAIN #> if ($($app.Id) -eq "Microsoft.SQLServerManagementStudio") { - $ConfirmInstall = Confirm-Installation $($app.Id) $($app.AvailableVersion) - if ($ConfirmInstall -ne $true) { + if ($ConfirmInstall -eq $false) { try { Write-ToLog "...succesfully done something" "Green" }