some prettier

This commit is contained in:
2025-10-12 01:25:03 +03:00
parent fb3f2565bc
commit ec284d2385
4 changed files with 41 additions and 52 deletions
+7 -7
View File
@@ -10,39 +10,39 @@ if (-not $isAdmin) {
Write-Host "Administrator privileges confirmed."
Clear-Host
Write-Host "Select a module:"
Write-Host "Select a module:" -ForegroundColor Yellow
$moduleNames = $modules.Keys | Sort-Object
for ($i = 0; $i -lt $moduleNames.Count; $i++) {
Write-Host "[$($i+1)] $($moduleNames[$i])"
Write-Host "$($i+1). $($moduleNames[$i])" -ForegroundColor DarkYellow
}
do {
$moduleSelection = Read-Host "Enter the number of your choice"
$validModule = ($moduleSelection -as [int]) -and ($moduleSelection -ge 1) -and ($moduleSelection -le $moduleNames.Count)
if (-not $validModule) { Write-Host "Invalid module selection. Try again." }
if (-not $validModule) { Write-Host "Invalid module selection. Try again." -ForegroundColor Yellow }
} until ($validModule)
Clear-Host
$selectedModule = $moduleNames[$moduleSelection - 1]
$actions = $modules[$selectedModule]
Write-Host "Selected module: $selectedModule"
Write-Host "Selected module: $selectedModule" -ForegroundColor Yellow
if ($args.Count -ge 1) {
$action = $args[0]
} else {
Write-Host "Select an action for $selectedModule :"
for ($i = 0; $i -lt $actions.Count; $i++) {
Write-Host "[$($i+1)] $($actions[$i])"
Write-Host "$($i+1). $($actions[$i])" -ForegroundColor DarkYellow
}
do {
$selection = Read-Host "Enter the number of your choice"
$valid = ($selection -as [int]) -and ($selection -ge 1) -and ($selection -le $actions.Count)
if (-not $valid) { Write-Host "Invalid selection. Try again." }
if (-not $valid) { Write-Host "Invalid selection. Try again." -ForegroundColor Yellow }
} until ($valid)
$action = $actions[$selection - 1]
}
Clear-Host
Write-Host "Selected action: $action"
Write-Host "Selected action: $action" -ForegroundColor Yellow
& (Get-Variable $selectedModule).Value $action
+18 -24
View File
@@ -1,18 +1,12 @@
# Manage symlink state. Reconnect = disconnect && connect
param(
[string]$action = "reconnect" # connect | disconnect | reconnect
[string]$action = "reconnect"
)
Write-Host "Apps Manager started with action: $action"
Write-Host "AppData Manager started with action: $action" -ForegroundColor Yellow
# CSV file with applications
$config = $appsAll
# Import CSV
$csv = Import-Csv -Path $config
$csv = Import-Csv -Path $appsAll
foreach ($app in $csv) {
# Skip disabled entries
if ($app.Enabled -ne "1") { continue }
$AppName = $app.App
@@ -30,12 +24,12 @@ foreach ($app in $csv) {
$to = Join-Path $env:USERPROFILE $to
}
Write-Host "=============================="
Write-Host "Processing $AppName with action $action (Type=$($app.Type))"
Write-Host " Raw From: $rawFrom"
Write-Host " Raw To : $rawTo"
Write-Host " Expanded From: $from"
Write-Host " Expanded To : $to"
Write-Host "==============================" -ForegroundColor Gray
Write-Host "Processing $AppName with action $action (Type=$($app.Type))" -ForegroundColor White
Write-Host " Raw From: $rawFrom" -ForegroundColor White
Write-Host " Raw To : $rawTo" -ForegroundColor White
Write-Host " Expanded From: $from" -ForegroundColor White
Write-Host " Expanded To : $to" -ForegroundColor White
# Handle isolate type: execute a script instead of symlinks
if ($app.Type -eq "isolate") {
@@ -52,41 +46,41 @@ foreach ($app in $csv) {
$scriptPath = Join-Path $apps "$safeName.ps1"
}
Write-Host " Isolate mode: Executing script $scriptPath"
Write-Host " Isolate mode: Executing script $scriptPath" -ForegroundColor Yellow
if (Test-Path $scriptPath) {
try {
# Pass action and app context to the script
& $scriptPath -Action $action -AppName $AppName -From $from -To $to
} catch {
Write-Error "Script failed for $AppName`: $($_.Exception.Message)"
Write-Error "Script failed for $AppName`: $($_.Exception.Message)" -ForegroundColor Red
}
} else {
Write-Warning "Isolate script not found: $scriptPath"
Write-Warning "Isolate script not found: $scriptPath" -ForegroundColor Red
}
continue # Skip symlink handling
continue
}
switch ($action.ToLower()) {
"disconnect" {
Write-Host " Removing $to"
Write-Host " Removing $to" -ForegroundColor Red
if (Test-Path $to) { Remove-Item $to -Recurse -Force }
}
"connect" {
Write-Host " Creating symlink $to -> $from"
Write-Host " Creating symlink $to -> $from" -ForegroundColor Blue
if (-not (Test-Path $to)) {
New-Item -Path $to -ItemType SymbolicLink -Value $from | Out-Null
}
}
"reconnect" {
Write-Host " Removing $to"
Write-Host " Removing $to" -ForegroundColor Red
if (Test-Path $to) { Remove-Item $to -Recurse -Force }
Write-Host " Creating symlink $to -> $from"
Write-Host " Creating symlink $to -> $from" -ForegroundColor Blue
if (-not (Test-Path $to)) {
New-Item -Path $to -ItemType SymbolicLink -Value $from | Out-Null
}
}
default {
Write-Warning "Unknown action: $action"
Write-Warning "Unknown action: $action" -ForegroundColor DarkYellow
}
}
}
+5 -5
View File
@@ -3,7 +3,7 @@ param(
[string]$Action = 'apply'
)
Write-Host "Deployment Manager started with action: $Action"
Write-Host "Deployment Manager started with action: $Action" -ForegroundColor Yellow
# Define modules with their respective actions
$Modules = @(
@@ -16,7 +16,7 @@ $Modules = @(
foreach ($module in $Modules) {
$currentAction = if ($Action -eq 'apply') { $module.Apply } else { $module.Clean }
Write-Host "`n=== $($module.Name) : $currentAction"
Write-Host "`n=== $($module.Name) : $currentAction" -ForegroundColor White
try {
# Resolve the script path stored in a variable with the same name
$scriptPath = (Get-Variable -Name $module.Name -ErrorAction Stop).Value
@@ -25,12 +25,12 @@ foreach ($module in $Modules) {
& $scriptPath $currentAction
}
else {
Write-Warning "Module script not found: $scriptPath"
Write-Warning "Module script not found: $scriptPath" -ForegroundColor DarkYellow
}
}
catch {
Write-Warning "Could not resolve path for module '$($module.Name)': $_"
Write-Warning "Could not resolve path for module '$($module.Name)': $_" -ForegroundColor DarkYellow
}
}
Write-Host "`nDeployment finished."
Write-Host "`nDeployment finished." -ForegroundColor Green
+11 -16
View File
@@ -1,15 +1,10 @@
param(
[string]$action = "reconnect" # connect | disconnect | reconnect
[string]$action = "reconnect"
)
Write-Host "Folder Symlink Manager started with action: $action"
# CSV file with folder mappings
$config = $mountsAll # переменная с путём к CSV
# Import CSV
$csv = Import-Csv -Path $config
Write-Host "Mounts Manager started with action: $action" -ForegroundColor Yellow
$csv = Import-Csv -Path $mountsAll
foreach ($entry in $csv) {
if ($entry.Enabled -ne "1") { continue }
@@ -28,26 +23,26 @@ foreach ($entry in $csv) {
$to = Join-Path $env:USERPROFILE $to
}
Write-Host "=============================="
Write-Host "Processing $Name with action $action"
Write-Host " From: $from"
Write-Host " To : $to"
Write-Host "===============================" -ForegroundColor Gray
Write-Host "Processing $Name with action $action" -ForegroundColor White
Write-Host " From: $from" -ForegroundColor White
Write-Host " To : $to" -ForegroundColor White
switch ($action.ToLower()) {
"disconnect" {
Write-Host " Removing $to"
Write-Host " Removing $to" -ForegroundColor Red
if (Test-Path $to) { Remove-Item $to -Recurse -Force }
}
"connect" {
Write-Host " Creating symlink $to -> $from"
Write-Host " Creating symlink $to -> $from" -ForegroundColor Blue
if (-not (Test-Path $to)) {
New-Item -Path $to -ItemType SymbolicLink -Value $from | Out-Null
}
}
"reconnect" {
Write-Host " Removing $to"
Write-Host " Removing $to" -ForegroundColor Red
if (Test-Path $to) { Remove-Item $to -Recurse -Force }
Write-Host " Creating symlink $to -> $from"
Write-Host " Creating symlink $to -> $from" -ForegroundColor Blue
if (-not (Test-Path $to)) {
New-Item -Path $to -ItemType SymbolicLink -Value $from | Out-Null
}