wingetautoupdate/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1

52 lines
2.2 KiB
PowerShell
Raw Permalink Normal View History

function Update-WAU {
2024-09-18 13:55:43 +00:00
$OnClickAction = "https://github.com/Romanitho/$($GitHub_Repo)/releases"
$Button1Text = $NotifLocale.local.outputs.output[10].message
#Send available update notification
$Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[2].message -f $WAUCurrentVersion, $WAUAvailableVersion
$MessageType = "info"
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
#Run WAU update
try {
2024-09-13 20:06:18 +00:00
Write-ToLog "Downloading the GitHub Repository version $WAUAvailableVersion" "Cyan"
2024-09-30 21:40:36 +00:00
#Create an unpredictable temp folder for security reasons
$MsiFolder = "$env:temp\WAU_$(Get-Date -Format yyyyMMddHHmmss)"
New-Item -ItemType Directory -Path $MsiFolder
#Download the msi
$MsiFile = Join-Path $MsiFolder "WAU.msi"
2024-09-13 20:06:18 +00:00
Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/releases/download/v$($WAUAvailableVersion)/WAU.msi" -OutFile $MsiFile
2024-09-13 20:06:18 +00:00
#Update WAU
Write-ToLog "Updating WAU..." "Yellow"
2024-09-18 10:57:39 +00:00
Start-Process msiexec.exe -ArgumentList "/i $MsiFile /qn /L*v ""$WorkingDir\logs\WAU-Installer.log"" RUN_WAU=YES INSTALLDIR=""$WorkingDir""" -Wait
#Send success Notif
2024-09-13 20:06:18 +00:00
Write-ToLog "WAU Update completed. Rerunning WAU..." "Green"
$Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion
$MessageType = "success"
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
2024-09-30 21:40:36 +00:00
#Remove temp folder and content
Remove-Item $MsiFolder -Recurse -Force
2024-09-13 20:06:18 +00:00
exit 0
}
catch {
2024-09-13 20:06:18 +00:00
#Send Error Notif
$Title = $NotifLocale.local.outputs.output[4].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[4].message
$MessageType = "error"
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
Write-ToLog "WAU Update failed" "Red"
}
2024-09-13 20:06:18 +00:00
}