#!/bin/bash """ ORCHESTRATION SCRIPT - Complete book scanning with auto-resume Manages chunked scanning to complete entire 226-page book """ TOTAL_PAGES=226 CHUNK_SIZE=40 PROGRESS_FILE="scan_progress.json" echo "🚀 KINDLE BOOK SCANNING ORCHESTRATOR" echo "=====================================" echo "Total pages: $TOTAL_PAGES" echo "Chunk size: $CHUNK_SIZE pages" echo "" # Function to get last completed page get_last_page() { if [ -f "$PROGRESS_FILE" ]; then python3 -c " import json try: with open('$PROGRESS_FILE', 'r') as f: data = json.load(f) print(data.get('last_completed_page', 0)) except: print(0) " else echo 0 fi } # Main scanning loop chunk_number=1 total_chunks=$(( (TOTAL_PAGES + CHUNK_SIZE - 1) / CHUNK_SIZE )) while true; do last_completed=$(get_last_page) next_start=$((last_completed + 1)) if [ "$next_start" -gt "$TOTAL_PAGES" ]; then echo "🏁 SCANNING COMPLETE!" echo "✅ All $TOTAL_PAGES pages have been scanned" break fi next_end=$((next_start + CHUNK_SIZE - 1)) if [ "$next_end" -gt "$TOTAL_PAGES" ]; then next_end=$TOTAL_PAGES fi echo "📦 CHUNK $chunk_number/$total_chunks" echo " Pages: $next_start to $next_end" echo " Progress: $last_completed/$TOTAL_PAGES completed ($(( last_completed * 100 / TOTAL_PAGES ))%)" echo "" # Run the chunked scanner python3 chunked_scanner.py --start-page "$next_start" --chunk-size "$CHUNK_SIZE" # Check if chunk completed successfully new_last_completed=$(get_last_page) if [ "$new_last_completed" -le "$last_completed" ]; then echo "❌ ERROR: Chunk failed or made no progress" echo " Last completed before: $last_completed" echo " Last completed after: $new_last_completed" echo "" echo "🔄 Retrying chunk in 10 seconds..." sleep 10 else echo "✅ Chunk completed successfully" echo " Scanned pages: $next_start to $new_last_completed" echo "" chunk_number=$((chunk_number + 1)) # Brief pause between chunks echo "⏳ Waiting 5 seconds before next chunk..." sleep 5 fi done echo "" echo "📊 FINAL SUMMARY" echo "================" echo "Total pages scanned: $(get_last_page)/$TOTAL_PAGES" echo "Files location: ./scanned_pages/" echo "Progress file: $PROGRESS_FILE" # Count actual files file_count=$(ls scanned_pages/page_*.png 2>/dev/null | wc -l) echo "Screenshot files: $file_count" if [ "$(get_last_page)" -eq "$TOTAL_PAGES" ]; then echo "" echo "🎉 SUCCESS: Complete book scan finished!" echo "Ready for OCR processing and translation." else echo "" echo "⚠️ Partial completion. You can resume by running this script again." fi