update at 2026-03-21 18:44:12
This commit is contained in:
@@ -21,11 +21,17 @@ echo "Source keys: ${SOURCE_KEYS}"
|
||||
|
||||
for target_dir in "${ROOT_HOME}/.ssh" /root/.ssh /var/local/root/.ssh /mnt/us/usbnet/etc/dot.ssh; do
|
||||
echo "--- target: ${target_dir} ---"
|
||||
mkdir -p "${target_dir}"
|
||||
if ! mkdir -p "${target_dir}" 2>/dev/null; then
|
||||
echo "skip: cannot create ${target_dir}"
|
||||
continue
|
||||
fi
|
||||
if [ -f "${target_dir}/authorized_keys" ]; then
|
||||
cp "${target_dir}/authorized_keys" "${target_dir}/authorized_keys.bak.${TS}" || true
|
||||
fi
|
||||
cp "${SOURCE_KEYS}" "${target_dir}/authorized_keys"
|
||||
if ! cp "${SOURCE_KEYS}" "${target_dir}/authorized_keys"; then
|
||||
echo "skip: cannot write ${target_dir}/authorized_keys"
|
||||
continue
|
||||
fi
|
||||
chmod 700 "${target_dir}" 2>/dev/null || true
|
||||
chmod 600 "${target_dir}/authorized_keys" 2>/dev/null || true
|
||||
ls -ld "${target_dir}" "${target_dir}/authorized_keys" 2>/dev/null || true
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>cn.biboer.kindle-dash.refresh-kindle-backgrounds</string>
|
||||
|
||||
<key>WorkingDirectory</key>
|
||||
<string>/Users/gavin/kindle-dash</string>
|
||||
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/bin/sh</string>
|
||||
<string>/Users/gavin/kindle-dash/scripts/refresh-kindle-backgrounds.sh</string>
|
||||
<string>--once</string>
|
||||
</array>
|
||||
|
||||
<key>EnvironmentVariables</key>
|
||||
<dict>
|
||||
<key>PATH</key>
|
||||
<string>/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
||||
</dict>
|
||||
|
||||
<key>ProcessType</key>
|
||||
<string>Background</string>
|
||||
|
||||
<key>StandardOutPath</key>
|
||||
<string>/Users/gavin/Library/Logs/kindle-dash/refresh-kindle-backgrounds.log</string>
|
||||
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/Users/gavin/Library/Logs/kindle-dash/refresh-kindle-backgrounds.err.log</string>
|
||||
|
||||
<key>StartCalendarInterval</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>0</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>2</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>4</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>6</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>8</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>10</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>12</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>14</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>16</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>18</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>20</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>22</integer>
|
||||
<key>Minute</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
162
scripts/publish-calendar-dist.sh
Normal file
162
scripts/publish-calendar-dist.sh
Normal file
@@ -0,0 +1,162 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
ROOT_DIR="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
|
||||
CALENDAR_DIR="$ROOT_DIR/calendar"
|
||||
DIST_DIR="$CALENDAR_DIR/dist"
|
||||
|
||||
OUTPUT_DIR=""
|
||||
INTERVAL_MINUTES=60
|
||||
RUN_ONCE=false
|
||||
|
||||
print_usage() {
|
||||
cat <<'EOF'
|
||||
用法:
|
||||
sh scripts/publish-calendar-dist.sh --output-dir <dir> [选项]
|
||||
|
||||
作用:
|
||||
1. 调用 calendar 现有导出链路生成最新背景图与主题资源
|
||||
2. 把 calendar/dist 整体发布到指定目录
|
||||
3. 默认每 60 分钟自动重跑一次;加 --once 只跑一轮
|
||||
|
||||
选项:
|
||||
-o, --output-dir <dir> 发布目标目录,通常是 Web 服务器实际对外提供静态文件的目录
|
||||
--interval-minutes <n> 自动生成间隔,默认 60 分钟
|
||||
--once 只生成并发布一轮
|
||||
-h, --help 查看帮助
|
||||
|
||||
示例:
|
||||
sh scripts/publish-calendar-dist.sh --output-dir /srv/calendar-dashboard --once
|
||||
sh scripts/publish-calendar-dist.sh --output-dir /srv/calendar-dashboard
|
||||
EOF
|
||||
}
|
||||
|
||||
log() {
|
||||
printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$1"
|
||||
}
|
||||
|
||||
validate_positive_integer() {
|
||||
value=$1
|
||||
name=$2
|
||||
|
||||
case "$value" in
|
||||
''|*[!0-9]*)
|
||||
echo "$name 必须是正整数:$value" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$value" -le 0 ]; then
|
||||
echo "$name 必须大于 0:$value" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
publish_once() {
|
||||
temp_publish_dir=$(mktemp -d "${TMPDIR:-/tmp}/kindle-dash-publish.XXXXXX")
|
||||
publish_status=0
|
||||
|
||||
log "开始生成 Web 端背景图与主题资源"
|
||||
(
|
||||
cd "$CALENDAR_DIR"
|
||||
npm run export:themes
|
||||
) || publish_status=$?
|
||||
|
||||
if [ "$publish_status" -ne 0 ]; then
|
||||
rm -rf "$temp_publish_dir"
|
||||
return "$publish_status"
|
||||
fi
|
||||
|
||||
log "开始发布到目标目录:$OUTPUT_DIR"
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# 先把本轮导出结果完整复制到临时目录,确认结构无误后再整体 rsync 到目标目录,
|
||||
# 避免 Web 根目录在导出过程中暴露半成品文件。
|
||||
rsync -a --delete "$DIST_DIR"/ "$temp_publish_dir"/ || publish_status=$?
|
||||
if [ "$publish_status" -eq 0 ]; then
|
||||
rsync -a --delete "$temp_publish_dir"/ "$OUTPUT_DIR"/ || publish_status=$?
|
||||
fi
|
||||
|
||||
rm -rf "$temp_publish_dir"
|
||||
|
||||
if [ "$publish_status" -ne 0 ]; then
|
||||
return "$publish_status"
|
||||
fi
|
||||
|
||||
log "发布完成:$OUTPUT_DIR"
|
||||
}
|
||||
|
||||
sleep_until_next_run() {
|
||||
interval_seconds=$((INTERVAL_MINUTES * 60))
|
||||
now_epoch=$(date '+%s')
|
||||
next_epoch=$(( ((now_epoch / interval_seconds) + 1) * interval_seconds ))
|
||||
sleep_seconds=$((next_epoch - now_epoch))
|
||||
|
||||
if [ "$sleep_seconds" -le 0 ]; then
|
||||
sleep_seconds=$interval_seconds
|
||||
fi
|
||||
|
||||
log "等待 ${sleep_seconds} 秒后执行下一轮生成"
|
||||
sleep "$sleep_seconds"
|
||||
}
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o|--output-dir)
|
||||
shift
|
||||
OUTPUT_DIR=${1:?"missing output dir"}
|
||||
;;
|
||||
--interval-minutes)
|
||||
shift
|
||||
INTERVAL_MINUTES=${1:?"missing interval minutes"}
|
||||
;;
|
||||
--once)
|
||||
RUN_ONCE=true
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "未知参数: $1" >&2
|
||||
echo >&2
|
||||
print_usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "$OUTPUT_DIR" ]; then
|
||||
echo "必须通过 --output-dir 指定发布目录。" >&2
|
||||
echo >&2
|
||||
print_usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
validate_positive_integer "$INTERVAL_MINUTES" "interval-minutes"
|
||||
|
||||
# 当前导图链路依赖 macOS 自带的 Swift + WKWebView。
|
||||
# 如果部署机不是 macOS,这一步会失败,届时需要单独换成跨平台截图方案。
|
||||
if [ ! -x /usr/bin/swift ]; then
|
||||
echo "未找到 /usr/bin/swift,当前机器无法使用现有 WebKit 导图链路。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while true; do
|
||||
if publish_once; then
|
||||
:
|
||||
else
|
||||
status=$?
|
||||
log "本轮发布失败,退出码:$status"
|
||||
if [ "$RUN_ONCE" = true ]; then
|
||||
exit "$status"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$RUN_ONCE" = true ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
sleep_until_next_run
|
||||
done
|
||||
115
scripts/refresh-kindle-backgrounds.sh
Normal file
115
scripts/refresh-kindle-backgrounds.sh
Normal file
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
ROOT_DIR="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
|
||||
CALENDAR_DIR="$ROOT_DIR/calendar"
|
||||
INTERVAL_MINUTES=60
|
||||
RUN_ONCE=false
|
||||
|
||||
print_usage() {
|
||||
cat <<'EOF'
|
||||
用法:
|
||||
sh scripts/refresh-kindle-backgrounds.sh [选项]
|
||||
|
||||
作用:
|
||||
1. 构建 calendar Web 产物
|
||||
2. 生成主题背景图到 calendar/kindle-backgrounds/
|
||||
3. 默认每 60 分钟重跑一次;加 --once 只跑一轮
|
||||
|
||||
选项:
|
||||
--interval-minutes <n> 自动生成间隔,默认 60 分钟
|
||||
--once 只生成一轮
|
||||
-h, --help 查看帮助
|
||||
|
||||
示例:
|
||||
sh scripts/refresh-kindle-backgrounds.sh --once
|
||||
sh scripts/refresh-kindle-backgrounds.sh --interval-minutes 30
|
||||
EOF
|
||||
}
|
||||
|
||||
log() {
|
||||
printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$1"
|
||||
}
|
||||
|
||||
validate_positive_integer() {
|
||||
value=$1
|
||||
name=$2
|
||||
|
||||
case "$value" in
|
||||
''|*[!0-9]*)
|
||||
echo "$name 必须是正整数:$value" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$value" -le 0 ]; then
|
||||
echo "$name 必须大于 0:$value" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
refresh_once() {
|
||||
log "开始生成 Kindle 背景图到 $CALENDAR_DIR/kindle-backgrounds"
|
||||
(
|
||||
cd "$CALENDAR_DIR"
|
||||
npm run export:themes
|
||||
)
|
||||
log "背景图生成完成"
|
||||
}
|
||||
|
||||
sleep_until_next_run() {
|
||||
interval_seconds=$((INTERVAL_MINUTES * 60))
|
||||
now_epoch=$(date '+%s')
|
||||
next_epoch=$(( ((now_epoch / interval_seconds) + 1) * interval_seconds ))
|
||||
sleep_seconds=$((next_epoch - now_epoch))
|
||||
|
||||
if [ "$sleep_seconds" -le 0 ]; then
|
||||
sleep_seconds=$interval_seconds
|
||||
fi
|
||||
|
||||
log "等待 ${sleep_seconds} 秒后执行下一轮生成"
|
||||
sleep "$sleep_seconds"
|
||||
}
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--interval-minutes)
|
||||
shift
|
||||
INTERVAL_MINUTES=${1:?"missing interval minutes"}
|
||||
;;
|
||||
--once)
|
||||
RUN_ONCE=true
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "未知参数: $1" >&2
|
||||
echo >&2
|
||||
print_usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
validate_positive_integer "$INTERVAL_MINUTES" "interval-minutes"
|
||||
|
||||
while true; do
|
||||
if refresh_once; then
|
||||
:
|
||||
else
|
||||
status=$?
|
||||
log "本轮背景图生成失败,退出码:$status"
|
||||
if [ "$RUN_ONCE" = true ]; then
|
||||
exit "$status"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$RUN_ONCE" = true ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
sleep_until_next_run
|
||||
done
|
||||
@@ -6,6 +6,8 @@ KINDLE_TARGET="kindle"
|
||||
THEME_FILTER=""
|
||||
ORIENTATION_FILTER=""
|
||||
CLOCK_REGION_JSON="$ROOT_DIR/calendar/dist/clock-region.json"
|
||||
LOCATION_LAT=""
|
||||
LOCATION_LON=""
|
||||
|
||||
print_usage() {
|
||||
cat <<'EOF'
|
||||
@@ -50,20 +52,6 @@ if [ -n "$ORIENTATION_FILTER" ] && [ -z "$THEME_FILTER" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$ROOT_DIR/calendar"
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
npm run export:themes -- --theme "$THEME_FILTER" --orientation "$ORIENTATION_FILTER" >/dev/null
|
||||
CLOCK_REGION_JSON="$ROOT_DIR/calendar/dist/themes/$THEME_FILTER/$ORIENTATION_FILTER/kindlebg.clock-region.json"
|
||||
else
|
||||
npm run export:themes -- --theme "$THEME_FILTER" >/dev/null
|
||||
CLOCK_REGION_JSON=""
|
||||
fi
|
||||
else
|
||||
npm run export:themes >/dev/null
|
||||
fi
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
clock_region_value() {
|
||||
key=$1
|
||||
python3 - "$CLOCK_REGION_JSON" "$key" <<'PY'
|
||||
@@ -98,19 +86,69 @@ sync_dashboard_runtime() {
|
||||
"$ROOT_DIR/dash/src/local/env.sh" \
|
||||
"$ROOT_DIR/dash/src/local/fetch-dashboard.sh" \
|
||||
"$ROOT_DIR/dash/src/local/clock-index.sh" \
|
||||
"$ROOT_DIR/dash/src/local/location-env.sh" \
|
||||
"$ROOT_DIR/dash/src/local/location-sync.sh" \
|
||||
"$ROOT_DIR/dash/src/local/render-clock.lua" \
|
||||
"$ROOT_DIR/dash/src/local/render-clock.sh" \
|
||||
"$ROOT_DIR/dash/src/local/touch-home-service.sh" \
|
||||
"$ROOT_DIR/dash/src/local/theme-menu-service.sh" \
|
||||
"$ROOT_DIR/dash/src/local/theme-json.lua" \
|
||||
"$ROOT_DIR/dash/src/local/sync-theme-backgrounds.sh" \
|
||||
"$ROOT_DIR/dash/src/local/theme-sync.sh" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/local/
|
||||
|
||||
ssh "$KINDLE_TARGET" "chmod +x /mnt/us/dashboard/start.sh /mnt/us/dashboard/dash.sh /mnt/us/dashboard/stop.sh /mnt/us/dashboard/launch-from-kual.sh /mnt/us/dashboard/launch-theme-from-kual.sh /mnt/us/dashboard/switch-theme.sh /mnt/us/dashboard/local/fetch-dashboard.sh /mnt/us/dashboard/local/clock-index.sh /mnt/us/dashboard/local/render-clock.sh /mnt/us/dashboard/local/touch-home-service.sh /mnt/us/dashboard/local/theme-menu-service.sh /mnt/us/dashboard/local/theme-sync.sh"
|
||||
ssh "$KINDLE_TARGET" "chmod +x /mnt/us/dashboard/start.sh /mnt/us/dashboard/dash.sh /mnt/us/dashboard/stop.sh /mnt/us/dashboard/launch-from-kual.sh /mnt/us/dashboard/launch-theme-from-kual.sh /mnt/us/dashboard/switch-theme.sh /mnt/us/dashboard/local/fetch-dashboard.sh /mnt/us/dashboard/local/clock-index.sh /mnt/us/dashboard/local/location-env.sh /mnt/us/dashboard/local/location-sync.sh /mnt/us/dashboard/local/render-clock.sh /mnt/us/dashboard/local/touch-home-service.sh /mnt/us/dashboard/local/theme-menu-service.sh /mnt/us/dashboard/local/sync-theme-backgrounds.sh /mnt/us/dashboard/local/theme-sync.sh"
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/dashboard/local/state"
|
||||
ssh "$KINDLE_TARGET" "date '+%s' >/mnt/us/dashboard/local/state/background-updated-at"
|
||||
}
|
||||
|
||||
resolve_kindle_location_override() {
|
||||
location_output=""
|
||||
|
||||
if ! location_output=$(ssh "$KINDLE_TARGET" "/mnt/us/dashboard/local/location-env.sh --refresh-if-needed" 2>/dev/null); then
|
||||
echo "Skipped Kindle location override: unable to resolve remote location"
|
||||
return
|
||||
fi
|
||||
|
||||
LOCATION_LAT=$(printf '%s\n' "$location_output" | awk -F= '/^export LOCATION_LAT=/{gsub("'"'"'", "", $2); print $2; exit}')
|
||||
LOCATION_LON=$(printf '%s\n' "$location_output" | awk -F= '/^export LOCATION_LON=/{gsub("'"'"'", "", $2); print $2; exit}')
|
||||
|
||||
if [ -z "$LOCATION_LAT" ] || [ -z "$LOCATION_LON" ]; then
|
||||
echo "Skipped Kindle location override: remote coordinates unavailable"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Using Kindle location override: ${LOCATION_LAT},${LOCATION_LON}"
|
||||
}
|
||||
|
||||
export_theme_bundle_locally() {
|
||||
cd "$ROOT_DIR/calendar"
|
||||
set -- npm run export:themes --
|
||||
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
set -- "$@" --theme "$THEME_FILTER"
|
||||
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
set -- "$@" --orientation "$ORIENTATION_FILTER"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$LOCATION_LAT" ] && [ -n "$LOCATION_LON" ]; then
|
||||
set -- "$@" --location-lat "$LOCATION_LAT" --location-lon "$LOCATION_LON"
|
||||
fi
|
||||
|
||||
"$@" >/dev/null
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
CLOCK_REGION_JSON="$ROOT_DIR/calendar/dist/themes/$THEME_FILTER/$ORIENTATION_FILTER/kindlebg.clock-region.json"
|
||||
else
|
||||
CLOCK_REGION_JSON=""
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
sync_kual_extension() {
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/extensions/kindle-dash"
|
||||
rsync -av --no-o --no-g \
|
||||
@@ -124,15 +162,15 @@ sync_theme_bundle() {
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/
|
||||
|
||||
if [ -z "$THEME_FILTER" ]; then
|
||||
if [ -f "$ROOT_DIR/calendar/dist/kindlebg.png" ]; then
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/dist/kindlebg.png" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/
|
||||
fi
|
||||
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/dist/themes/" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/themes/
|
||||
|
||||
if [ -d "$ROOT_DIR/calendar/kindle-backgrounds" ]; then
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/kindle-backgrounds/" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/kindle-backgrounds/
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -140,6 +178,21 @@ sync_theme_bundle() {
|
||||
"$ROOT_DIR/calendar/dist/themes/$THEME_FILTER.json" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/themes/
|
||||
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/dashboard/kindle-backgrounds"
|
||||
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
flat_background_path="$ROOT_DIR/calendar/kindle-backgrounds/$THEME_FILTER-$ORIENTATION_FILTER.png"
|
||||
if [ -f "$flat_background_path" ]; then
|
||||
rsync -av --no-o --no-g \
|
||||
"$flat_background_path" \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/kindle-backgrounds/
|
||||
fi
|
||||
else
|
||||
rsync -av --no-o --no-g \
|
||||
"$ROOT_DIR/calendar/kindle-backgrounds/$THEME_FILTER-"*.png \
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/kindle-backgrounds/
|
||||
fi
|
||||
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
ssh "$KINDLE_TARGET" "mkdir -p /mnt/us/dashboard/themes/$THEME_FILTER/$ORIENTATION_FILTER"
|
||||
rsync -av --no-o --no-g \
|
||||
@@ -154,6 +207,40 @@ sync_theme_bundle() {
|
||||
"$KINDLE_TARGET":/mnt/us/dashboard/themes/$THEME_FILTER/
|
||||
}
|
||||
|
||||
refresh_current_background_cache() {
|
||||
# 不能再把本地默认导出的 kindlebg.png 直接覆盖到设备根目录;
|
||||
# 否则设备当前主题若不是默认主题,重启后就会出现“背景回默认、时钟还按旧主题画”的分叉。
|
||||
# 这里统一在 Kindle 端按当前 theme-runtime.env 重新生成根目录背景缓存。
|
||||
if ssh "$KINDLE_TARGET" "/mnt/us/dashboard/local/fetch-dashboard.sh --local-only /mnt/us/dashboard/kindlebg.png"; then
|
||||
ssh "$KINDLE_TARGET" "date '+%s' >/mnt/us/dashboard/local/state/background-updated-at"
|
||||
echo "Current background cache refreshed on device"
|
||||
else
|
||||
echo "Skipped current background cache refresh: current runtime theme assets unavailable"
|
||||
fi
|
||||
}
|
||||
|
||||
refresh_current_theme_runtime() {
|
||||
# 主题包同步完之后,设备上的 theme-runtime.env 仍可能停留在旧坐标。
|
||||
# render-clock / fetch-dashboard 实际都读这份运行时快照,
|
||||
# 所以这里必须按“当前主题 + 当前方向”在 Kindle 本地重写一次,
|
||||
# 让时钟位置和背景图一起跟随最新的 calendar 导出结果。
|
||||
if ssh "$KINDLE_TARGET" "set -eu
|
||||
theme_id=default
|
||||
orientation=portrait
|
||||
if [ -f /mnt/us/dashboard/local/theme.env ]; then
|
||||
# shellcheck disable=SC1091
|
||||
. /mnt/us/dashboard/local/theme.env
|
||||
theme_id=\${THEME_ID:-\$theme_id}
|
||||
orientation=\${ORIENTATION:-\$orientation}
|
||||
fi
|
||||
/mnt/us/dashboard/local/theme-sync.sh --local-only --theme \"\$theme_id\" --orientation \"\$orientation\" >/dev/null
|
||||
"; then
|
||||
echo "Current theme runtime refreshed on device"
|
||||
else
|
||||
echo "Skipped current theme runtime refresh: unable to resolve current theme locally"
|
||||
fi
|
||||
}
|
||||
|
||||
update_default_clock_region_env() {
|
||||
if [ -z "$CLOCK_REGION_JSON" ] || [ ! -f "$CLOCK_REGION_JSON" ]; then
|
||||
echo "Skipped CLOCK_REGION_* env update: no single background region selected"
|
||||
@@ -185,9 +272,13 @@ update_default_clock_region_env() {
|
||||
}
|
||||
|
||||
sync_dashboard_runtime
|
||||
resolve_kindle_location_override
|
||||
export_theme_bundle_locally
|
||||
sync_theme_bundle
|
||||
sync_kual_extension
|
||||
update_default_clock_region_env
|
||||
refresh_current_theme_runtime
|
||||
refresh_current_background_cache
|
||||
|
||||
if [ -n "$THEME_FILTER" ]; then
|
||||
if [ -n "$ORIENTATION_FILTER" ]; then
|
||||
|
||||
Reference in New Issue
Block a user