run-map-pipeline.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  4. map_output_dir="$root_dir/assets/campaign_map"
  5. venv_path="$root_dir/tools/map_pipeline/venv"
  6. requirements_path="$root_dir/tools/map_pipeline/requirements.txt"
  7. python_cmd="${PYTHON:-python3}"
  8. rebuild_maps="${map_pipeline_rebuild:-0}"
  9. for arg in "$@"; do
  10. if [ "$arg" = "--rebuild" ] || [ "$arg" = "-f" ]; then
  11. rebuild_maps=1
  12. fi
  13. done
  14. required_outputs=(
  15. "$map_output_dir/campaign_base_color.png"
  16. "$map_output_dir/campaign_water.png"
  17. "$map_output_dir/coastlines_uv.json"
  18. "$map_output_dir/rivers_uv.json"
  19. "$map_output_dir/land_mesh.bin"
  20. "$map_output_dir/provinces.json"
  21. "$map_output_dir/hannibal_path.json"
  22. )
  23. missing_outputs=()
  24. if [ -d "$map_output_dir" ]; then
  25. for output in "${required_outputs[@]}"; do
  26. if [ ! -s "$output" ]; then
  27. missing_outputs+=("$output")
  28. fi
  29. done
  30. else
  31. missing_outputs=("${required_outputs[@]}")
  32. fi
  33. if [ "$rebuild_maps" != "1" ] && [ "${#missing_outputs[@]}" -eq 0 ]; then
  34. echo "Map pipeline output already present; skipping. Use --rebuild to force."
  35. exit 0
  36. fi
  37. if [ "$rebuild_maps" != "1" ] && [ "${#missing_outputs[@]}" -gt 0 ]; then
  38. echo "Map pipeline outputs missing; regenerating:"
  39. printf ' - %s\n' "${missing_outputs[@]}"
  40. fi
  41. # Ensure Python exists
  42. if ! command -v "$python_cmd" >/dev/null 2>&1; then
  43. echo "Error: python3 not found" >&2
  44. exit 1
  45. fi
  46. # Create venv if missing
  47. if [ ! -d "$venv_path" ]; then
  48. echo "Creating virtual environment at $venv_path"
  49. "$python_cmd" -m venv "$venv_path"
  50. fi
  51. python_bin="$venv_path/bin/python"
  52. if [ ! -x "$python_bin" ]; then
  53. echo "Virtualenv python not found at $python_bin" >&2
  54. exit 1
  55. fi
  56. # ------------------------------------------------------------
  57. # Bootstrap pip (works even if ensurepip is missing)
  58. # ------------------------------------------------------------
  59. if ! "$python_bin" -m pip --version >/dev/null 2>&1; then
  60. echo "pip missing in venv — bootstrapping via get-pip.py"
  61. get_pip="$venv_path/get-pip.py"
  62. if command -v curl >/dev/null 2>&1; then
  63. curl -fsSL https://bootstrap.pypa.io/get-pip.py -o "$get_pip"
  64. elif command -v wget >/dev/null 2>&1; then
  65. wget -q https://bootstrap.pypa.io/get-pip.py -O "$get_pip"
  66. else
  67. echo "Error: neither curl nor wget available" >&2
  68. exit 1
  69. fi
  70. "$python_bin" "$get_pip"
  71. rm -f "$get_pip"
  72. fi
  73. pip_bin="$venv_path/bin/pip"
  74. # Upgrade tooling
  75. "$pip_bin" install --upgrade pip setuptools wheel
  76. # Install dependencies
  77. "$pip_bin" install -r "$requirements_path"
  78. # Run pipeline
  79. "$python_bin" "$root_dir/tools/map_pipeline/pipeline.py"
  80. "$python_bin" "$root_dir/tools/map_pipeline/provinces.py"
  81. "$python_bin" "$root_dir/tools/map_pipeline/hannibal_path.py"