auto-turning/setup.ps1

193 lines
8.0 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================================================
# Скрипт установки программ
# Запуск: irm https://git.help-d.ru/helmut/auto-turning/raw/branch/main/setup.ps1 | iex
# ============================================================
$repo = "https://git.help-d.ru/helmut/auto-turning/raw/branch/main"
$temp = "$env:TEMP\win_setup"
# ============================================================
# 1. ОТКЛЮЧЕНИЕ АНТИВИРУСА (ОБЯЗАТЕЛЬНО!)
# ============================================================
Write-Host "`n[1/5] Отключение антивируса..." -ForegroundColor Yellow
Set-MpPreference -DisableRealtimeMonitoring $true -ErrorAction SilentlyContinue
Set-MpPreference -DisableBehaviorMonitoring $true -ErrorAction SilentlyContinue
Set-MpPreference -DisableBlockAtFirstSeen $true -ErrorAction SilentlyContinue
Set-MpPreference -DisableIOAVProtection $true -ErrorAction SilentlyContinue
Set-MpPreference -DisableArchiveScanning $true -ErrorAction SilentlyContinue
Stop-Service -Name WinDefend -Force -ErrorAction SilentlyContinue
Stop-Service -Name MsMpSvc -Force -ErrorAction SilentlyContinue
Write-Host " Антивирус отключен" -ForegroundColor Green
# ============================================================
# 2. ЗАГРУЗКА КОНФИГА
# ============================================================
Write-Host "[2/5] Загрузка конфигурации..." -ForegroundColor Yellow
Remove-Item $temp -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $temp -Force | Out-Null
$configUrl = "$repo/configs/config.yaml"
$configPath = "$temp\config.yaml"
try {
Invoke-WebRequest -Uri $configUrl -OutFile $configPath -ErrorAction Stop
Write-Host " Конфиг загружен" -ForegroundColor Green
} catch {
Write-Host " Ошибка загрузки конфига" -ForegroundColor Red
exit 1
}
# Парсим конфиг
$yaml = Get-Content $configPath -Raw
$offAntivirus = $yaml -match "off_antivirus:\s*true"
$reinstall = $yaml -match "reinstall:\s*true"
if ($offAntivirus) {
Write-Host " off_antivirus: true (подтверждено)" -ForegroundColor Green
}
# Извлекаем категории и программы
$categories = @{}
$currentCat = $null
Get-Content $configPath | ForEach-Object {
if ($_ -match "^\s*(\w+):\s*$" -and $_ -notmatch "basic:") {
$currentCat = $matches[1]
$categories[$currentCat] = @()
}
if ($currentCat -and $_ -match '\d+:\s*"(.+)"') {
$categories[$currentCat] += $matches[1]
}
}
# ============================================================
# 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++
}
Write-Host "`n a - ВСЕ категории" -ForegroundColor Green
Write-Host " 0 - Отмена`n" -ForegroundColor Gray
$choice = Read-Host "Выберите категории (1,2,3 или a)"
if ($choice -eq "0") {
Write-Host "Отмена" -ForegroundColor Red
exit
}
$selectedCategories = @()
if ($choice -eq "a") {
$selectedCategories = $catList
} else {
foreach ($num in $choice.Split(',')) {
$num = $num.Trim()
if ($catMap[$num]) {
$selectedCategories += $catMap[$num]
}
}
}
if ($selectedCategories.Count -eq 0) {
Write-Host "Категории не выбраны" -ForegroundColor Red
exit
}
Write-Host "`nВыбрано: $($selectedCategories -join ', ')" -ForegroundColor Green
# ============================================================
# 4. СКАЧИВАНИЕ И УСТАНОВКА
# ============================================================
Write-Host "[4/5] Установка программ..." -ForegroundColor Yellow
$installed = @()
$failed = @()
foreach ($category in $selectedCategories) {
Write-Host "`n >>> $category" -ForegroundColor Cyan
foreach ($program in $categories[$category]) {
$programUrl = "$repo/installers/$program"
$programPath = "$temp\$program"
Write-Host " Скачиваю: $program" -ForegroundColor Gray
try {
Invoke-WebRequest -Uri $programUrl -OutFile $programPath -ErrorAction Stop
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
}
}
}
# ============================================================
# 5. ЧИСТКА И ВКЛЮЧЕНИЕ АНТИВИРУСА
# ============================================================
Write-Host "[5/5] Завершение..." -ForegroundColor Yellow
Remove-Item $temp -Recurse -Force -ErrorAction SilentlyContinue
Write-Host " Временные файлы удалены" -ForegroundColor Green
Write-Host "`nВключаю антивирус..." -ForegroundColor Yellow
Set-MpPreference -DisableRealtimeMonitoring $false -ErrorAction SilentlyContinue
Set-MpPreference -DisableBehaviorMonitoring $false -ErrorAction SilentlyContinue
Set-MpPreference -DisableBlockAtFirstSeen $false -ErrorAction SilentlyContinue
Set-MpPreference -DisableIOAVProtection $false -ErrorAction SilentlyContinue
Set-MpPreference -DisableArchiveScanning $false -ErrorAction SilentlyContinue
Start-Service -Name WinDefend -ErrorAction SilentlyContinue
Write-Host " Антивирус включен" -ForegroundColor Green
# ============================================================
# РЕЗУЛЬТАТ
# ============================================================
Write-Host "`n==========================================" -ForegroundColor Green
Write-Host " УСТАНОВКА ЗАВЕРШЕНА" -ForegroundColor Green
Write-Host "==========================================" -ForegroundColor Green
Write-Host "`nУстановлено: $($installed.Count)" -ForegroundColor Cyan
if ($failed.Count -gt 0) {
Write-Host "Ошибок: $($failed.Count)" -ForegroundColor Red
Write-Host "`nНе установлены:" -ForegroundColor Yellow
foreach ($f in $failed) { Write-Host " - $f" -ForegroundColor Gray }
}
Write-Host ""