#!/bin/bash # # Outline Import Script # Imports markdown files back into Outline wiki with hierarchy preservation. # Companion script to export_with_trees.sh # # Usage: ./import_to_outline.sh [OPTIONS] # # Options: # -s, --single Import all into single timestamped collection # -n, --dry-run Preview operations without making changes # -d, --source DIR Source directory (default: outline_export) # -v, --verbose Increase output verbosity (-vv for debug) # -f, --force Overwrite existing collections (instead of skip) # --settings FILE Path to settings file (default: settings.json) # -h, --help Show help message # set -e # Exit on error # Capture CLI arguments to pass to Python CLI_ARGS="$@" # Colors for output GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Configuration WORK_DIR="$(pwd)" SETTINGS_FILE="$WORK_DIR/settings.json" DEFAULT_SOURCE_DIR="$WORK_DIR/outline_export" # Parse arguments to find settings file and source directory SETTINGS_ARG="" SOURCE_ARG="" for arg in "$@"; do if [[ "$prev_arg" == "--settings" ]]; then SETTINGS_ARG="$arg" SETTINGS_FILE="$WORK_DIR/$arg" fi if [[ "$prev_arg" == "-d" || "$prev_arg" == "--source" ]]; then SOURCE_ARG="$arg" fi prev_arg="$arg" done # Determine source directory if [ -n "$SOURCE_ARG" ]; then SOURCE_DIR="$WORK_DIR/$SOURCE_ARG" else SOURCE_DIR="$DEFAULT_SOURCE_DIR" fi # Show help if requested show_help() { echo "Outline Import Script" echo "" echo "Usage: $0 [OPTIONS]" echo "" echo "Import markdown files back into Outline wiki with hierarchy preservation." echo "This is a companion script to export_with_trees.sh." echo "" echo "Options:" echo " -s, --single Import all into single timestamped collection" echo " -n, --dry-run Preview operations without making changes" echo " -d, --source DIR Source directory (default: outline_export)" echo " -v, --verbose Increase output verbosity (-vv for debug)" echo " -f, --force Overwrite existing collections (instead of skip)" echo " --settings FILE Path to settings file (default: settings.json)" echo " -h, --help Show this help message" echo "" echo "Examples:" echo " $0 Import all collections from outline_export/" echo " $0 --dry-run Preview what would be imported" echo " $0 --single Import all into a single timestamped collection" echo " $0 -d backup/ Import from custom directory" echo " $0 --force Overwrite existing collections" echo "" exit 0 } # Check for help flag for arg in "$@"; do if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then show_help fi done echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}" echo -e "${BLUE} OUTLINE IMPORT${NC}" echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}" echo "" # Pre-flight checks echo -e "${YELLOW}Pre-flight checks...${NC}" # Check if settings.json exists if [ ! -f "$SETTINGS_FILE" ]; then echo -e "${RED}✗ Error: settings.json not found at $SETTINGS_FILE${NC}" echo " Create a settings.json file with your Outline API configuration:" echo " {" echo ' "source": {' echo ' "url": "http://outline:3000",' echo ' "token": "ol_api_YOUR_TOKEN_HERE"' echo " }" echo " }" exit 1 fi echo -e "${GREEN}✓ Settings file found${NC}" # Check if source directory exists (unless dry-run with no source specified) if [ ! -d "$SOURCE_DIR" ]; then echo -e "${RED}✗ Error: Source directory not found: $SOURCE_DIR${NC}" echo " Run export_with_trees.sh first to create export data," echo " or specify a different source with -d option." exit 1 fi echo -e "${GREEN}✓ Source directory found: $SOURCE_DIR${NC}" # Check for metadata files in source METADATA_COUNT=$(find "$SOURCE_DIR" -name "_collection_metadata.json" 2>/dev/null | wc -l) if [ "$METADATA_COUNT" -eq 0 ]; then echo -e "${RED}✗ Error: No collection metadata found in $SOURCE_DIR${NC}" echo " Make sure the source directory contains exported collections" echo " with _collection_metadata.json files." exit 1 fi echo -e "${GREEN}✓ Found $METADATA_COUNT collection(s) with metadata${NC}" # Extract API URL from settings.json for display API_URL=$(jq -r '.source.url' "$SETTINGS_FILE" 2>/dev/null || echo "unknown") echo -e "${GREEN}✓ Target: $API_URL${NC}" echo "" # Run the import via Docker docker run --rm --network domnet \ --user "$(id -u):$(id -g)" \ -e HOME=/tmp \ -v "$WORK_DIR:/work" \ -w /work \ python:3.11-slim \ bash -c "pip install -qqq requests tqdm 2>/dev/null && python3 outline_import.py $CLI_ARGS" echo ""