#!/bin/bash

set -e

cd $AUTOPKGTEST_TMP
redis_tmp=$AUTOPKGTEST_TMP/redis-tmp
mkdir $redis_tmp

find tests/redis-configurations -print -name '*.conf' -exec sed -i "s@/tmp/@${redis_tmp}/@g" {} +
sed -i "s@dir \".\"@dir \"${redis_tmp}\"@" tests/redis-configurations/sentinel/redis-sentinel.conf

redis-server tests/redis-configurations/cluster/redis-0.conf
redis-server tests/redis-configurations/cluster/redis-1.conf
redis-server tests/redis-configurations/cluster/redis-2.conf
redis-server tests/redis-configurations/cluster/redis-3.conf
redis-server tests/redis-configurations/cluster/redis-4.conf
redis-server tests/redis-configurations/cluster/redis-5.conf
redis-server tests/redis-configurations/sentinel/redis-master.conf
redis-server tests/redis-configurations/sentinel/redis-slave.conf
redis-server tests/redis-configurations/sentinel/redis-sentinel.conf --sentinel

echo "yes" | ruby /usr/share/doc/redis-tools/examples/redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
