#!/usr/bin/env bash
# Download CICAPT-IIoT2024 (entire dataset tree) from UNB CIC via cic_download.py.
#
# Prereq: Token cookie for .cicresearch.ca saved as
#   scripts/download/cookies_cicapt_iiot2024.txt
#
# Remote tree is crawled in a single pass under ROOT="CICAPT-IIoT Dataset"
# (the top-level folder at
#  https://cicresearch.ca/IOTDataset/CICAPT-IIoT-Dataset/browse.php?p=CICAPT-IIoT+Dataset ).
# Every leaf file — pcap, csv, whatever — is mirrored under
#   datasets/cicapt_iiot2024/raw/
# preserving the remote subdirectory layout.
#
# Usage:
#   bash download_cicapt_iiot2024.sh               # full download
#   DRY_RUN=1 bash download_cicapt_iiot2024.sh     # enumerate only
#   LIMIT=5 bash download_cicapt_iiot2024.sh       # smoke test (first 5 files)
#   SKIP_EXT=zip,7z bash download_cicapt_iiot2024.sh   # skip archives

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"

DEST_ROOT="${DEST:-${REPO_ROOT}/datasets/cicapt_iiot2024/raw}"
COOKIES="${COOKIES:-${SCRIPT_DIR}/cookies_cicapt_iiot2024.txt}"
BASE="${BASE:-https://cicresearch.ca/IOTDataset/CICAPT-IIoT-Dataset/}"
ROOT="${ROOT:-CICAPT-IIoT Dataset}"

EXTRA=()
[[ "${DRY_RUN:-}" == "1" ]] && EXTRA+=(--dry-run)
[[ -n "${LIMIT:-}" ]] && EXTRA+=(--limit "${LIMIT}")
[[ -n "${SKIP_EXT:-}" ]] && EXTRA+=(--skip-ext "${SKIP_EXT}")

echo "=== ${ROOT} -> ${DEST_ROOT} ==="
python3 -u "${SCRIPT_DIR}/cic_download.py" \
  --cookies "${COOKIES}" --base "${BASE}" \
  --root "${ROOT}" --dest "${DEST_ROOT}" "${EXTRA[@]}"
