#!/bin/bash set -u TMP=/tmp/pdf-seed-fix2 API=http://localhost/pdfs/api/upload mkdir -p "$TMP" PDFS=( "https://archive.org/download/fm21-150-combatives/fm21-150-combatives.pdf|FM 21-150 Combatives (1992)|defense" "https://archive.org/download/WhereThereIsNoDoctor-English-DavidWerner/WhereThereIsNoDoctor-English-DavidWerner.pdf|Where There Is No Doctor (Hesperian)|medical" "https://www.globalsecurity.org/military/library/policy/army/fm/3-22-9/fm3-22-9_c1_2011.pdf|FM 3-22.9 Rifle Marksmanship M16/M4 (2011)|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=120 -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"