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

[Request] Do not set up automated package update tasks without prompting the user first #122

Closed
nopeless opened this issue Oct 3, 2023 · 3 comments · Fixed by #127
Closed
Labels
Feature Request New feature request

Comments

@nopeless
Copy link

nopeless commented Oct 3, 2023

Description

src/scripts/Install-PackageManager.ps1

function Install-PackageManager() {
    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory)]
        [String]	  $PackageManagerFullName,
        [Parameter(Position = 1, Mandatory)]
        [ScriptBlock] $CheckExistenceBlock,
        [Parameter(Position = 2, Mandatory)]
        [ScriptBlock] $InstallCommandBlock,
        [String]      $Time,
        [ScriptBlock] $UpdateScriptBlock,
        [ScriptBlock] $PostInstallBlock
    )

    Try {
        $Err = (Invoke-Expression "$CheckExistenceBlock")
        If (($LASTEXITCODE)) { throw $Err } # 0 = False, 1 = True
        Write-Status -Types "?", $PackageManagerFullName -Status "$PackageManagerFullName is already installed." -Warning
    } Catch {
        Write-Status -Types "?", $PackageManagerFullName -Status "$PackageManagerFullName was not found." -Warning
        Write-Status -Types "+", $PackageManagerFullName -Status "Downloading and Installing $PackageManagerFullName package manager."

        Invoke-Expression "$InstallCommandBlock"

        If ($PostInstallBlock) {
            Write-Status -Types "+", $PackageManagerFullName -Status "Executing post install script: { $("$PostInstallBlock".Trim(' ')) }."
            Invoke-Expression "$PostInstallBlock"
        }
    }

    # Self-reminder, this part stay out of the Try-Catch block
    If ($UpdateScriptBlock) {
        # Adapted from: https://blogs.technet.microsoft.com/heyscriptingguy/2013/11/23/using-scheduled-tasks-and-scheduled-jobs-in-powershell/
        Write-Status -Types "@", $PackageManagerFullName -Status "Creating a daily task to automatically upgrade $PackageManagerFullName packages at $Time."
        $JobName = "$PackageManagerFullName Daily Upgrade"
        $ScheduledJob = @{
            Name               = $JobName
            ScriptBlock        = $UpdateScriptBlock
            Trigger            = New-JobTrigger -Daily -At $Time
            ScheduledJobOption = New-ScheduledJobOption -RunElevated -MultipleInstancePolicy StopExisting -RequireNetwork
        }

        If ((Get-ScheduledTask -TaskName $JobName -ErrorAction SilentlyContinue) -or (Get-ScheduledJob -Name $JobName -ErrorAction SilentlyContinue)) {
            Write-Status -Types "@", $PackageManagerFullName -Status "ScheduledJob: $JobName FOUND!"
            Write-Status -Types "@", $PackageManagerFullName -Status "Re-Creating with the command:"
            Write-Host " { $("$UpdateScriptBlock".Trim(' ')) }`n" -ForegroundColor Cyan
            Stop-ScheduledTask -TaskPath "\Microsoft\Windows\PowerShell\ScheduledJobs" -TaskName $JobName
            Unregister-ScheduledJob -Name $JobName
            Register-ScheduledJob @ScheduledJob | Out-Null
        } Else {
            Write-Status -Types "@", $PackageManagerFullName -Status "Creating Scheduled Job with the command:"
            Write-Host " { $("$UpdateScriptBlock".Trim(' ')) }`n" -ForegroundColor Cyan
            Register-ScheduledJob @ScheduledJob | Out-Null
        }
    }
}

Reason

I do not like automated updates unless its a package I am actively tracking. A simple Y/N prompt should satisfy all types of users

Examples

PowerToys once had a bug introduced in their update. Had I enabled automatic updates I wouldn't have figured out whats wrong.

However, some people would prefer the security enhancements of automatic updates. I think it should be a choice

@nopeless nopeless added the Feature Request New feature request label Oct 3, 2023
@nopeless
Copy link
Author

nopeless commented Oct 3, 2023

I am willing to submit a PR for this

@LeDragoX
Copy link
Owner

LeDragoX commented Oct 4, 2023

I am willing to submit a PR for this

@nopeless Before you do that, i kinda changed how Winget and Chocolatey are installed, it's not automated with the script's startup anymore, even the Daily Upgrade Scheduled Tasks (#110).

Check the develop branch, and if you feel good (or not) on the changes, let me know (find them on src/lib/package-managers).

@LeDragoX
Copy link
Owner

Again, the way Winget and Chocolatey installs was changed, they'll install as a feature on DEMAND, when the user wants to install a software and didn't got winget or chocolatey working, it'll install only the needed tool to get the demanded package.
No automated update will happen, only the package manager install.

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

Successfully merging a pull request may close this issue.

2 participants