253 lines
9.6 KiB
PowerShell
253 lines
9.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/tree/main/installers"
|
|
$temp = "$env:TEMP\win_setup"
|
|
|
|
# ============================================================
|
|
# 1. OTKLYuChENIE ANTIVIRUSA (OBYAZATELNO!)
|
|
# ============================================================
|
|
Write-Host "`n[1/4] 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/4] 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
|
|
}
|
|
|
|
# Gruppiruem programmy po kategoriyam iz konfiga
|
|
$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]
|
|
}
|
|
}
|
|
|
|
# Sozdayom kartu: imya faila -> programma
|
|
$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' }
|
|
}
|
|
}
|
|
|
|
# Avtomaticheski raspredelyaem programmy po kategoriyam
|
|
$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["Other"] = $uncategorized
|
|
}
|
|
|
|
# ============================================================
|
|
# 3. VYBOR PROGRAMM
|
|
# ============================================================
|
|
Write-Host "[3/4] Program selection..." -ForegroundColor Yellow
|
|
|
|
Write-Host "`nAvailable programs in repo:`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 - ALL programs" -ForegroundColor Green
|
|
Write-Host " 0 - Cancel`n" -ForegroundColor Gray
|
|
|
|
$choice = Read-Host "Select programs (1,2,3 or a)"
|
|
|
|
if ($choice -eq "0") {
|
|
Write-Host "Canceled" -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 "No programs selected" -ForegroundColor Red
|
|
exit
|
|
}
|
|
|
|
Write-Host "`nSelected: $($selectedPrograms.Count) programs" -ForegroundColor Green
|
|
|
|
# ============================================================
|
|
# 4. SKACHIVANIE I USTANOVKA
|
|
# ============================================================
|
|
Write-Host "[4/4] 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/4] 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 ""
|