auto-turning/setup.ps1

212 lines
8.6 KiB
PowerShell

# ============================================================
# Skript ustanovki programm
# Zapusk: 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/contents/installers"
$temp = "$env:TEMP\win_setup"
# ============================================================
# 1. OTKLYuChENIE ANTIVIRUSA (OBYAZATELNO!)
# ============================================================
Write-Host "`n[1/5] Antivirus disable..." -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 " Antivirus disabled" -ForegroundColor Green
# ============================================================
# 2. ZAGRUZKA KONFIGA I SPISKA PROGRAMM
# ============================================================
Write-Host "[2/5] Loading config and program list..." -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 " Config loaded" -ForegroundColor Green
} catch {
Write-Host " Config load error" -ForegroundColor Red
exit 1
}
# Zagruzhayem spisok faylov iz repo cherez API
Write-Host " Scanning installers repo..." -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 " No programs found in repo" -ForegroundColor Red
exit 1
}
Write-Host " Found: $($files.Count) programs" -ForegroundColor Green
} catch {
Write-Host " Failed to get program list" -ForegroundColor Red
exit 1
}
# Sozdayom spisok programm
$programList = @()
foreach ($file in $files) {
$fileName = $file.name
$programList += @{
Name = ($fileName -replace '\.(exe|msi)$', '') -replace '\.', ' '
File = $fileName
Type = if ($fileName -match '\.msi$') { 'msi' } else { 'exe' }
}
}
# Sortiruem po imeni
$programList = $programList | Sort-Object Name
# ============================================================
# 3. VYBOR PROGRAMM
# ============================================================
Write-Host "[3/5] Program selection..." -ForegroundColor Yellow
Write-Host "`nAvailable programs in repo:`n" -ForegroundColor Cyan
$progMap = @{}
$allPrograms = @()
$i = 1
foreach ($prog in $programList) {
Write-Host (" {0,2} - {1}" -f $i, $prog.Name) -ForegroundColor Yellow
$progMap[$i] = $prog
$allPrograms += $prog
$i++
}
Write-Host "`n a - ALL programs" -ForegroundColor Green
Write-Host " 0 - Cancel`n" -ForegroundColor Gray
$choice = Read-Host "Select (1 2 3 or 1,2,3 or a)"
if ($choice -eq "0") {
Write-Host "Canceled" -ForegroundColor Red
exit
}
$selectedPrograms = @()
if ($choice -eq "a") {
$selectedPrograms = $allPrograms
} else {
# Поддержка: "1, 2, 3" или "1 2 3" или "1,2,3"
$normalized = $choice -replace ',', ' '
foreach ($num in ($normalized -split '\s+') | Where-Object { $_ -match '^\d+$' }) {
if ($progMap[[int]$num]) {
$selectedPrograms += $progMap[[int]$num]
}
}
}
if ($selectedPrograms.Count -eq 0) {
Write-Host "No programs selected" -ForegroundColor Red
exit
}
Write-Host "`nSelected: $($selectedPrograms.Count) programs" -ForegroundColor Green
# ============================================================
# 4. SKACHIVANIE I USTANOVKA
# ============================================================
Write-Host "[4/5] Installing programs..." -ForegroundColor Yellow
$installed = @()
$failed = @()
foreach ($prog in $selectedPrograms) {
$programUrl = "$repo/installers/$($prog.File)"
$programPath = "$temp\$($prog.File)"
Write-Host "`n Downloading: $($prog.Name)" -ForegroundColor Gray
try {
Invoke-WebRequest -Uri $programUrl -OutFile $programPath -ErrorAction Stop
Write-Host " Installing: $($prog.Name)" -ForegroundColor Gray
# Setup by file type
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
} elseif ($prog.File -match "openssh.*\.msi$") {
$result = Start-Process msiexec -ArgumentList "/i `"$programPath`" /quiet /norestart" -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 " [OK] $($prog.Name) installed" -ForegroundColor Green
$installed += $prog.Name
} else {
Write-Host " [FAIL] $($prog.Name) error (code: $($result.ExitCode))" -ForegroundColor Red
$failed += $prog.Name
}
} catch {
Write-Host " [FAIL] $($prog.Name) - download or install error" -ForegroundColor Red
$failed += $prog.Name
}
}
# ============================================================
# 5. ChISTKA I VKLYuChENIE ANTIVIRUSA
# ============================================================
Write-Host "`n[5/5] Cleanup..." -ForegroundColor Yellow
Remove-Item $temp -Recurse -Force -ErrorAction SilentlyContinue
Write-Host " Temp files deleted" -ForegroundColor Green
Write-Host "`nEnabling antivirus..." -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 " Antivirus enabled" -ForegroundColor Green
# ============================================================
# REZULTAT
# ============================================================
Write-Host "`n==========================================" -ForegroundColor Green
Write-Host " INSTALLATION COMPLETE" -ForegroundColor Green
Write-Host "==========================================" -ForegroundColor Green
Write-Host "`nInstalled: $($installed.Count)" -ForegroundColor Cyan
if ($failed.Count -gt 0) {
Write-Host "Failed: $($failed.Count)" -ForegroundColor Red
Write-Host "`nNot installed:" -ForegroundColor Yellow
foreach ($f in $failed) { Write-Host " - $f" -ForegroundColor Gray }
}
Write-Host ""