LeDragoX / Win-Debloat-Tools

Re-imagining Windows like a minimal OS install, already debloated with minimal impact for most functionality.
MIT License
4.82k stars 245 forks source link

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

Closed nopeless closed 8 months ago

nopeless commented 9 months ago

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 commented 9 months ago

I am willing to submit a PR for this

LeDragoX commented 9 months ago

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 commented 8 months ago

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.