diff --git a/README.md b/README.md index 70af36a..5766a34 100644 --- a/README.md +++ b/README.md @@ -177,11 +177,13 @@ 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 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. diff --git a/Winget-AutoUpdate/functions/Test-Mods.ps1 b/Winget-AutoUpdate/functions/Test-Mods.ps1 index f46d4da..5153f53 100644 --- a/Winget-AutoUpdate/functions/Test-Mods.ps1 +++ b/Winget-AutoUpdate/functions/Test-Mods.ps1 @@ -8,8 +8,14 @@ function Test-Mods ($app) { $ModsUpgrade = $null $ModsInstall = $null $ModsInstalled = $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" @@ -27,8 +33,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..b74c803 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" @@ -81,10 +81,23 @@ 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" + } } } diff --git a/Winget-AutoUpdate/mods/README.md b/Winget-AutoUpdate/mods/README.md index d25361a..ff10a4c 100644 --- a/Winget-AutoUpdate/mods/README.md +++ b/Winget-AutoUpdate/mods/README.md @@ -2,22 +2,27 @@ 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... 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 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..207eec5 --- /dev/null +++ b/Winget-AutoUpdate/mods/_WAU-notinstalled-template.ps1 @@ -0,0 +1,29 @@ +<# 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") { + if ($ConfirmInstall -eq $false) { + try { + Write-ToLog "...succesfully done something" "Green" + } + catch { + Write-ToLog "...failed to do something" "Red" + } + } +} +else { + Write-ToLog "...nothing defined for $($app.Id)" "Yellow" +}