#!/usr/bin/env bash

echo -e "Manticore Search (type $suffix):"
if [ -f manticoresearch/idx$suffix/${test}1.*sph ]; then
  echo -e "${COLORED}\tNo need to rebuild${NC}"
  exit 10
fi

docker-compose -f ../../docker-compose.yml --env-file ../../.env stop manticoresearch
docker-compose -f ../../docker-compose.yml --env-file ../../.env rm -f manticoresearch
php manticoresearch/generate_manticore_config.php --test=$test --type=$suffix > manticoresearch/manticore$suffix.conf
mkdir -p manticoresearch/idx$suffix/data/binlog
chmod 777 manticoresearch/idx$suffix/data/binlog
suffix=$suffix docker-compose -f ../../docker-compose.yml --env-file ../../.env up -d manticoresearch

if timeout 60 grep -qm1 '\[BUDDY\] started' <(docker logs -f manticoresearch_engine); then
  echo -e '\tAccepting connections';
else
  echo -e '\tManticore failed to start properly in 60 seconds';
  exit 1
fi
