auto-turning/rd_setup.ps1

221 lines
8.6 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.

# ============================================================
# RustDesk CLIENT SETUP
# Zapusk: irm https://git.help-d.ru/helmut/auto-turning/raw/branch/main/rd_setup.ps1 | iex
# ============================================================
$repo = "https://git.help-d.ru/helmut/auto-turning/raw/branch/main"
$temp = "$env:TEMP\rd_setup"
# RustDesk server config
$RD_HOST = "95.81.124.153"
$RD_KEY = "T2CieQYAOU+iSkFGTLkkuJBdoYF5lyv4vPAikNRvruo="
Write-Host "`n========== RUSTDESK SETUP ==========`n" -ForegroundColor Cyan
# ============================================================
# 1. OTKLYuChENIE ANTIVIRUSA
# ============================================================
Write-Host "[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
Write-Host " Antivirus disabled" -ForegroundColor Green
# ============================================================
# 2. POKACHIVANIE I USTANOVKA
# ============================================================
Write-Host "[2/5] Download and install RustDesk..." -ForegroundColor Yellow
New-Item -ItemType Directory -Path $temp -Force | Out-Null
# Opredelyaem razryadnost sistemy
$arch = (Get-WmiObject -Class Win32_OperatingSystem -ErrorAction SilentlyContinue).OSArchitecture
if ($arch -match "32") {
$isX86 = $true
Write-Host " Architecture: x86 (32-bit)" -ForegroundColor Gray
} else {
$isX86 = $false
Write-Host " Architecture: x64 (64-bit)" -ForegroundColor Gray
}
# Nahodim fayl RustDesk v repo cherez API
$repoApi = "$($repo -replace '/raw/branch/main', '')/api/v1/repos/helmut/auto-turning/contents/installers"
try {
$response = Invoke-WebRequest -Uri $repoApi -ErrorAction Stop
$allFiles = ($response.Content | ConvertFrom-Json) | Where-Object { $_.type -eq "file" }
# Vibiraem nuzhnyj fayl po arhitekture
if ($isX86) {
# Dlya 32-bit: sciter versiya
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk.*x86.*sciter" } | Select-Object -First 1).name
if (-not $rdFile) {
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk.*x86" } | Select-Object -First 1).name
}
} else {
# Dlya 64-bit: x86_64 versiya
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk.*x86_64" } | Select-Object -First 1).name
}
if (-not $rdFile) {
# Fallback: lyuboy rustdesk fayl
$rdFile = ($allFiles | Where-Object { $_.name -match "rustdesk" } | Select-Object -First 1).name
}
if (-not $rdFile) {
Write-Host " RustDesk installer NOT found in repo" -ForegroundColor Red
exit 1
}
Write-Host " Selected: $rdFile" -ForegroundColor Green
} catch {
# Fallback: esli API nedostupen
if ($isX86) {
$rdFile = "rustdesk-1.4.6-x86-sciter.exe"
} else {
$rdFile = "rustdesk-1.4.6-x86_64.exe"
}
Write-Host " Using default: $rdFile" -ForegroundColor Yellow
}
$rdUrl = "$repo/installers/$rdFile"
$rdPath = "$temp\$rdFile"
Write-Host " Downloading..." -ForegroundColor Gray
Invoke-WebRequest -Uri $rdUrl -OutFile $rdPath -ErrorAction Stop
Write-Host " Downloaded" -ForegroundColor Green
Write-Host " Installing..." -ForegroundColor Gray
$result = Start-Process $rdPath -ArgumentList "/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-" -Wait -PassThru -NoNewWindow
if ($result.ExitCode -eq 0 -or $result.ExitCode -eq 3010) {
Write-Host " RustDesk installed" -ForegroundColor Green
} else {
Write-Host " Install error (code: $($result.ExitCode))" -ForegroundColor Yellow
}
# ============================================================
# 3. NASTROYKA RETRANSLyATORA (HOST + KEY)
# ============================================================
Write-Host "[3/5] Configuring relay server..." -ForegroundColor Yellow
# RustDesk hranit nastrojki v registru i v config-fajle
# 1) Reestr (HKEY_LOCAL_MACHINE) — dlya vseh polzovatelej
$rdRegPath = "HKLM:\SOFTWARE\RustDesk"
if (-not (Test-Path $rdRegPath)) {
New-Item -Path $rdRegPath -Force | Out-Null
}
# Proverayem kuda ustanovlen RustDesk
$rdExePaths = @(
"C:\Program Files\RustDesk\RustDesk.exe",
"${env:ProgramFiles(x86)}\RustDesk\RustDesk.exe",
"$env:LOCALAPPDATA\Programs\RustDesk\RustDesk.exe"
)
$rdExe = $rdExePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $rdExe) {
Write-Host " RustDesk.exe not found, trying registry config..." -ForegroundColor Yellow
}
# 2) Config fayl — RustDesk ispolzuet JSON/TOML config
# Path: C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk\config\RustDesk2.toml
# Ili dlya tekushchego polzovatelya: %APPDATA%\RustDesk\config\RustDesk2.toml
$rdConfigDir = "$env:APPDATA\RustDesk\config"
$rdConfigFile = "$rdConfigDir\RustDesk2.toml"
# Sozdayem papku esli net
New-Item -ItemType Directory -Path $rdConfigDir -Force | Out-Null
# Proveryaem sushestvuet li config
$createNew = $true
if (Test-Path $rdConfigFile) {
$createNew = $false
Write-Host " Existing config found, updating..." -ForegroundColor Gray
}
# Formiruem soderzhimoe TOML
$tomlContent = @"
[options]
custom-rendezvous-server = "$RD_HOST"
relay-server = "$RD_HOST"
key = "$RD_KEY"
"@
$tomlContent | Set-Content $rdConfigFile -Encoding UTF8 -Force
Write-Host " User config written" -ForegroundColor Green
# Takzhe zapisyvaem v reestr dlya system-level
if ($rdExe) {
$rdDir = Split-Path $rdExe
$systemConfigDir = "$rdDir\config"
$systemConfigFile = "$systemConfigDir\RustDesk2.toml"
New-Item -ItemType Directory -Path $systemConfigDir -Force | Out-Null
$tomlContent | Set-Content $systemConfigFile -Encoding UTF8 -Force
Write-Host " System config written" -ForegroundColor Green
}
# Registry keys (dlya avtozapuska servisa)
$serviceRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\rustdesk"
$rustdeskService = Get-Service -Name "RustDesk" -ErrorAction SilentlyContinue
if ($rustdeskService) {
# Ostanavlivаем servis pered nastrojkoj
Write-Host " Stopping RustDesk service..." -ForegroundColor Gray
Stop-Service -Name "RustDesk" -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
# Zapuskem s nastrojkami
Write-Host " Starting RustDesk service..." -ForegroundColor Gray
Start-Service -Name "RustDesk" -ErrorAction SilentlyContinue
Write-Host " RustDesk service restarted" -ForegroundColor Green
} else {
Write-Host " RustDesk service not found (running as app)" -ForegroundColor Yellow
}
# ============================================================
# 4. VKLYuChENIE ANTIVIRUSA
# ============================================================
Write-Host "[4/5] Enabling 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
# ============================================================
# 5. ChISTKA
# ============================================================
Write-Host "[5/5] Cleanup..." -ForegroundColor Yellow
Remove-Item $temp -Recurse -Force -ErrorAction SilentlyContinue
Write-Host " Temp files deleted" -ForegroundColor Green
# ============================================================
# REZULTAT
# ============================================================
Write-Host "`n==========================================" -ForegroundColor Green
Write-Host " RUSTDESK SETUP COMPLETE" -ForegroundColor Green
Write-Host "==========================================" -ForegroundColor Green
Write-Host "`nRelay Server: $RD_HOST" -ForegroundColor Cyan
Write-Host "Key: $RD_KEY" -ForegroundColor Cyan
if ($rdExe) {
Write-Host "`nRustDesk path: $rdExe" -ForegroundColor Yellow
}
Write-Host "`nZapustite RustDesk i podklyuchaytes cherez vash server." -ForegroundColor Green
Write-Host ""