44 lines
1.8 KiB
PowerShell
44 lines
1.8 KiB
PowerShell
# -----------------------------
|
|
# تنظیمات
|
|
# -----------------------------
|
|
$LocalPath = "C:\Users\Pars\Desktop\saba-python" # مسیر پروژه روی ویندوز
|
|
$PiUser = "pars" # کاربر روی Raspberry Pi
|
|
$PiHost = "10.65.40.150" # آیپی 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
|
|
|
|
# -----------------------------
|
|
# انتقال پروژه با scp
|
|
# -----------------------------
|
|
Write-Host "Transferring project to Raspberry Pi..."
|
|
$scpTarget = "$PiUser@$PiHost`:$RemotePath"
|
|
scp -r $LocalPath $scpTarget
|
|
|
|
# -----------------------------
|
|
# اجرای برنامه روی 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 |