#!/bin/bash # Check for --no-confirm flag NO_CONFIRM=false for arg in "$@"; do if [ "$arg" == "--no-confirm" ]; then NO_CONFIRM=true break fi done # Prompt for user confirmation if [ "$NO_CONFIRM" == false ]; then read -p "This script will add new mock books and notes to your dnote db. Do you want to proceed? (y/n): " confirm if [[ "$confirm" != "y" ]]; then echo "Operation cancelled." exit 0 fi fi # JSON Data embedded in the script JSON_DATA=$(cat < /dev/null; then echo "jq could not be found, installing..." apt-get update && apt-get install -y jq fi # Debug: Output the JSON_DATA to ensure it's parsed correctly echo "$JSON_DATA" | jq '.' || { echo "Invalid JSON data"; exit 1; } # Read JSON data and create books and notes echo "$JSON_DATA" | jq -c '.[]' | while IFS= read -r BOOK; do BOOK_NAME=$(echo "$BOOK" | jq -r '.book') echo "Processing book: $BOOK_NAME..." echo "$BOOK" | jq -c '.notes[]' | while IFS= read -r NOTE; do NOTE_CONTENT=$(echo "$NOTE" | jq -r '.') echo "Adding note: $NOTE_CONTENT" dnote add "$BOOK_NAME" -c "$NOTE_CONTENT" done done echo "Mock Books and notes have been created."