update at 2026-03-17 10:37:27
This commit is contained in:
64
scripts/capture-kindle-screen.sh
Normal file
64
scripts/capture-kindle-screen.sh
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
ROOT_DIR=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
||||
HOST_TARGET=${1:-kindle}
|
||||
OUTPUT_BASENAME=${2:-current-screen}
|
||||
OUTPUT_DIR=${3:-"$ROOT_DIR/tmp"}
|
||||
RUNTIME_ENV_PATH=/mnt/us/dashboard/local/state/theme-runtime.env
|
||||
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
raw_path="$OUTPUT_DIR/${OUTPUT_BASENAME}-raw.png"
|
||||
physical_path="$OUTPUT_DIR/${OUTPUT_BASENAME}-physical.png"
|
||||
tmp_download_path="$OUTPUT_DIR/${OUTPUT_BASENAME}-download.tmp"
|
||||
|
||||
read_remote_value() {
|
||||
key=$1
|
||||
ssh "$HOST_TARGET" "awk -F= '/^export ${key}=/{gsub(\"\\047\", \"\", \$2); print \$2; exit}' \"$RUNTIME_ENV_PATH\" 2>/dev/null || true"
|
||||
}
|
||||
|
||||
orientation=$(read_remote_value ORIENTATION)
|
||||
device_placement=$(read_remote_value THEME_DEVICE_PLACEMENT)
|
||||
|
||||
ssh "$HOST_TARGET" '
|
||||
set -eu
|
||||
capture_path="/tmp/kindle-dashboard-capture-$$.png"
|
||||
fbgrab "$capture_path" >/dev/null 2>&1
|
||||
cat "$capture_path"
|
||||
rm -f "$capture_path"
|
||||
' >"$tmp_download_path"
|
||||
|
||||
python3 - "$tmp_download_path" "$raw_path" <<'PY'
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
download_path = Path(sys.argv[1])
|
||||
raw_path = Path(sys.argv[2])
|
||||
data = download_path.read_bytes()
|
||||
magic = b"\x89PNG\r\n\x1a\n"
|
||||
index = data.find(magic)
|
||||
if index == -1:
|
||||
raise SystemExit("抓屏结果里没有找到 PNG 头")
|
||||
|
||||
raw_path.write_bytes(data[index:])
|
||||
download_path.unlink(missing_ok=True)
|
||||
PY
|
||||
|
||||
case "$orientation:$device_placement" in
|
||||
landscape:logo_right)
|
||||
cp "$raw_path" "$physical_path"
|
||||
# 原始 fbgrab 输出始终是纵向 framebuffer。
|
||||
# Logo 在右侧时,日常评审应优先看 physical 图;
|
||||
# 它等于把 raw 图按设备实际摆放方向逆时针旋转 90 度。
|
||||
sips -r 270 "$physical_path" >/dev/null
|
||||
;;
|
||||
*)
|
||||
cp "$raw_path" "$physical_path"
|
||||
;;
|
||||
esac
|
||||
|
||||
printf 'raw=%s\n' "$raw_path"
|
||||
printf 'physical=%s\n' "$physical_path"
|
||||
printf 'orientation=%s\n' "${orientation:-unknown}"
|
||||
printf 'devicePlacement=%s\n' "${device_placement:-unknown}"
|
||||
Reference in New Issue
Block a user