#!/bin/bash set -u TMP=/tmp/pdf-seed-fix API=http://localhost/pdfs/api/upload mkdir -p "$TMP" PDFS=( "https://ia801301.us.archive.org/5/items/WhereWomenHaveNoDoctor/18.HersperianFoundation-WhereWomenHaveNoDoctor.pdf|Where Women Have No Doctor (Hesperian)|medical" "https://archive.org/download/WhereThereIsNoDoctor-English-DavidWerner/WhereThereIsNoDoctor-English-DavidWerner.pdf|Where There Is No Doctor (Hesperian)|medical" "https://ia801500.us.archive.org/28/items/MManuals/Fm5-31Boobytraps.pdf|FM 5-31 Boobytraps (1965)|defense" "https://archive.org/download/milmanual-fm-3-25.26-map-reading-and-land-navigation/fm_3-25.26_map_reading_and_land_navigation.pdf|FM 3-25.26 Map Reading and Land Navigation|navigation" "https://archive.org/download/milmanual-fm-23-10-sniper-training/fm_23-10_sniper_training.pdf|FM 23-10 Sniper Training|defense" "https://archive.org/download/milmanual-fm-21-150-combatives/fm_21-150_combatives.pdf|FM 21-150 Combatives|defense" "https://archive.org/download/milmanual-fm-3-06.11-combined-arms-operations-in-urban-terrain/fm_3-06.11_combined_arms_operations_in_urban_terrain.pdf|FM 3-06.11 Combined Arms Urban Terrain|defense" "https://armypubs.army.mil/epubs/DR_pubs/DR_a/ARN36119-TC_3-22.9-000-WEB-1.pdf|TC 3-22.9 Rifle and Carbine Marksmanship (v2)|defense" ) ok=0; fail=0; total=${#PDFS[@]}; i=0 for entry in "${PDFS[@]}"; do i=$((i+1)) IFS='|' read -r url title tag <<< "$entry" fname=$(echo "$title" | tr -c 'A-Za-z0-9._-' '_' | head -c 100).pdf out="$TMP/$fname" echo "" echo "==> [$i/$total] [$title]" if wget -q --show-progress -U "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36" --tries=2 --timeout=60 -O "$out" "$url"; then sz_bytes=$(stat -c%s "$out" 2>/dev/null || echo 0) if [ "$sz_bytes" -gt 100000 ] && file "$out" | grep -qi "PDF"; then sz=$(du -h "$out" | cut -f1) curl -s -X POST "$API" -F "file=@$out;type=application/pdf" -F "title=$title" -F "tag=$tag" > /dev/null echo " ✓ uploaded ($sz)" ok=$((ok+1)) else echo " ✗ skipped (not a valid PDF, $sz_bytes bytes)" fail=$((fail+1)) fi rm -f "$out" else echo " ✗ download failed" fail=$((fail+1)) fi done echo "" echo "================================" echo "OK: $ok Failed: $fail Total: $total" echo "================================" rm -rf "$TMP"