49 lines
2.1 KiB
PowerShell
49 lines
2.1 KiB
PowerShell
# -----------------------------
|
|
# تنظیمات
|
|
# -----------------------------
|
|
$LocalPath = $PSScriptRoot # مسیر پروژه روی ویندوز (همان پوشهای که اسکریپت در آن است)
|
|
$PiUser = "pars" # کاربر روی Raspberry Pi
|
|
$PiHost = "10.63.136.150" # آیپی Raspberry Pi
|
|
$RemotePath = "/home/pars/Desktop" # مسیر پروژه روی Pi
|
|
$ProjectFolder = "saba-python" # نام پوشه پروژه
|
|
$MainPy = "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__" --exclude=".runtime-venv" $FolderName
|
|
scp deploy.tar "$PiUser@$PiHost`:$RemotePath/deploy.tar"
|
|
ssh "$PiUser@$PiHost" "cd $RemotePath && rm -rf $ProjectFolder && tar -xf deploy.tar && rm deploy.tar"
|
|
Remove-Item $DeployTar
|
|
Set-Location $LocalPath
|
|
|
|
# -----------------------------
|
|
# اجرای برنامه روی Raspberry Pi
|