auto-turning/setup.ps1

250 lines
10 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"
$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/4] Отключение антивируса..." -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/4] Загрузка конфигурации и списка программ..." -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
}
# Загружаем список файлов из репозитория через API
Write-Host " Получаю список программ из репозитория..." -ForegroundColor Gray
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
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]
}
}
# Создаём карту: имя файла -> программа
$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' }
}
}
# Автоматически распределяем программы по категориям
$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)"
if ($choice -eq "0") {
Write-Host "Отмена" -ForegroundColor Red
exit
}
$selectedPrograms = @()
if ($choice -eq "a") {
$selectedPrograms = $allPrograms
} else {
foreach ($num in $choice.Split(',')) {
$num = $num.Trim()
if ($progMap[$num]) {
$selectedPrograms += $progMap[$num]
}
}
}
if ($selectedPrograms.Count -eq 0) {
Write-Host "Программы не выбраны" -ForegroundColor Red
exit
}
Write-Host "`nВыбрано программ: $($selectedPrograms.Count)" -ForegroundColor Green
# ============================================================
# 4. СКАЧИВАНИЕ И УСТАНОВКА
# ============================================================
Write-Host "[4/4] Установка программ..." -ForegroundColor Yellow
$installed = @()
$failed = @()
foreach ($prog in $selectedPrograms) {
$programUrl = "$repo/installers/$($prog.File)"
$programPath = "$temp\$($prog.File)"
Write-Host "`n Скачиваю: $($prog.Name)" -ForegroundColor Gray
try {
Invoke-WebRequest -Uri $programUrl -OutFile $programPath -ErrorAction Stop
Write-Host " Устанавливаю: $($prog.Name)" -ForegroundColor Gray
# Установка в зависимости от типа файла
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 "`n[5/4] Завершение..." -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 ""