196 lines
8.9 KiB
PowerShell
196 lines
8.9 KiB
PowerShell
# ==============================================================================
|
||
# 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
|
||
}
|
||
|
||
# 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 = "/var/www/ttmadethat.shop/updates/ld-uninstaller"
|
||
|
||
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 ping / erişim kontrolü yapılıyor ($ServerIP)..." -ForegroundColor Gray
|
||
$ping = Test-Connection -ComputerName $ServerIP -Count 1 -Quiet -ErrorAction SilentlyContinue
|
||
|
||
if (-not $ping) {
|
||
Write-Host "`n--------------------------------------------------------------------------" -ForegroundColor Yellow
|
||
Write-Host "[BİLGİ] Sunucunuz şu anda askıda veya çevrimdışı durumda ($ServerIP)." -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"
|
||
|
||
Write-Host " -> Dosyalar sunucuya aktarılıyor (SCP)..." -ForegroundColor Gray
|
||
scp -i $SSHKey -o ConnectTimeout=10 "$DistServerDir\*" root@${ServerIP}:${RemoteDir}/
|
||
|
||
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
|
||
} catch {
|
||
Write-Host "`n[UYARI] Sunucuya bağlanırken zaman aşımı oluştu: $_" -ForegroundColor Yellow
|
||
Write-Host "Dosyalar '$DistServerDir' dizininde korundu. Sunucu açıldığında '.\publish.ps1 -UploadOnly' çalıştırabilirsiniz." -ForegroundColor Cyan
|
||
}
|