FROM ubuntu:20.04

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://pkgs.netbird.io/install.sh | sh

RUN mkdir -p /scripts && \
    printf '#!/bin/bash\necho "=== Starting NetBird Entrypoint ==="\necho "Current user: $(whoami)"\necho "PATH: $PATH"\necho "Checking for netbird..."\nwhich netbird || echo "netbird not found in PATH"\necho "Attempting to start NetBird..."\nif command -v netbird &> /dev/null; then\n  netbird up -F &\n  NETBIRD_PID=$!\n  echo "NetBird started with PID $NETBIRD_PID"\n  trap "kill $NETBIRD_PID" TERM INT\n  wait $NETBIRD_PID\nelse\n  echo "ERROR: netbird command not available"\n  echo "=== Container will keep running for debugging ==="\n  tail -f /dev/null\nfi\n' > /scripts/entrypoint.sh && \
    chmod +x /scripts/entrypoint.sh

ENTRYPOINT ["/scripts/entrypoint.sh"]
