# Auto run database setup with password $ErrorActionPreference = "Stop" Write-Host "========================================" -ForegroundColor Cyan Write-Host " HR Portal Database Auto Setup" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" $REMOTE_HOST = "10.1.0.254" $REMOTE_USER = "ubuntu" $PASSWORD = "DC1qaz2wsx" $LOCAL_SCRIPT = "W:\DevOps-Workspace\hr-portal\scripts\auto-setup.sh" # Step 1: Upload script using plink (PuTTY) Write-Host "[1/3] Uploading setup script..." -ForegroundColor Yellow # Create expect-like script for SSH $uploadCommand = @" `$password = '$PASSWORD' `$process = Start-Process plink -ArgumentList "-ssh $REMOTE_USER@$REMOTE_HOST -pw `$password 'cat > /tmp/auto-setup.sh'" -NoNewWindow -Wait -RedirectStandardInput '$LOCAL_SCRIPT' -PassThru "@ # Fallback: Try with cmd echo Write-Host " Trying direct SSH connection..." -ForegroundColor Gray # Create a temporary script with password $tempScript = @" #!/usr/bin/expect -f set timeout 60 spawn scp $LOCAL_SCRIPT ${REMOTE_USER}@${REMOTE_HOST}:/tmp/auto-setup.sh expect "password:" send "${PASSWORD}\r" expect eof "@ # Write temp script $tempScriptPath = "$env:TEMP\upload-script.exp" $tempScript | Out-File -FilePath $tempScriptPath -Encoding ASCII # Try using WSL if available $wslAvailable = Get-Command wsl -ErrorAction SilentlyContinue if ($wslAvailable) { Write-Host " Using WSL for transfer..." -ForegroundColor Gray # Copy file to WSL $wslTempPath = "/tmp/auto-setup.sh" wsl cp "$LOCAL_SCRIPT" $wslTempPath # Use sshpass in WSL $result = wsl bash -c "sshpass -p '$PASSWORD' scp /tmp/auto-setup.sh ${REMOTE_USER}@${REMOTE_HOST}:/tmp/" if ($LASTEXITCODE -eq 0) { Write-Host " [OK] Script uploaded" -ForegroundColor Green } else { Write-Host " [FAIL] Upload failed" -ForegroundColor Red exit 1 } } else { # Manual method Write-Host "" Write-Host " WSL not available. Please manually upload the script:" -ForegroundColor Yellow Write-Host " 1. Open WinSCP or FileZilla" -ForegroundColor White Write-Host " 2. Connect to: ubuntu@10.1.0.254 (password: DC1qaz2wsx)" -ForegroundColor White Write-Host " 3. Upload: W:\DevOps-Workspace\hr-portal\scripts\auto-setup.sh" -ForegroundColor White Write-Host " 4. To: /tmp/auto-setup.sh" -ForegroundColor White Write-Host "" Read-Host "Press Enter after upload completes" } Write-Host "" # Step 2: Make executable and run Write-Host "[2/3] Executing setup on remote server..." -ForegroundColor Yellow if ($wslAvailable) { $executeCommands = @" chmod +x /tmp/auto-setup.sh bash /tmp/auto-setup.sh "@ $result = wsl bash -c "sshpass -p '$PASSWORD' ssh -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} '$executeCommands'" Write-Host $result if ($LASTEXITCODE -eq 0) { Write-Host "" Write-Host " [OK] Setup completed!" -ForegroundColor Green } else { Write-Host " [WARNING] Check output above for any errors" -ForegroundColor Yellow } } else { Write-Host " Please run these commands on Ubuntu Server:" -ForegroundColor Yellow Write-Host " chmod +x /tmp/auto-setup.sh" -ForegroundColor White Write-Host " bash /tmp/auto-setup.sh" -ForegroundColor White Write-Host "" } Write-Host "" Write-Host "[3/3] Database connection info:" -ForegroundColor Yellow Write-Host "" Write-Host " CONNECTION STRING:" -ForegroundColor Cyan Write-Host " postgresql://hr_user:DC1qaz2wsx@10.1.0.254:5432/hr_portal" -ForegroundColor White Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host " Next: Update backend/.env file" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host ""