#!/bin/sh
# Sync Kobo highlights to home server
# Place at: /usr/local/bin/sync_highlights.sh

DB="/mnt/onboard/.kobo/KoboReader.sqlite"
ENDPOINT="http://192.168.88.69:42070/api/highlights"
LOGFILE="/mnt/onboard/.adds/kb_exfiltrator.log"

# Create log directory if needed
mkdir -p /mnt/onboard/.adds

# Log with timestamp
echo "=== $(date) ===" >> "$LOGFILE"

# Run exfiltrator and capture output
if /usr/local/bin/kb_exfiltrator "$DB" "$ENDPOINT" >> "$LOGFILE" 2>&1; then
    # Success
    echo "Success: Highlights synced!" >> "$LOGFILE"
    # Optional: Show a notification (requires FBInk or similar)
    # fbink -g file=success.png
    exit 0
else
    # Failure
    echo "Error: Sync failed. Check log at .adds/kb_exfiltrator.log" >> "$LOGFILE"
    exit 1
fi
