#!/usr/bin/env bash
# Download RadPose. Run the same command again to resume an interrupted download.
set -euo pipefail

if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
  echo "Usage: bash download_radpose.sh [output_directory]"
  echo "Default output: ./RadPose_dataset (full dataset: about 1.81 TiB)"
  echo "Requires GNU Wget. Re-run the same command to resume."
  exit 0
fi
if (( $# > 1 )); then
  echo "Usage: bash download_radpose.sh [output_directory]" >&2
  exit 2
fi
if ! command -v wget >/dev/null 2>&1; then
  echo "Please install GNU Wget, then run this script again." >&2
  exit 1
fi

destination="${1:-RadPose_dataset}"
mkdir -p -- "$destination"
printf 'Downloading RadPose to %s (about 1.81 TiB). Re-run to resume.\n' "$destination"

exec wget \
  --recursive --level=inf --continue --no-parent \
  --no-host-directories --cut-dirs=2 \
  --reject='index.html*' --reject-regex='[?]' \
  --execute robots=off \
  --tries=10 --timeout=60 --waitretry=5 \
  --directory-prefix="$destination" \
  'https://mirrors.egr.msu.edu/inss/RadPose_dataset/seen/' \
  'https://mirrors.egr.msu.edu/inss/RadPose_dataset/unseen/'
