#!/bin/bash

set -e

echo "Waiting for SonarQube..."

for i in {1..60}; do
  STATUS=$(curl -s http://localhost:9000/api/system/status | jq -r '.status')

  echo "Current status: $STATUS"

  if [ "$STATUS" = "UP" ]; then
    echo "SonarQube is UP"
    exit 0
  fi

  sleep 5
done

echo "SonarQube failed to start"
exit 1