Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Functions #419

Merged
merged 10 commits into from
Oct 14, 2023
Merged

Better Functions #419

merged 10 commits into from
Oct 14, 2023

Conversation

KnifMelti
Copy link
Contributor

@KnifMelti KnifMelti commented Oct 11, 2023

Proposed Changes

Update-Winget as an external Function, Get-StoreApps changed to Update-StoreApps
Winget-Autoupdate-Install and Invoke-PostUpdateActions now using Update-Winget

@KnifMelti KnifMelti temporarily deployed to megalinter October 11, 2023 20:26 — with GitHub Actions Inactive
@KnifMelti KnifMelti temporarily deployed to megalinter October 11, 2023 20:45 — with GitHub Actions Inactive
@KnifMelti KnifMelti temporarily deployed to megalinter October 11, 2023 20:49 — with GitHub Actions Inactive
@KnifMelti KnifMelti marked this pull request as ready for review October 11, 2023 20:53
@KnifMelti KnifMelti marked this pull request as draft October 11, 2023 22:20
@KnifMelti KnifMelti temporarily deployed to megalinter October 12, 2023 02:21 — with GitHub Actions Inactive
@KnifMelti KnifMelti temporarily deployed to megalinter October 12, 2023 02:40 — with GitHub Actions Inactive
@KnifMelti KnifMelti marked this pull request as ready for review October 12, 2023 03:04
@KnifMelti KnifMelti marked this pull request as draft October 12, 2023 04:02
@KnifMelti KnifMelti temporarily deployed to megalinter October 12, 2023 17:42 — with GitHub Actions Inactive
@KnifMelti KnifMelti marked this pull request as ready for review October 12, 2023 17:46
@KnifMelti KnifMelti temporarily deployed to megalinter October 13, 2023 01:16 — with GitHub Actions Inactive
@KnifMelti
Copy link
Contributor Author

KnifMelti commented Oct 13, 2023

Example of _WAU-mods.ps1:

<# #Mods for WAU (if Network is active/any WinGet is installed/running as SYSTEM)
Winget-Upgrade.ps1 calls this script with the code:
[Write-ToLog "Running Mods for WAU..." "Yellow"
& "$Mods\_WAU-mods.ps1"]
Make sure your Functions have unique names!
Exit 1 to Re-run WAU from this script!
#>

<# FUNCTIONS #>



<# ARRAYS/VARIABLES #>

$WinGetAvailableVersion = Get-WinGetAvailableVersion
$WinGetInstalledVersion = & $Winget --version
$WinGetInstalledVersion = $WinGetInstalledVersion.Replace("v", "")

<# MAIN #>

#Check for GPO changes
$ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue
if ($ActivateGPOManagement -eq 1) {
    Write-ToLog "-> Evaluating GPO settings" "Yellow"
    $PoliciesTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-Policies' -ErrorAction SilentlyContinue
    $null = $PoliciesTask | Start-ScheduledTask -ErrorAction SilentlyContinue
}

#Update to the latest WinGet version but exclude -preview versions
If (!($WinGetAvailableVersion -match "-pre") -and ($WinGetAvailableVersion -gt $WinGetInstalledVersion)) {
    Write-ToLog "-> WinGet is not up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available:" "Red"
    Update-WinGet $WinGetAvailableVersion $($WAUConfig.InstallLocation) $true

    #Exit and Re-run WAU
    Exit 1
}
elseif ($WinGetAvailableVersion -match "-pre") {
    Write-ToLog "-> WinGet is probably up to date (v$WinGetInstalledVersion) - v$WinGetAvailableVersion is available but only as a Pre-release" "yellow"
    Update-StoreApps $true
}
else {
    Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "green"
}


Write-ToLog "...all done!" "Green"
Exit 0

@KnifMelti KnifMelti temporarily deployed to megalinter October 14, 2023 08:29 — with GitHub Actions Inactive
@Romanitho
Copy link
Owner

seems really good. Nice rework.

@Romanitho Romanitho merged commit 11f3811 into Romanitho:main Oct 14, 2023
3 checks passed
@Romanitho
Copy link
Owner

MegaLinter spotted other thing to optimise 😅


Processing linters on [2] parallel cores…
✅ Linted [COPYPASTE] files with [jscpd]: Found 9 non blocking error(s) - (2.63s) (expand for details)
  - Using [jscpd v3.5.9] https://megalinter.io/7.3.0/descriptors/copypaste_jscpd
  - MegaLinter key: [COPYPASTE_JSCPD]
  - Rules config: [.jscpd.json]
  --Error detail:
  Clone found (powershell):
   - Winget-AutoUpdate/mods/_Mods-Functions.ps1 [109:13 - [116](https://github.com/Romanitho/Winget-AutoUpdate/actions/runs/6516589851/job/17700259244#step:4:119):19] (7 lines, 99 tokens)
     Winget-AutoUpdate/mods/_Mods-Functions.ps1 [53:9 - 60:19]
  
  Clone found (powershell):
   - Winget-AutoUpdate/mods/_Mods-Functions.ps1 [[117](https://github.com/Romanitho/Winget-AutoUpdate/actions/runs/6516589851/job/17700259244#step:4:120):25 - 129:59] (12 lines, [128](https://github.com/Romanitho/Winget-AutoUpdate/actions/runs/6516589851/job/17700259244#step:4:131) tokens)
     Winget-AutoUpdate/mods/_Mods-Functions.ps1 [61:21 - 73:59]
  
  Clone found (powershell):
   - Winget-AutoUpdate/functions/Start-Init.ps1 [38:9 - 49:91] (11 lines, 117 tokens)
     Winget-AutoUpdate/functions/Start-Init.ps1 [27:9 - 37:7]
  
  Clone found (powershell):
   - Winget-AutoUpdate/functions/Invoke-LogRotation.ps1 [40:21 - 50:6] (10 lines, 116 tokens)
     Winget-AutoUpdate/functions/Start-Init.ps1 [27:9 - 37:7]
  
  Clone found (powershell):
   - Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 [45:2 - 54:2] (9 lines, 102 tokens)
     Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 [29:2 - 39:50]
  
  Clone found (powershell):
   - Winget-AutoUpdate/Winget-Upgrade.ps1 [276:2 - 285:59] (9 lines, 93 tokens)
     Winget-AutoUpdate/Winget-Upgrade.ps1 [259:2 - 268:63]
  
  Clone found (powershell):
   - Winget-AutoUpdate-Install.ps1 [300:2 - 310:2] (10 lines, 110 tokens)
     Winget-AutoUpdate-Install.ps1 [290:9 - 300:7]
  
  Clone found (powershell):
   - Winget-AutoUpdate-Install.ps1 [516:13 - 528:2] (12 lines, 193 tokens)
     Winget-AutoUpdate/WAU-Uninstall.ps1 [45:9 - 56:10]
  
  Clone found (powershell):
   - Winget-AutoUpdate-Install.ps1 [587:1 - 595:2] (8 lines, 101 tokens)
     Winget-AutoUpdate/functions/Add-Shortcut.ps1 [2:1 - 10:2]

The Add-Shortcut can also be added to Winget-AutoUpdate-Install.ps1 I guess.

@KnifMelti
Copy link
Contributor Author

Don't know what clone found means.. ..and yes add-shortcut can also be imported

@KnifMelti KnifMelti deleted the Update-Winget branch October 14, 2023 14:29
@Romanitho
Copy link
Owner

I guess it means duplicate parts in between files.

@KnifMelti
Copy link
Contributor Author

KnifMelti commented Oct 14, 2023

Let it have its own life 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants