wrongmove/scripts/otp-setup.sh

95 lines
2.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# OpenTripPlanner data setup script for Greater London
# Downloads OSM extract and TfL GTFS feeds for transit routing.
#
# Usage:
# ./scripts/otp-setup.sh [DATA_DIR]
#
# DATA_DIR defaults to ./otp-data/
# The directory is suitable for mounting as /var/opentripplanner in OTP container.
set -euo pipefail
DATA_DIR="${1:-./otp-data}"
GEOFABRIK_URL="https://download.geofabrik.de/europe/great-britain/england/greater-london-latest.osm.pbf"
OSM_FILE="greater-london-latest.osm.pbf"
# TfL GTFS feeds (Bus Open Data Service + TfL open data)
# These URLs may need updating; check https://data.bus-data.dft.gov.uk/ and TfL API
TFL_GTFS_URLS=(
"https://data.bus-data.dft.gov.uk/timetable/download/gtfs-file/london/"
)
echo "==> OTP Setup for Greater London"
echo " Data directory: ${DATA_DIR}"
mkdir -p "${DATA_DIR}"
# Download OSM extract
if [ ! -f "${DATA_DIR}/${OSM_FILE}" ]; then
echo "==> Downloading Greater London OSM extract..."
curl -L -o "${DATA_DIR}/${OSM_FILE}" "${GEOFABRIK_URL}"
else
echo "==> OSM extract already downloaded"
fi
# Download GTFS feeds
for i in "${!TFL_GTFS_URLS[@]}"; do
GTFS_FILE="gtfs-london-${i}.zip"
if [ ! -f "${DATA_DIR}/${GTFS_FILE}" ]; then
echo "==> Downloading GTFS feed ${i}..."
curl -L -o "${DATA_DIR}/${GTFS_FILE}" "${TFL_GTFS_URLS[$i]}" || {
echo " WARNING: Failed to download GTFS feed from ${TFL_GTFS_URLS[$i]}"
echo " You may need to manually download GTFS data."
echo " Check: https://data.bus-data.dft.gov.uk/"
echo " Place .zip files in ${DATA_DIR}/"
}
else
echo "==> GTFS feed ${i} already downloaded"
fi
done
# Create OTP build config if not present
if [ ! -f "${DATA_DIR}/build-config.json" ]; then
echo "==> Creating OTP build config..."
cat > "${DATA_DIR}/build-config.json" << 'EOF'
{
"osm": [
{
"source": "greater-london-latest.osm.pbf"
}
],
"transitFeeds": [
{
"type": "gtfs",
"source": "gtfs-london-0.zip"
}
]
}
EOF
fi
# Create OTP router config if not present
if [ ! -f "${DATA_DIR}/router-config.json" ]; then
echo "==> Creating OTP router config..."
cat > "${DATA_DIR}/router-config.json" << 'EOF'
{
"routingDefaults": {
"walkSpeed": 1.3,
"bikeSpeed": 5.0,
"numItineraries": 3
}
}
EOF
fi
echo ""
echo "==> OTP setup complete!"
echo " Mount ${DATA_DIR} as /var/opentripplanner in OTP container."
echo ""
echo " OTP will build the transit graph on first startup (~2 min for London)."
echo ""
echo " Example:"
echo " docker run -p 8080:8080 -v ${DATA_DIR}:/var/opentripplanner \\"
echo " opentripplanner/opentripplanner:2.6.0 --load --serve"