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" +}