50 lines
1.3 KiB
Bash
Executable File
50 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PROJECT_ROOT="$SCRIPT_DIR/.."
|
|
VM_DIR="$PROJECT_ROOT/.nogit/vm"
|
|
SCREENSHOT_DIR="$PROJECT_ROOT/.nogit/screenshots"
|
|
MONITOR_SOCK="$VM_DIR/qemu-monitor.sock"
|
|
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
|
|
|
|
# Check if QEMU is running
|
|
if [ ! -S "$MONITOR_SOCK" ]; then
|
|
echo "ERROR: QEMU not running (no monitor socket)"
|
|
echo "Run 'pnpm run test' first to start the VM"
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$SCREENSHOT_DIR"
|
|
PPM_FILE="$SCREENSHOT_DIR/ecoos-$TIMESTAMP.ppm"
|
|
PNG_FILE="$SCREENSHOT_DIR/ecoos-$TIMESTAMP.png"
|
|
LATEST_FILE="$SCREENSHOT_DIR/latest.png"
|
|
|
|
echo "Taking screenshot..."
|
|
echo "screendump $PPM_FILE" | socat - UNIX-CONNECT:"$MONITOR_SOCK"
|
|
sleep 1
|
|
|
|
# Check if PPM was created
|
|
if [ ! -f "$PPM_FILE" ]; then
|
|
echo "ERROR: Screenshot failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Convert to PNG if imagemagick is available
|
|
if command -v convert &> /dev/null; then
|
|
convert "$PPM_FILE" "$PNG_FILE"
|
|
rm "$PPM_FILE"
|
|
|
|
# Copy to latest.png
|
|
cp "$PNG_FILE" "$LATEST_FILE"
|
|
|
|
echo "Screenshot saved: $PNG_FILE"
|
|
echo "Also saved as: $LATEST_FILE"
|
|
else
|
|
echo "Screenshot saved: $PPM_FILE"
|
|
echo "(Install imagemagick to auto-convert to PNG)"
|
|
fi
|
|
|
|
# Keep only last 20 screenshots (excluding latest.png)
|
|
cd "$SCREENSHOT_DIR"
|
|
ls -t ecoos-*.png 2>/dev/null | tail -n +21 | xargs -r rm -f
|