# ----------------------------- # تنظیمات # ----------------------------- $LocalPath = "C:\Users\Pars\Desktop\saba-python" # مسیر پروژه روی ویندوز $PiUser = "pars" # کاربر روی Raspberry Pi $PiHost = "192.168.1.25" # آی‌پی Raspberry Pi $RemotePath = "/home/pars/Desktop/" # مسیر پروژه روی Pi $MainPy = "saba-python/main.py" # فایل اصلی پایتون $KeyPath = "$env:USERPROFILE\.ssh\id_ed25519" # ----------------------------- # ساخت کلید SSH اگر موجود نباشد # ----------------------------- if (-not (Test-Path $KeyPath)) { Write-Host "Generating SSH key..." ssh-keygen -t ed25519 -f $KeyPath -N "" -C "$PiUser@windows" } else { Write-Host "SSH key already exists." } # ----------------------------- # اضافه کردن کلید به Pi (رمز یک بار لازم است) # ----------------------------- Write-Host "Copying public key to Raspberry Pi..." $pubKey = Get-Content "$KeyPath.pub" # دستور برای اضافه کردن کلید به authorized_keys روی Pi $command = "mkdir -p ~/.ssh; chmod 700 ~/.ssh; echo '$pubKey' >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys" ssh "$PiUser@$PiHost" $command # ----------------------------- # انتقال پروژه (بدون فایل‌های مخفی) # ----------------------------- Write-Host "Transferring project to Raspberry Pi (excluding .git)..." $ParentDir = Split-Path $LocalPath -Parent $FolderName = Split-Path $LocalPath -Leaf $DeployTar = "$ParentDir\deploy.tar" Set-Location $ParentDir tar.exe -cf deploy.tar --exclude=".git" --exclude="__pycache__" $FolderName scp deploy.tar "$PiUser@$PiHost`:$RemotePath/deploy.tar" ssh "$PiUser@$PiHost" "cd $RemotePath && tar -xf deploy.tar && rm deploy.tar" Remove-Item $DeployTar Set-Location $LocalPath # ----------------------------- # اجرای برنامه روی Raspberry Pi # ----------------------------- Write-Host "Running program on Raspberry Pi..." ssh "$PiUser@$PiHost" "cd $RemotePath && python3 $MainPy" Write-Host "Deployment complete! Latest version is running on Raspberry Pi." -ForegroundColor Green