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