complete..
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
param(
|
||||
[string]$action = "update" # update, remove
|
||||
)
|
||||
|
||||
$taskPrefix = "winos_"
|
||||
|
||||
function Get-ManagedTasks {
|
||||
Get-ScheduledTask | Where-Object {$_.TaskName -like "$taskPrefix*"}
|
||||
}
|
||||
function Update-Tasks($shortcut) {
|
||||
$shell = New-Object -ComObject WScript.Shell
|
||||
$sc = $shell.CreateShortcut($shortcut.FullName)
|
||||
$taskName = "$taskPrefix$($shortcut.BaseName)"
|
||||
|
||||
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
||||
|
||||
# Добавляем аргументы из ярлыка
|
||||
$actionObj = New-ScheduledTaskAction -Execute $sc.TargetPath -Argument $sc.Arguments
|
||||
if ($sc.WorkingDirectory) { $actionObj.WorkingDirectory = $sc.WorkingDirectory }
|
||||
$trigger = New-ScheduledTaskTrigger -AtLogOn
|
||||
|
||||
if ($existingTask) {
|
||||
Set-ScheduledTask -TaskName $taskName -Action $actionObj -Trigger $trigger
|
||||
} else {
|
||||
Register-ScheduledTask -TaskName $taskName -Action $actionObj -Trigger $trigger -User $env:USERNAME -RunLevel Highest -Force
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Remove-AllTasks($tasks) {
|
||||
foreach ($t in $tasks) {
|
||||
Unregister-ScheduledTask -TaskName $t.TaskName -Confirm:$false
|
||||
}
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
"update" {
|
||||
if (-Not (Test-Path $autostartDir)) {
|
||||
Write-Error "Папка автозапуска не найдена: $autostartDir"
|
||||
break
|
||||
}
|
||||
|
||||
# Получаем все ярлыки из папки
|
||||
$shortcuts = Get-ChildItem -Path $autostartDir -Filter *.lnk
|
||||
|
||||
# Создаем/обновляем задачи по ярлыкам
|
||||
foreach ($sc in $shortcuts) {
|
||||
Update-Tasks $sc
|
||||
}
|
||||
|
||||
# Удаляем задачи, которых нет в папке
|
||||
$existingTasks = Get-ManagedTasks
|
||||
foreach ($t in $existingTasks) {
|
||||
$nameWithoutPrefix = $t.TaskName.Substring($taskPrefix.Length)
|
||||
if (-Not ($shortcuts.BaseName -contains $nameWithoutPrefix)) {
|
||||
Unregister-ScheduledTask -TaskName $t.TaskName -Confirm:$false
|
||||
}
|
||||
}
|
||||
}
|
||||
"remove" {
|
||||
Remove-AllTasks (Get-ManagedTasks)
|
||||
}
|
||||
default {
|
||||
Write-Error "Неизвестное действие: $action. Используйте 'update' или 'remove'."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
param(
|
||||
[ValidateSet("apply","clean")]
|
||||
[string]$action = "apply"
|
||||
)
|
||||
|
||||
Write-Host "Deployment Manager started with action: $action"
|
||||
|
||||
# Список модулей с аргументами для apply и clean
|
||||
$deployModules = @(
|
||||
@{ Module = "autostartManager"; Apply = "update"; Clean = "remove" },
|
||||
@{ Module = "appsDataManager"; Apply = "reconnect"; Clean = "disconnect" },
|
||||
@{ Module = "mountsManagerModule"; Apply = "reconnect"; Clean = "disconnect" }
|
||||
)
|
||||
|
||||
foreach ($item in $deployModules) {
|
||||
$moduleName = $item.Module
|
||||
$moduleAction = if ($action -eq "apply") { $item.Apply } else { $item.Clean }
|
||||
|
||||
Write-Host "=============================="
|
||||
Write-Host "Executing module '$moduleName' with action '$moduleAction'"
|
||||
|
||||
$modulePath = Join-Path $PSScriptRoot "$moduleName.ps1"
|
||||
|
||||
if (Test-Path $modulePath) {
|
||||
try {
|
||||
# Передаём аргумент точно так же, как $action передавался бы напрямую модулю
|
||||
& $modulePath $moduleAction
|
||||
} catch {
|
||||
Write-Warning "Module '$moduleName' failed: $($_.Exception.Message)"
|
||||
}
|
||||
} else {
|
||||
Write-Warning "Module script not found: $modulePath"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Deployment finished."
|
||||
+6
-8
@@ -1,9 +1,10 @@
|
||||
# LOCAL
|
||||
|
||||
# Modules
|
||||
$appsDataManager = "$PSScriptRoot\modules\appdata-manager.ps1"
|
||||
$autostartManager = "$PSScriptRoot\modules\autostart-manager.ps1"
|
||||
$mountsManager = "$PSScriptRoot\modules\mounts-manager.ps1"
|
||||
$appsDataManagerModule = "$PSScriptRoot\modules\appdata-manager.ps1"
|
||||
$autostartManagerModule = "$PSScriptRoot\modules\autostart-manager.ps1"
|
||||
$mountsManagerModule = "$PSScriptRoot\modules\mounts-manager.ps1"
|
||||
$deployModule = "$PSScriptRoot\modules\deploy.ps1"
|
||||
|
||||
# Package Manager Installers
|
||||
$winget = "$PSScriptRoot\winget.ps1"
|
||||
@@ -16,14 +17,11 @@ $apps = "$data\isolate"
|
||||
$appsAll = "$data\apps.csv"
|
||||
$mountsAll = "$data\mounts.csv"
|
||||
# $appsUser = "$apps\$env:COMPUTERNAME"
|
||||
# $appsLegacy = "$apps\legacy"
|
||||
|
||||
# Mounts
|
||||
# $mounts = "$data\mounts"
|
||||
|
||||
# GLOBAL
|
||||
$storage = "$env:USERPROFILE\Storage"
|
||||
$autostartDir = "C:\Winos\Scenaries\Autorun"
|
||||
$autostartDir = "$data\autorun"
|
||||
# $autostartDir = "C:\Winos\Scenaries\Autorun"
|
||||
|
||||
# $userName = "oqyude"
|
||||
# $diskLabel = "S:"
|
||||
|
||||
Reference in New Issue
Block a user