This commit is contained in:
Windneiro 2026-04-14 09:25:41 +05:00
parent a6203ab3ed
commit ef5eb0fcbb
1 changed files with 133 additions and 76 deletions

201
setup.ps1
View File

@ -4,12 +4,13 @@
# ============================================================
$repo = "https://git.help-d.ru/helmut/auto-turning/raw/branch/main"
$repoApi = "https://git.help-d.ru/api/v1/repos/helmut/auto-turning/tree/main/installers"
$temp = "$env:TEMP\win_setup"
# ============================================================
# 1. ОТКЛЮЧЕНИЕ АНТИВИРУСА (ОБЯЗАТЕЛЬНО!)
# ============================================================
Write-Host "`n[1/5] Отключение антивируса..." -ForegroundColor Yellow
Write-Host "`n[1/4] Отключение антивируса..." -ForegroundColor Yellow
Set-MpPreference -DisableRealtimeMonitoring $true -ErrorAction SilentlyContinue
Set-MpPreference -DisableBehaviorMonitoring $true -ErrorAction SilentlyContinue
@ -22,9 +23,9 @@ Stop-Service -Name MsMpSvc -Force -ErrorAction SilentlyContinue
Write-Host " Антивирус отключен" -ForegroundColor Green
# ============================================================
# 2. ЗАГРУЗКА КОНФИГА
# 2. ЗАГРУЗКА КОНФИГА И СПИСКА ПРОГРАММ
# ============================================================
Write-Host "[2/5] Загрузка конфигурации..." -ForegroundColor Yellow
Write-Host "[2/4] Загрузка конфигурации и списка программ..." -ForegroundColor Yellow
Remove-Item $temp -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $temp -Force | Out-Null
@ -40,16 +41,25 @@ try {
exit 1
}
# Парсим конфиг
$yaml = Get-Content $configPath -Raw
$offAntivirus = $yaml -match "off_antivirus:\s*true"
$reinstall = $yaml -match "reinstall:\s*true"
# Загружаем список файлов из репозитория через API
Write-Host " Получаю список программ из репозитория..." -ForegroundColor Gray
if ($offAntivirus) {
Write-Host " off_antivirus: true (подтверждено)" -ForegroundColor Green
try {
$response = Invoke-WebRequest -Uri $repoApi -ErrorAction Stop
$files = ($response.Content | ConvertFrom-Json) | Where-Object { $_.type -eq "file" }
if ($files.Count -eq 0) {
Write-Host " Программы не найдены в репозитории" -ForegroundColor Red
exit 1
}
Write-Host " Найдено программ: $($files.Count)" -ForegroundColor Green
} catch {
Write-Host " Ошибка получения списка программ" -ForegroundColor Red
exit 1
}
# Извлекаем категории и программы
# Группируем программы по категориям из конфига
$categories = @{}
$currentCat = $null
@ -63,108 +73,155 @@ Get-Content $configPath | ForEach-Object {
}
}
# ============================================================
# 3. ВЫБОР КАТЕГОРИЙ
# ============================================================
Write-Host "[3/5] Выбор категорий..." -ForegroundColor Yellow
Write-Host "`nДоступные категории:`n" -ForegroundColor Cyan
$catList = $categories.Keys | Sort-Object
$i = 1
$catMap = @{}
foreach ($cat in $catList) {
Write-Host " $i - $cat ($($categories[$cat].Count) программ)" -ForegroundColor Yellow
$catMap[$i] = $cat
$i++
# Создаём карту: имя файла -> программа
$programMap = @{}
foreach ($file in $files) {
$fileName = $file.name
$programMap[$fileName] = @{
Name = $fileName -replace '\.exe$|\.msi$', ''
File = $fileName
Type = if ($fileName -match '\.msi$') { 'msi' } else { 'exe' }
}
}
Write-Host "`n a - ВСЕ категории" -ForegroundColor Green
# Автоматически распределяем программы по категориям
$autoCategories = @{}
$uncategorized = @()
foreach ($prog in $programMap.Values) {
$assigned = $false
foreach ($cat in $categories.Keys) {
foreach ($keyword in $categories[$cat]) {
if ($prog.Name -match [regex]::Escape($keyword)) {
if (-not $autoCategories.ContainsKey($cat)) {
$autoCategories[$cat] = @()
}
$autoCategories[$cat] += $prog
$assigned = $true
break
}
}
if ($assigned) { break }
}
if (-not $assigned) {
$uncategorized += $prog
}
}
if ($uncategorized.Count -gt 0) {
$autoCategories["Другие"] = $uncategorized
}
# ============================================================
# 3. ВЫБОР ПРОГРАММ
# ============================================================
Write-Host "[3/4] Выбор программ..." -ForegroundColor Yellow
Write-Host "`nДоступные программы в репозитории:`n" -ForegroundColor Cyan
$i = 1
$progMap = @{}
$allPrograms = @()
foreach ($cat in ($autoCategories.Keys | Sort-Object)) {
Write-Host "`n [$cat]" -ForegroundColor Magenta
foreach ($prog in $autoCategories[$cat]) {
Write-Host " $i - $($prog.Name)" -ForegroundColor Yellow
$progMap[$i] = $prog
$allPrograms += $prog
$i++
}
}
Write-Host "`n a - ВСЕ программы" -ForegroundColor Green
Write-Host " 0 - Отмена`n" -ForegroundColor Gray
$choice = Read-Host "Выберите категории (1,2,3 или a)"
$choice = Read-Host "Выберите программы (1,2,3 или a)"
if ($choice -eq "0") {
Write-Host "Отмена" -ForegroundColor Red
exit
}
$selectedCategories = @()
$selectedPrograms = @()
if ($choice -eq "a") {
$selectedCategories = $catList
$selectedPrograms = $allPrograms
} else {
foreach ($num in $choice.Split(',')) {
$num = $num.Trim()
if ($catMap[$num]) {
$selectedCategories += $catMap[$num]
if ($progMap[$num]) {
$selectedPrograms += $progMap[$num]
}
}
}
if ($selectedCategories.Count -eq 0) {
Write-Host "Категории не выбраны" -ForegroundColor Red
if ($selectedPrograms.Count -eq 0) {
Write-Host "Программы не выбраны" -ForegroundColor Red
exit
}
Write-Host "`nВыбрано: $($selectedCategories -join ', ')" -ForegroundColor Green
Write-Host "`nВыбрано программ: $($selectedPrograms.Count)" -ForegroundColor Green
# ============================================================
# 4. СКАЧИВАНИЕ И УСТАНОВКА
# ============================================================
Write-Host "[4/5] Установка программ..." -ForegroundColor Yellow
Write-Host "[4/4] Установка программ..." -ForegroundColor Yellow
$installed = @()
$failed = @()
foreach ($category in $selectedCategories) {
Write-Host "`n >>> $category" -ForegroundColor Cyan
foreach ($prog in $selectedPrograms) {
$programUrl = "$repo/installers/$($prog.File)"
$programPath = "$temp\$($prog.File)"
foreach ($program in $categories[$category]) {
$programUrl = "$repo/installers/$program"
$programPath = "$temp\$program"
Write-Host "`n Скачиваю: $($prog.Name)" -ForegroundColor Gray
Write-Host " Скачиваю: $program" -ForegroundColor Gray
try {
Invoke-WebRequest -Uri $programUrl -OutFile $programPath -ErrorAction Stop
try {
Invoke-WebRequest -Uri $programUrl -OutFile $programPath -ErrorAction Stop
Write-Host " Устанавливаю: $($prog.Name)" -ForegroundColor Gray
Write-Host " Устанавливаю: $program" -ForegroundColor Gray
# Установка в зависимости от типа файла
if ($program -match "\.msi$") {
$result = Start-Process msiexec -ArgumentList "/i `"$programPath`" /quiet /norestart" -Wait -PassThru -NoNewWindow
} elseif ($program -match "chrome.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/silent /install" -Wait -PassThru -NoNewWindow
} elseif ($program -match "firefox.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} elseif ($program -match "winrar.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} elseif ($program -match "7zip.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} else {
$result = Start-Process $programPath -Wait -PassThru -NoNewWindow
}
if ($result.ExitCode -eq 0 -or $result.ExitCode -eq 3010) {
Write-Host "$program установлен" -ForegroundColor Green
$installed += $program
} else {
Write-Host "$program ошибка (код: $($result.ExitCode))" -ForegroundColor Red
$failed += $program
}
} catch {
Write-Host "$program - не найден в репозитории" -ForegroundColor Red
$failed += $program
# Установка в зависимости от типа файла
if ($prog.Type -eq "msi") {
$result = Start-Process msiexec -ArgumentList "/i `"$programPath`" /quiet /norestart" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "chrome.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/silent /install" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "firefox.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "winrar.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "7zip.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "rustdesk.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "k\.lite.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/VERYSILENT" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "csp.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} elseif ($prog.File -match "thunderbird.*\.exe$") {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
} else {
$result = Start-Process $programPath -ArgumentList "/S" -Wait -PassThru -NoNewWindow
}
if ($result.ExitCode -eq 0 -or $result.ExitCode -eq 3010) {
Write-Host "$($prog.Name) установлен" -ForegroundColor Green
$installed += $prog.Name
} else {
Write-Host "$($prog.Name) ошибка (код: $($result.ExitCode))" -ForegroundColor Red
$failed += $prog.Name
}
} catch {
Write-Host "$($prog.Name) - ошибка загрузки или установки" -ForegroundColor Red
$failed += $prog.Name
}
}
# ============================================================
# 5. ЧИСТКА И ВКЛЮЧЕНИЕ АНТИВИРУСА
# ============================================================
Write-Host "[5/5] Завершение..." -ForegroundColor Yellow
Write-Host "`n[5/4] Завершение..." -ForegroundColor Yellow
Remove-Item $temp -Recurse -Force -ErrorAction SilentlyContinue
Write-Host " Временные файлы удалены" -ForegroundColor Green