#!/bin/bash
# Re-download missing UK MOD UFO PDFs
MASTER_DIR="/var/www/jaeswift-homepage/propaganda/docs/ufo-uap/uk-mod-complete"
BASE_DIR="/var/www/jaeswift-homepage/propaganda/docs/ufo-uap"

echo "[$(date)] Re-downloading 53 missing files"

wget --tries=5 \
     --wait=1 \
     --random-wait \
     --timeout=60 \
     --directory-prefix="$MASTER_DIR" \
     --no-check-certificate \
     --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" \
     "https://documents.theblackvault.com/documents/ufos/UK/aug-2009-highlights-guide.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1948.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1958-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1959.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1960.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1961.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1962.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1963.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1964.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1965.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1970.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1972.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1974.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1975.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1976.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1984-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1985-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1986-1-2.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1987-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1997-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-1999-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2005-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2006-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2018-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2019-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2020-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2021-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2022-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2023-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2024-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2025-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2026-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2027-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2028-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2030-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2031-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2032-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2033-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2034-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2035-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2036-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2037-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2038-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2039-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2040-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2041-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2043-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2044-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2046-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2047-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2048-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2049-1-1.pdf" "https://documents.theblackvault.com/documents/ufos/UK/defe-24-2050-1-1.pdf"

echo "[$(date)] Re-download complete"

# Recreate ALL symlinks
for f in "$MASTER_DIR"/defe-24-*.pdf; do
    [ -f "$f" ] && ln -sf "$f" "$BASE_DIR/uk-mod-ufo-desk/$(basename $f)"
done

for f in "$MASTER_DIR"/defe-31-*.pdf; do
    [ -f "$f" ] && ln -sf "$f" "$BASE_DIR/di55-ufo-archive/$(basename $f)"
done

[ -f "$MASTER_DIR/defe-24-1948.pdf" ] && ln -sf "$MASTER_DIR/defe-24-1948.pdf" "$BASE_DIR/rendlesham-forest/defe-24-1948.pdf"

for f in aug-2009-highlights-guide.pdf highlights-guide-09-08-11.pdf mar-2011-highlights-guide.pdf uk2009.pdf; do
    [ -f "$MASTER_DIR/$f" ] && ln -sf "$MASTER_DIR/$f" "$BASE_DIR/highlights-and-guides/$f"
done

echo "[$(date)] Symlinks recreated"
DOWN=$(ls -1 "$MASTER_DIR"/*.pdf 2>/dev/null | wc -l)
SIZE=$(du -sh "$MASTER_DIR" | cut -f1)
echo "[$(date)] Total: ${DOWN}/112 files (${SIZE})"
