#!/bin/bash
set -e

TERRAIN_DIR="/opt/rfcp/data/terrain"
mkdir -p $TERRAIN_DIR
cd $TERRAIN_DIR

echo "📡 Downloading Ukraine SRTM 30m tiles..."

# CGIAR SRTM (easiest, no auth needed)
BASE="https://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF"

# Download Ukraine tiles
wget -c $BASE/srtm_39_02.zip
wget -c $BASE/srtm_40_02.zip
wget -c $BASE/srtm_41_02.zip
wget -c $BASE/srtm_39_03.zip
wget -c $BASE/srtm_40_03.zip

echo "📦 Extracting..."
for f in *.zip; do
    unzip -o $f
    rm $f
done

echo "✅ Terrain data ready: $(ls *.tif | wc -l) tiles"
du -sh $TERRAIN_DIR
