Cleanning
parent
a57f7d838a
commit
94ca44bc49
|
@ -1,6 +1,6 @@
|
|||
#Get locale file for Notification.
|
||||
|
||||
Function Get-NotifLocal {
|
||||
Function Get-NotifLocale {
|
||||
#Get OS locale
|
||||
$OSLocale = (Get-Culture).Parent
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
function Get-WAUAvailableVersion{
|
||||
#Get Github latest version
|
||||
$WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
|
||||
$Script:WAULatestVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v","")
|
||||
return [version]$WAULatestVersion
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
function Get-WAUCurrentVersion{
|
||||
#Get current installed version
|
||||
[xml]$About = Get-Content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||
$Script:WAUCurrentVersion = $About.app.version
|
||||
return [version]$WAUCurrentVersion
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
function Get-WAUUpdateStatus{
|
||||
#Get AutoUpdate status
|
||||
[xml]$UpdateStatus = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||
if ($true -eq $UpdateStatus.app.WAUautoupdate){
|
||||
Write-Log "WAU AutoUpdate is Enabled" "Green"
|
||||
return $true
|
||||
}
|
||||
else{
|
||||
Write-Log "WAU AutoUpdate is Disabled" "Grey"
|
||||
return $false
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
function Get-WingetOutdated {
|
||||
function Get-WingetOutdatedApps {
|
||||
class Software {
|
||||
[string]$Name
|
||||
[string]$Id
|
|
@ -1,32 +0,0 @@
|
|||
function Start-WAUUpdateCheck{
|
||||
#Get AutoUpdate status
|
||||
[xml]$UpdateStatus = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||
$AutoUpdateStatus = $UpdateStatus.app.WAUautoupdate
|
||||
|
||||
#Get current installed version
|
||||
[xml]$About = Get-Content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||
[version]$Script:CurrentVersion = $About.app.version
|
||||
|
||||
#Check if AutoUpdate is enabled
|
||||
if ($AutoUpdateStatus -eq $false){
|
||||
Write-Log "WAU Current version: $CurrentVersion. AutoUpdate is disabled." "Cyan"
|
||||
return $false
|
||||
}
|
||||
#If enabled, check online available version
|
||||
else{
|
||||
#Get Github latest version
|
||||
$WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
|
||||
$LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
|
||||
[version]$AvailableVersion = $LatestVersion.Replace("v","")
|
||||
|
||||
#If newer version is avalable, return $True
|
||||
if ($AvailableVersion -gt $CurrentVersion){
|
||||
Write-Log "WAU Current version: $CurrentVersion. Version $AvailableVersion is available." "Yellow"
|
||||
return $true
|
||||
}
|
||||
else{
|
||||
Write-Log "WAU Current version: $CurrentVersion. Up to date." "Green"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
function Test-Network {
|
||||
#init
|
||||
#Init
|
||||
$timeout = 0
|
||||
|
||||
#test connectivity during 30 min then timeout
|
||||
#Test connectivity during 30 min then timeout
|
||||
Write-Log "Checking internet connection..." "Yellow"
|
||||
While ($timeout -lt 1800){
|
||||
try{
|
||||
Invoke-RestMethod -Uri "https://api.github.com/zen"
|
||||
$TestNetwork = Test-NetConnection 8.8.8.8 -Port 443 -InformationLevel Quiet
|
||||
if ($TestNetwork){
|
||||
Write-Log "Connected !" "Green"
|
||||
return $true
|
||||
}
|
||||
catch{
|
||||
else{
|
||||
Start-Sleep 10
|
||||
$timeout += 10
|
||||
Write-Log "Checking internet connection. $($timeout)s." "Yellow"
|
||||
#Send Notif if no connection for 5 min
|
||||
|
||||
#Send Warning Notif if no connection for 5 min
|
||||
if ($timeout -eq 300){
|
||||
Write-Log "Notify 'No connection' sent." "Yellow"
|
||||
$Title = $NotifLocale.local.outputs.output[0].title
|
||||
|
@ -25,8 +25,9 @@ function Test-Network {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Send Timeout Notif if no connection for 30 min
|
||||
Write-Log "Timeout. No internet connection !" "Red"
|
||||
#Send Notif if no connection for 30 min
|
||||
$Title = $NotifLocale.local.outputs.output[1].title
|
||||
$Message = $NotifLocale.local.outputs.output[1].message
|
||||
$MessageType = "error"
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
|
||||
function Update-WAU{
|
||||
#Get WAU Github latest version
|
||||
$WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
|
||||
$LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
|
||||
|
||||
function Update-WAU ($VersionToUpdate){
|
||||
#Send available update notification
|
||||
$Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate"
|
||||
$Message = $NotifLocale.local.outputs.output[2].message -f $CurrentVersion, $LatestVersion.Replace("v","")
|
||||
|
@ -18,16 +14,16 @@ function Update-WAU{
|
|||
New-Item $ZipFile -ItemType File -Force | Out-Null
|
||||
|
||||
#Download the zip
|
||||
Write-Log "Starting downloading the GitHub Repository"
|
||||
Invoke-RestMethod -Uri "https://api.github.com/repos/Romanitho/Winget-AutoUpdate/zipball/$($LatestVersion)" -OutFile $ZipFile
|
||||
Write-Log 'Download finished'
|
||||
Write-Log "Starting downloading the GitHub Repository version $VersionToUpdate"
|
||||
Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/archive/refs/tags/v$($VersionToUpdate).zip/" -OutFile $ZipFile
|
||||
Write-Log "Download finished" "Green"
|
||||
|
||||
#Extract Zip File
|
||||
Write-Log "Starting unzipping the WAU GitHub Repository"
|
||||
$location = "$WorkingDir\WAU_update"
|
||||
Expand-Archive -Path $ZipFile -DestinationPath $location -Force
|
||||
Get-ChildItem -Path $location -Recurse | Unblock-File
|
||||
Write-Log "Unzip finished"
|
||||
Write-Log "Unzip finished" "Green"
|
||||
$TempPath = (Resolve-Path "$location\Romanitho-Winget-AutoUpdate*\Winget-AutoUpdate\").Path
|
||||
Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force
|
||||
|
||||
|
@ -37,9 +33,9 @@ function Update-WAU{
|
|||
#Remove update folder
|
||||
Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue
|
||||
|
||||
#Set new version to conf.xml
|
||||
#Set new version to about.xml
|
||||
[xml]$XMLconf = Get-content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
|
||||
$XMLconf.app.version = $LatestVersion.Replace("v","")
|
||||
$XMLconf.app.version = $VersionToUpdate
|
||||
$XMLconf.Save("$WorkingDir\config\about.xml")
|
||||
|
||||
#Send success Notif
|
||||
|
@ -51,7 +47,7 @@ function Update-WAU{
|
|||
|
||||
#Rerun with newer version
|
||||
Write-Log "Re-run WAU"
|
||||
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade`""
|
||||
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade`""
|
||||
exit
|
||||
}
|
||||
catch{
|
||||
|
|
|
@ -5,21 +5,30 @@ $Script:WorkingDir = $PSScriptRoot
|
|||
#Get Functions
|
||||
Get-ChildItem "$WorkingDir\functions" | ForEach-Object {. $_.FullName}
|
||||
|
||||
|
||||
<# MAIN #>
|
||||
|
||||
#Run log initialisation function
|
||||
Start-Init
|
||||
|
||||
#Get Notif Locale function
|
||||
Get-NotifLocal
|
||||
Get-NotifLocale
|
||||
|
||||
#Check network connectivity
|
||||
if (Test-Network){
|
||||
#Check if WAU is up to date
|
||||
$CheckWAUupdate = Start-WAUUpdateCheck
|
||||
#If AutoUpdate is enabled and Update is avalaible, then run WAU update
|
||||
if ($CheckWAUupdate){
|
||||
Update-WAU
|
||||
#Check if WAU update feature is enabled
|
||||
$WAUAutoUpdateEnabled = Get-WAUUpdateStatus
|
||||
#If yes then check WAU update
|
||||
if ($WAUAutoUpdateEnabled){
|
||||
#Get Current Version
|
||||
$WAUCurrentVersion = Get-WAUCurrentVersion
|
||||
#Get Available Version
|
||||
$WAUAvailableVersion = Get-WAUAvailableVersion
|
||||
#Compare
|
||||
if ($WAUAvailableVersion -gt $WAUCurrentVersion){
|
||||
#If new version is available, update it
|
||||
Update-WAU $WAUAvailableVersion
|
||||
}
|
||||
}
|
||||
|
||||
#Get exclude apps list
|
||||
|
@ -27,7 +36,7 @@ if (Test-Network){
|
|||
|
||||
#Get outdated Winget packages
|
||||
Write-Log "Checking available updates..." "yellow"
|
||||
$outdated = Get-WingetOutdated
|
||||
$outdated = Get-WingetOutdatedApps
|
||||
|
||||
#Log list of app to update
|
||||
foreach ($app in $outdated){
|
||||
|
@ -37,7 +46,7 @@ if (Test-Network){
|
|||
$Log | out-file -filepath $LogFile -Append
|
||||
}
|
||||
|
||||
#Count good update installs
|
||||
#Count good update installations
|
||||
$InstallOK = 0
|
||||
|
||||
#For each app, notify and update
|
||||
|
@ -59,14 +68,14 @@ if (Test-Network){
|
|||
& $UpgradeCmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
||||
|
||||
#Check if application updated properly
|
||||
$CheckOutdated = Get-WingetOutdated
|
||||
$CheckOutdated = Get-WingetOutdatedApps
|
||||
$FailedToUpgrade = $false
|
||||
foreach ($CheckApp in $CheckOutdated){
|
||||
if ($($CheckApp.Id) -eq $($app.Id)) {
|
||||
#If app failed to upgrade, run Install command
|
||||
& $upgradecmd install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
||||
#Check if application installed properly
|
||||
$CheckOutdated2 = Get-WingetOutdated
|
||||
$CheckOutdated2 = Get-WingetOutdatedApps
|
||||
foreach ($CheckApp2 in $CheckOutdated2){
|
||||
if ($($CheckApp2.Id) -eq $($app.Id)) {
|
||||
$FailedToUpgrade = $true
|
||||
|
|
Loading…
Reference in New Issue