#!/usr/bin/env bash # Start the LiDAR map locally with a single command (GPU optional). # # ./start.sh build the image and start the map (port 8973) # ./start.sh stop stop the map # ./start.sh logs follow the server log # ./start.sh process [opts] one-off processing of the tiles in input/ # (options passed to the pipeline, e.g. --file NAME) # # Without an NVIDIA GPU usable by Docker, docker-compose.cpu.yml is added # automatically (the pipeline then runs on the CPU, more slowly). set -euo pipefail cd "$(dirname "$0")" # Create input/ and output/ as the current user: if Docker created them they # would belong to root and the container (uid 1000) could not write to them. mkdir -p input output for d in input output; do if [ ! -w "$d" ]; then echo "Error: $d/ is not writable (owner: $(stat -c %U "$d"))." >&2 echo "Fix it with: sudo chown -R $(id -u):$(id -g) $d" >&2 exit 1 fi done if [ "$(id -u)" != "1000" ]; then echo "Warning: the containers run as uid 1000, you are $(id -u):" >&2 echo "input/ and output/ must stay writable by uid 1000." >&2 fi # GPU: nvidia-smi present AND Docker able to hand it to a container. compose=(docker compose -f docker-compose.yml) if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi >/dev/null 2>&1 \ && docker run --rm --gpus all --entrypoint true busybox >/dev/null 2>&1; then echo "NVIDIA GPU detected: accelerated processing." else echo "No usable GPU: processing on the CPU (slower)." compose+=(-f docker-compose.cpu.yml) fi case "${1:-up}" in up) "${compose[@]}" up -d --build serve echo "Map: http://localhost:8973/" echo "Log: ./start.sh logs - stop: ./start.sh stop" ;; stop) "${compose[@]}" down ;; logs) "${compose[@]}" logs -f serve ;; process) shift if [ $# -gt 0 ]; then # Any option replaces the service's default command: repeat it in # full (input, output, 0.2 m, all GPUs). "${compose[@]}" run --rm --build process \ python3 -m lidar_pipeline /data/input -o /data/output -r 0.2 -g all "$@" else "${compose[@]}" run --rm --build process fi ;; *) sed -n '2,10p' "$0" | sed 's/^# \{0,1\}//' exit 1 ;; esac