From 0795ff4936bc32de342082d0222cd0400f6bf347 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:40:13 +0100 Subject: [PATCH 1/4] Changes to be used with Intune @KnifMelti I made few adjustments to allow mods to be put inside Intunewim package. This way, we can run install command with `%programdata%\Winget-AutoUpdate\Winget-Install.ps1` and it should copy mods from the intunewim to the WAU mod location --- .../WAU/Winget-AutoUpdate/Winget-Install.ps1 | 73 +++++++++---------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 index 2ed473c..41c4aff 100644 --- a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 +++ b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 @@ -75,26 +75,28 @@ function Confirm-Exist ($AppID) { #Check if install modifications exist in "mods" directory function Test-ModsInstall ($AppID) { - if (Test-Path "$PSScriptRoot\mods\$AppID-preinstall.ps1") { - $ModsPreInstall = "$PSScriptRoot\mods\$AppID-preinstall.ps1" + #Check current location + if (Test-Path ".\mods\$AppID-preinstall.ps1") { + $ModsPreInstall = ".\mods\$AppID-preinstall.ps1" } + #Else, check in WAU mods elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-preinstall.ps1")) { $ModsPreInstall = "$WAUInstallLocation\mods\$AppID-preinstall.ps1" } - if (Test-Path "$PSScriptRoot\mods\$AppID-install.ps1") { - $ModsInstall = "$PSScriptRoot\mods\$AppID-install.ps1" + if (Test-Path ".\mods\$AppID-install.ps1") { + $ModsInstall = ".\mods\$AppID-install.ps1" } elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-install.ps1")) { $ModsInstall = "$WAUInstallLocation\mods\$AppID-install.ps1" } - if (Test-Path "$PSScriptRoot\mods\$AppID-installed-once.ps1") { - $ModsInstalledOnce = "$PSScriptRoot\mods\$AppID-installed-once.ps1" + if (Test-Path ".\mods\$AppID-installed-once.ps1") { + $ModsInstalledOnce = ".\mods\$AppID-installed-once.ps1" } - if (Test-Path "$PSScriptRoot\mods\$AppID-installed.ps1") { - $ModsInstalled = "$PSScriptRoot\mods\$AppID-installed.ps1" + if (Test-Path ".\mods\$AppID-installed.ps1") { + $ModsInstalled = ".\mods\$AppID-installed.ps1" } elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-installed.ps1")) { $ModsInstalled = "$WAUInstallLocation\mods\$AppID-installed.ps1" @@ -105,22 +107,24 @@ function Test-ModsInstall ($AppID) { #Check if uninstall modifications exist in "mods" directory function Test-ModsUninstall ($AppID) { - if (Test-Path "$PSScriptRoot\mods\$AppID-preuninstall.ps1") { - $ModsPreUninstall = "$PSScriptRoot\mods\$AppID-preuninstall.ps1" + #Check current location + if (Test-Path ".\mods\$AppID-preuninstall.ps1") { + $ModsPreUninstall = ".\mods\$AppID-preuninstall.ps1" } + #Else, check in WAU mods elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-preuninstall.ps1")) { $ModsPreUninstall = "$WAUInstallLocation\mods\$AppID-preuninstall.ps1" } - if (Test-Path "$PSScriptRoot\mods\$AppID-uninstall.ps1") { - $ModsUninstall = "$PSScriptRoot\mods\$AppID-uninstall.ps1" + if (Test-Path ".\mods\$AppID-uninstall.ps1") { + $ModsUninstall = ".\mods\$AppID-uninstall.ps1" } elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-uninstall.ps1")) { $ModsUninstall = "$WAUInstallLocation\mods\$AppID-uninstall.ps1" } - if (Test-Path "$PSScriptRoot\mods\$AppID-uninstalled.ps1") { - $ModsUninstalled = "$PSScriptRoot\mods\$AppID-uninstalled.ps1" + if (Test-Path ".\mods\$AppID-uninstalled.ps1") { + $ModsUninstalled = ".\mods\$AppID-uninstalled.ps1" } elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-uninstalled.ps1")) { $ModsUninstalled = "$WAUInstallLocation\mods\$AppID-uninstalled.ps1" @@ -168,8 +172,14 @@ function Install-App ($AppID, $AppArgs) { } #Add mods if deployed from Winget-Install - if ((Test-Path "$PSScriptRoot\mods\$AppID-preinstall.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-upgrade.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-install.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-installed.ps1")) { - Add-WAUMods $AppID + if ((Test-Path ".\mods\$AppID-preinstall.ps1") -or (Test-Path ".\mods\$AppID-upgrade.ps1") -or (Test-Path ".\mods\$AppID-install.ps1") -or (Test-Path ".\mods\$AppID-installed.ps1")) { + #Check if WAU default install path exists + $Mods = "$WAUInstallLocation\mods" + if (Test-Path $Mods) { + #Add mods + Write-ToLog "-> Add modifications for $AppID to WAU 'mods'" + Copy-Item ".\mods\$AppID-*" -Destination "$Mods" -Exclude "*installed-once*", "*uninstall*" -Force + } } #Add to WAU White List if set @@ -221,7 +231,13 @@ function Uninstall-App ($AppID, $AppArgs) { #Remove mods if deployed from Winget-Install if ((Test-Path "$PSScriptRoot\mods\$AppID-preinstall.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-upgrade.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-install.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-installed.ps1")) { - Remove-WAUMods $AppID + #Check if WAU default install path exists + $Mods = "$WAUInstallLocation\mods" + if (Test-Path "$Mods\$AppID*") { + Write-ToLog "-> Remove $AppID modifications from WAU 'mods'" + #Remove mods + Remove-Item -Path "$Mods\$AppID-*" -Exclude "*uninstall*" -Force + } } #Remove from WAU White List if set @@ -264,29 +280,6 @@ function Remove-WAUWhiteList ($AppID) { } } -#Function to Add Mods to WAU "mods" -function Add-WAUMods ($AppID) { - #Check if WAU default install path exists - $Mods = "$WAUInstallLocation\mods" - if (Test-Path $Mods) { - #Add mods - Write-ToLog "-> Add modifications for $AppID to WAU 'mods'" - Copy-Item "$PSScriptRoot\mods\$AppID-*" -Destination "$Mods" -Exclude "*installed-once*", "*uninstall*" -Force - } -} - -#Function to Remove Mods from WAU "mods" -function Remove-WAUMods ($AppID) { - #Check if WAU default install path exists - $Mods = "$WAUInstallLocation\mods" - if (Test-Path "$Mods\$AppID*") { - Write-ToLog "-> Remove $AppID modifications from WAU 'mods'" - #Remove mods - Remove-Item -Path "$Mods\$AppID-*" -Exclude "*uninstall*" -Force - } -} - - <# MAIN #> #If running as a 32-bit process on an x64 system, re-launch as a 64-bit process From 7487530a5eb49263ee6e939a521f9916afd0e2b7 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:44:15 +0100 Subject: [PATCH 2/4] simplify --- Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 index 41c4aff..7327805 100644 --- a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 +++ b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 @@ -80,14 +80,14 @@ function Test-ModsInstall ($AppID) { $ModsPreInstall = ".\mods\$AppID-preinstall.ps1" } #Else, check in WAU mods - elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-preinstall.ps1")) { + elseif (Test-Path "$WAUInstallLocation\mods\$AppID-preinstall.ps1") { $ModsPreInstall = "$WAUInstallLocation\mods\$AppID-preinstall.ps1" } if (Test-Path ".\mods\$AppID-install.ps1") { $ModsInstall = ".\mods\$AppID-install.ps1" } - elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-install.ps1")) { + elseif (Test-Path "$WAUInstallLocation\mods\$AppID-install.ps1") { $ModsInstall = "$WAUInstallLocation\mods\$AppID-install.ps1" } @@ -98,7 +98,7 @@ function Test-ModsInstall ($AppID) { if (Test-Path ".\mods\$AppID-installed.ps1") { $ModsInstalled = ".\mods\$AppID-installed.ps1" } - elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-installed.ps1")) { + elseif (Test-Path "$WAUInstallLocation\mods\$AppID-installed.ps1") { $ModsInstalled = "$WAUInstallLocation\mods\$AppID-installed.ps1" } @@ -112,21 +112,21 @@ function Test-ModsUninstall ($AppID) { $ModsPreUninstall = ".\mods\$AppID-preuninstall.ps1" } #Else, check in WAU mods - elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-preuninstall.ps1")) { + elseif (Test-Path "$WAUInstallLocation\mods\$AppID-preuninstall.ps1") { $ModsPreUninstall = "$WAUInstallLocation\mods\$AppID-preuninstall.ps1" } if (Test-Path ".\mods\$AppID-uninstall.ps1") { $ModsUninstall = ".\mods\$AppID-uninstall.ps1" } - elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-uninstall.ps1")) { + elseif (Test-Path "$WAUInstallLocation\mods\$AppID-uninstall.ps1") { $ModsUninstall = "$WAUInstallLocation\mods\$AppID-uninstall.ps1" } if (Test-Path ".\mods\$AppID-uninstalled.ps1") { $ModsUninstalled = ".\mods\$AppID-uninstalled.ps1" } - elseif (($WAUInstallLocation) -and (Test-Path "$WAUInstallLocation\mods\$AppID-uninstalled.ps1")) { + elseif (Test-Path "$WAUInstallLocation\mods\$AppID-uninstalled.ps1") { $ModsUninstalled = "$WAUInstallLocation\mods\$AppID-uninstalled.ps1" } From adc9da6882db9b9940bd8c8ae8e9cd18daf78534 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:49:59 +0100 Subject: [PATCH 3/4] Update Winget-Install.ps1 --- Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 index 7327805..b5be702 100644 --- a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 +++ b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 @@ -230,7 +230,7 @@ function Uninstall-App ($AppID, $AppArgs) { } #Remove mods if deployed from Winget-Install - if ((Test-Path "$PSScriptRoot\mods\$AppID-preinstall.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-upgrade.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-install.ps1") -or (Test-Path "$PSScriptRoot\mods\$AppID-installed.ps1")) { + if ((Test-Path ".\mods\$AppID-preinstall.ps1") -or (Test-Path ".\mods\$AppID-upgrade.ps1") -or (Test-Path ".\mods\$AppID-install.ps1") -or (Test-Path ".\mods\$AppID-installed.ps1")) { #Check if WAU default install path exists $Mods = "$WAUInstallLocation\mods" if (Test-Path "$Mods\$AppID*") { From 48326dc4823bcf963be63124f5ec6695c3778f94 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:39:13 +0100 Subject: [PATCH 4/4] Update Winget-Install.ps1 --- Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 index b5be702..e764292 100644 --- a/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 +++ b/Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1 @@ -172,7 +172,7 @@ function Install-App ($AppID, $AppArgs) { } #Add mods if deployed from Winget-Install - if ((Test-Path ".\mods\$AppID-preinstall.ps1") -or (Test-Path ".\mods\$AppID-upgrade.ps1") -or (Test-Path ".\mods\$AppID-install.ps1") -or (Test-Path ".\mods\$AppID-installed.ps1")) { + if (Test-Path ".\mods\$AppID-*") { #Check if WAU default install path exists $Mods = "$WAUInstallLocation\mods" if (Test-Path $Mods) { @@ -230,7 +230,7 @@ function Uninstall-App ($AppID, $AppArgs) { } #Remove mods if deployed from Winget-Install - if ((Test-Path ".\mods\$AppID-preinstall.ps1") -or (Test-Path ".\mods\$AppID-upgrade.ps1") -or (Test-Path ".\mods\$AppID-install.ps1") -or (Test-Path ".\mods\$AppID-installed.ps1")) { + if (Test-Path ".\mods\$AppID-*") { #Check if WAU default install path exists $Mods = "$WAUInstallLocation\mods" if (Test-Path "$Mods\$AppID*") {