From c283bbce405a3aa65c6a270c43dd0b1736f1647b Mon Sep 17 00:00:00 2001 From: oqyude Date: Sun, 12 Oct 2025 01:05:54 +0300 Subject: [PATCH] new modules --- src/modules/deploy.ps1 | 2 ++ src/modules/package-manager.ps1 | 38 ++++++++++++++++++++++++++++++++ src/modules/winget-installer.ps1 | 33 +++++++++++++++++++++++++++ src/vars.ps1 | 18 +++++++++++++-- src/winget.ps1 | 3 --- 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 src/modules/package-manager.ps1 create mode 100644 src/modules/winget-installer.ps1 delete mode 100644 src/winget.ps1 diff --git a/src/modules/deploy.ps1 b/src/modules/deploy.ps1 index 760be96..4c5c732 100644 --- a/src/modules/deploy.ps1 +++ b/src/modules/deploy.ps1 @@ -10,6 +10,8 @@ $Modules = @( @{ Name = 'autostartManagerModule'; Apply = 'update'; Clean = 'remove' }, @{ Name = 'appsDataManagerModule'; Apply = 'reconnect'; Clean = 'disconnect' }, @{ Name = 'mountsManagerModule'; Apply = 'reconnect'; Clean = 'disconnect' } + @{ Name = 'wingetInstallerModule'; Apply = 'install'; Clean = 'check' } + @{ Name = 'packageManagerModule'; Apply = 'install'; Clean = 'uninstall' } ) foreach ($module in $Modules) { diff --git a/src/modules/package-manager.ps1 b/src/modules/package-manager.ps1 new file mode 100644 index 0000000..28be0e0 --- /dev/null +++ b/src/modules/package-manager.ps1 @@ -0,0 +1,38 @@ +param( + [Parameter(Mandatory=$true)] + [ValidateSet("install","uninstall")] + [string]$Mode +) + +$packageList = @( + "MartiCliment.UniGetUI" +) + +if (-not (checkWingetStatus)) { + Write-Host "winget is not available. Aborting." -ForegroundColor Red + return +} + +foreach ($pkg in $packageList) { + switch ($Mode) { + "install" { + Write-Host "Installing $pkg..." -ForegroundColor Cyan + try { + winget install --id $pkg --silent --accept-package-list-agreements --accept-source-agreements + } + catch { + Write-Host "Failed to install $pkg : $($_.Exception.Message)" -ForegroundColor Red + } + } + "uninstall" { + Write-Host "Uninstalling $pkg..." -ForegroundColor Cyan + try { + winget uninstall --id $pkg --silent + } + catch { + Write-Host "Failed to uninstall $pkg : $($_.Exception.Message)" -ForegroundColor Red + } + } + } +} +Write-Host "All requested packages processed." -ForegroundColor Green diff --git a/src/modules/winget-installer.ps1 b/src/modules/winget-installer.ps1 new file mode 100644 index 0000000..c702577 --- /dev/null +++ b/src/modules/winget-installer.ps1 @@ -0,0 +1,33 @@ +param( + [Parameter(Mandatory=$true)] + [ValidateSet("check","install")] + [string]$Mode +) +function install { + if (checkWingetStatus) { + Write-Host "Skipping installation, winget already present." -ForegroundColor Cyan + return + } + $wingetUrl = "https://aka.ms/getwinget" + $wingetFile = "$tempFolder\winget.msixbundle" + try { + Write-Host "Downloading winget..." -ForegroundColor Cyan + Invoke-WebRequest -Uri $wingetUrl -OutFile $wingetFile -UseBasicParsing + + Write-Host "Installing winget..." -ForegroundColor Cyan + Add-AppxPackage $wingetFile + + Write-Host "winget successfully installed." -ForegroundColor Green + } + catch { + Write-Host "Failed to install winget: $($_.Exception.Message)" -ForegroundColor Red + } + finally { + if (Test-Path $wingetFile) { Remove-Item $wingetFile -Force } + } +} + +switch ($Mode) { + "check" { return checkWingetStatus | Out-Null } + "install" { install } +} diff --git a/src/vars.ps1 b/src/vars.ps1 index 3f60f5a..a26e305 100644 --- a/src/vars.ps1 +++ b/src/vars.ps1 @@ -3,6 +3,8 @@ $appsDataManagerModule = "$PSScriptRoot\modules\appdata-manager.ps1" $autostartManagerModule = "$PSScriptRoot\modules\autostart-manager.ps1" $mountsManagerModule = "$PSScriptRoot\modules\mounts-manager.ps1" $deployModule = "$PSScriptRoot\modules\deploy.ps1" +$wingetInstallerModule = "$PSScriptRoot\modules\winget-installer.ps1" +$packageManagerModule = "$PSScriptRoot\modules\package-manager.ps1" # Define available modules with their respective actions $modules = @{ @@ -10,10 +12,21 @@ $modules = @{ "autostartManagerModule" = @("update", "remove") "deployModule" = @("apply", "clean") "mountsManagerModule" = @("reconnect", "connect", "disconnect") + "packageManagerModule" = @("install", "uninstall") } -# Package Manager Installers -$winget = "$PSScriptRoot\winget.ps1" +# Functions +function checkWingetStatus { + try { + $null = winget --version 2>$null + Write-Host "Winget is installed." -ForegroundColor Green + return $true + } + catch { + Write-Host "Winget is not installed." -ForegroundColor Yellow + return $false + } +} # Data folder $data = "$root\data" @@ -24,5 +37,6 @@ $appsAll = "$data\apps.csv" $mountsAll = "$data\mounts.csv" # GLOBAL +$tempFolder = "$env:TEMP\winos"; $storage = "$env:USERPROFILE\Storage" $autostartDir = "$data\autorun" \ No newline at end of file diff --git a/src/winget.ps1 b/src/winget.ps1 deleted file mode 100644 index 310113b..0000000 --- a/src/winget.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle -Add-AppxPackage winget.msixbundle -Remove-Item winget.msixbundle \ No newline at end of file