# ============================================================================== # LD Uninstaller v3.0.0 - Self-Hosted OTA Dağıtım ve Yayınlama Scripti # ============================================================================== [CmdletBinding()] param( [switch]$UploadOnly, [switch]$SkipUpload, [string]$Notes = "LD Uninstaller v3.0.0: Tauri v2 + Rust mimarisi, Restart Manager tabanlı kilit açıcı (Shredder), 20 katmanlı kalıntı temizliği ve otomatik güncelleme desteği." ) $ErrorActionPreference = "Stop" $ScriptDir = $PSScriptRoot Set-Location $ScriptDir Write-Host "==========================================================" -ForegroundColor Cyan Write-Host " LD UNINSTALLER - SELF-HOSTED OTA DAĞITIM MOTORU" -ForegroundColor Cyan Write-Host "==========================================================" -ForegroundColor Cyan # 1. Anahtar ve Yapılandırma Kontrolü $KeyFile = Join-Path $ScriptDir ".keys\app.key" $TauriConfFile = Join-Path $ScriptDir "src-tauri\tauri.conf.json" $DistServerDir = Join-Path $ScriptDir "dist_server" if (-not (Test-Path $KeyFile)) { Write-Host "[HATA] Minisign özel anahtarı (.keys\app.key) bulunamadı!" -ForegroundColor Red exit 1 } $TauriConf = Get-Content $TauriConfFile -Raw | ConvertFrom-Json $Version = $TauriConf.version Write-Host "[1/5] Hedef Sürüm: v$Version" -ForegroundColor Green if (-not (Test-Path $DistServerDir)) { New-Item -ItemType Directory -Path $DistServerDir -Force | Out-Null } if (-not $UploadOnly) { # 2. Özel İmza Anahtarını Ortam Değişkenine Yükle Write-Host "[2/5] Minisign anahtarı yükleniyor ve derleme başlatılıyor..." -ForegroundColor Yellow $env:TAURI_SIGNING_PRIVATE_KEY_PATH = $KeyFile $env:TAURI_SIGNING_PRIVATE_KEY = (Get-Content $KeyFile -Raw).Trim() # Frontend Build Write-Host " -> Frontend derleniyor (tsc & vite build)..." -ForegroundColor Gray npm run build if ($LASTEXITCODE -ne 0) { Write-Host "[HATA] Frontend derlemesi başarısız oldu!" -ForegroundColor Red exit 1 } # Tauri Bundle Write-Host " -> Tauri v2 imzalı kurulum paketi üretiliyor (tauri build)..." -ForegroundColor Gray npx @tauri-apps/cli build if ($LASTEXITCODE -ne 0) { Write-Host "[UYARI] Standart tauri build sonlandı, çıktılar kontrol ediliyor..." -ForegroundColor Yellow } # Portable & Kaynak ZIP Üretimi Write-Host " -> Taşınabilir (Portable ZIP) ve Kaynak ZIP paketleniyor..." -ForegroundColor Gray $tempPortable = Join-Path $ScriptDir "dist_server\portable_staging" if (Test-Path $tempPortable) { Remove-Item $tempPortable -Recurse -Force } New-Item -ItemType Directory -Path $tempPortable -Force | Out-Null $releaseExe = "C:\Users\lildosto\ld_target\release\ld_uninstaller.exe" if (-not (Test-Path $releaseExe)) { $releaseExe = "$ScriptDir\src-tauri\target\release\ld_uninstaller.exe" } if (Test-Path $releaseExe) { Copy-Item $releaseExe -Destination "$tempPortable\LD Uninstaller.exe" $w2l = Join-Path (Split-Path $releaseExe) "WebView2Loader.dll" if (Test-Path $w2l) { Copy-Item $w2l -Destination "$tempPortable\WebView2Loader.dll" } $portableZip = Join-Path $DistServerDir "LD-Uninstaller-v${Version}-portable.zip" if (Test-Path $portableZip) { Remove-Item $portableZip -Force } Compress-Archive -Path "$tempPortable\*" -DestinationPath $portableZip -CompressionLevel Optimal } Remove-Item $tempPortable -Recurse -Force -ErrorAction SilentlyContinue $sourceZip = Join-Path $DistServerDir "ld-uninstaller-source.zip" if (Test-Path $sourceZip) { Remove-Item $sourceZip -Force } git archive --format=zip --output=$sourceZip HEAD 2>$null # 3. Üretilen Paketleri ve İmzaları Tespit Et Write-Host "[3/5] Kurulum paketleri ve kriptografik imzalar taranıyor..." -ForegroundColor Yellow # Olası hedef dizinler: C:\Users\lildosto\ld_target veya src-tauri\target $SearchLocations = @( "C:\Users\lildosto\ld_target\release\bundle\nsis", "$ScriptDir\src-tauri\target\release\bundle\nsis", "C:\Users\lildosto\ld_target\release", "$ScriptDir\src-tauri\target\release" ) $SetupExe = $null $SigFile = $null foreach ($loc in $SearchLocations) { if (Test-Path $loc) { $foundExe = Get-ChildItem -Path $loc -Filter "*setup*.exe" -File -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 if ($foundExe) { $SetupExe = $foundExe $possibleSig = "$($foundExe.FullName).sig" if (Test-Path $possibleSig) { $SigFile = Get-Item $possibleSig } break } } } # Eğer tauri build nsis yerine farklı bir isimle ürettiyse veya ilk derlemede zip/sig formatındaysa if ($SetupExe) { $DestExeName = "LD-Uninstaller_${Version}_x64-setup.exe" $DestExePath = Join-Path $DistServerDir $DestExeName Copy-Item -Path $SetupExe.FullName -Destination $DestExePath -Force Write-Host " -> Kurulum dosyası kopyalandı: $DestExeName" -ForegroundColor Green $Signature = "" if ($SigFile -and (Test-Path $SigFile.FullName)) { $Signature = (Get-Content $SigFile.FullName -Raw).Trim() Copy-Item -Path $SigFile.FullName -Destination "$DestExePath.sig" -Force Write-Host " -> Minisign imzası alındı: $($SigFile.Name)" -ForegroundColor Green } else { # Elle imzala Write-Host " -> İmza dosyası aranıyor / oluşturuluyor..." -ForegroundColor Gray $sigOutput = npx @tauri-apps/cli signer sign -k $KeyFile $DestExePath if (Test-Path "$DestExePath.sig") { $Signature = (Get-Content "$DestExePath.sig" -Raw).Trim() } } # SHA256 Hesapla $Hash = (Get-FileHash -Path $DestExePath -Algorithm SHA256).Hash # 4. latest.json Oluştur (Tauri v2 OTA Şeması) Write-Host "[4/5] Self-hosted 'latest.json' güncelleme manifesti üretiliyor..." -ForegroundColor Yellow $PubDate = [DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ") $UpdateUrl = "https://ttmadethat.shop/updates/ld-uninstaller/$DestExeName" $LatestManifest = @{ version = "v$Version" notes = $Notes pub_date = $PubDate platforms = @{ "windows-x86_64" = @{ signature = $Signature url = $UpdateUrl } } } $JsonContent = $LatestManifest | ConvertTo-Json -Depth 5 $LatestJsonPath = Join-Path $DistServerDir "latest.json" [System.IO.File]::WriteAllText($LatestJsonPath, $JsonContent, [System.Text.Encoding]::UTF8) # SHA256 Özet Dosyası $ShaSummary = "DOSYA: $DestExeName`nSHA256: $Hash`nTARIH: $PubDate`nURL: $UpdateUrl`n" [System.IO.File]::WriteAllText((Join-Path $DistServerDir "sha256.txt"), $ShaSummary, [System.Text.Encoding]::UTF8) Write-Host " -> 'dist_server\latest.json' başarıyla oluşturuldu." -ForegroundColor Green } else { Write-Host "[BİLGİ] Setup dosyası henüz oluşturulmadıysa simüle manifest hazırlandı." -ForegroundColor Gray $DestExeName = "LD-Uninstaller_${Version}_x64-setup.exe" $LatestJsonPath = Join-Path $DistServerDir "latest.json" $LatestManifest = @{ version = "v$Version" notes = $Notes pub_date = [DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ") platforms = @{ "windows-x86_64" = @{ signature = "TEST_SIGNATURE" url = "https://ttmadethat.shop/updates/ld-uninstaller/$DestExeName" } } } $JsonContent = $LatestManifest | ConvertTo-Json -Depth 5 [System.IO.File]::WriteAllText($LatestJsonPath, $JsonContent, [System.Text.Encoding]::UTF8) } } # 5. Sunucu Dağıtım Durumu (bağlan.bat Entegrasyonu) Write-Host "[5/5] Sunucu bağlantı ve dağıtım durumu kontrol ediliyor..." -ForegroundColor Yellow $ServerIP = "116.202.14.171" $SSHKey = "$env:USERPROFILE\.ssh\id_ed25519" $RemoteDir = "/opt/tylorindar-safelink/static/updates/ld-uninstaller" $RemoteDownloadsDir = "/opt/tylorindar-safelink/static/downloads/ld-apps" if ($SkipUpload) { Write-Host "`n[BİLGİ] -SkipUpload parametresi nedeniyle sunucuya yükleme yapılmadı." -ForegroundColor Cyan Write-Host "Tüm dağıtım paketleri hazır: '$DistServerDir'" -ForegroundColor Green exit 0 } Write-Host " -> Sunucu SSH port kontrolü yapılıyor ($ServerIP:22)..." -ForegroundColor Gray $tcpCheck = $false try { $tcpClient = New-Object System.Net.Sockets.TcpClient $iar = $tcpClient.BeginConnect($ServerIP, 22, $null, $null) $wait = $iar.AsyncWaitHandle.WaitOne(3000, $false) if ($wait -and $tcpClient.Connected) { $tcpCheck = $true } $tcpClient.Close() } catch { $tcpCheck = $false } if (-not $tcpCheck) { Write-Host "`n--------------------------------------------------------------------------" -ForegroundColor Yellow Write-Host "[BİLGİ] Sunucunuz şu anda askıda veya çevrimdışı durumda ($ServerIP:22)." -ForegroundColor Yellow Write-Host "Tüm OTA güncelleme dosyaları, kurulum paketi ve 'latest.json' yerel olarak" -ForegroundColor Yellow Write-Host "'$DistServerDir' klasörüne EKSİKSİZ hazırlandı." -ForegroundColor Yellow Write-Host "`nSunucunuz tekrar aktif hale geldiğinde tek bir komutla yüklemek için:" -ForegroundColor Green Write-Host " .\publish.ps1 -UploadOnly" -ForegroundColor Cyan Write-Host "--------------------------------------------------------------------------" -ForegroundColor Yellow exit 0 } # Sunucu açıksa SCP ile yükle try { Write-Host " -> Sunucuda güncelleme klasörü oluşturuluyor ($RemoteDir)..." -ForegroundColor Gray ssh -i $SSHKey -o ConnectTimeout=5 root@$ServerIP "mkdir -p $RemoteDir $RemoteDownloadsDir" Write-Host " -> Dosyalar sunucuya aktarılıyor (SCP)..." -ForegroundColor Gray scp -i $SSHKey -o ConnectTimeout=15 "$DistServerDir\*" root@${ServerIP}:${RemoteDir}/ scp -i $SSHKey -o ConnectTimeout=15 "$DistServerDir\LD-Uninstaller_${Version}_x64-setup.exe" root@${ServerIP}:${RemoteDownloadsDir}/LD-Uninstaller-Setup-v${Version}.exe scp -i $SSHKey -o ConnectTimeout=15 "$DistServerDir\LD-Uninstaller_${Version}_x64-setup.exe" root@${ServerIP}:${RemoteDownloadsDir}/LD-Uninstaller-Setup-latest.exe $portableUpload = Join-Path $DistServerDir "LD-Uninstaller-v${Version}-portable.zip" if (Test-Path $portableUpload) { scp -i $SSHKey -o ConnectTimeout=15 $portableUpload root@${ServerIP}:${RemoteDownloadsDir}/ } $sourceUpload = Join-Path $DistServerDir "ld-uninstaller-source.zip" if (Test-Path $sourceUpload) { scp -i $SSHKey -o ConnectTimeout=15 $sourceUpload root@${ServerIP}:${RemoteDownloadsDir}/ } $readmeUpload = Join-Path $DistServerDir "ld-uninstaller-README.md" if (Test-Path $readmeUpload) { scp -i $SSHKey -o ConnectTimeout=15 $readmeUpload root@${ServerIP}:${RemoteDownloadsDir}/readmes/ld-uninstaller-README.md } ssh -i $SSHKey -o ConnectTimeout=5 root@$ServerIP "chmod -R 755 $RemoteDir; docker restart tylorindar-safelink-hub >/dev/null 2>&1" Write-Host "`n[BAŞARILI] Sürüm v$Version kendi web sitene başarıyla yayınlandı!" -ForegroundColor Green Write-Host "OTA Manifest URL: https://ttmadethat.shop/updates/ld-uninstaller/latest.json" -ForegroundColor Cyan Write-Host "Setup İndirme URL: https://ttmadethat.shop/updates/ld-uninstaller/LD-Uninstaller_${Version}_x64-setup.exe" -ForegroundColor Cyan } catch { Write-Host "`n[UYARI] Sunucuya bağlanırken bir hata oluştu: $_" -ForegroundColor Yellow Write-Host "Dosyalar '$DistServerDir' dizininde korundu. Sunucu açıldığında '.\publish.ps1 -UploadOnly' çalıştırabilirsiniz." -ForegroundColor Cyan }