#!/bin/bash
set -euo pipefail

sudo systemctl start docker
sudo docker stop pgdb || true
sudo docker remove pgdb || true
sudo docker run -d \
  --name pgdb \
  -p 7777:5432 \
  -e POSTGRES_DB=vuln_demo \
  -e POSTGRES_PASSWORD=vuln_demo \
  -e POSTGRES_USER=vuln_demo \
  postgres:16-alpine

sudo docker stop redisdb || true
sudo docker remove redisdb || true
REDIS_USER="vuln_demo"
REDIS_PASSWORD="vuln_demo"
REDIS_MAX_MEMORY="512mb"
sudo docker run -d \
  --name redisdb \
  -p 7778:6379 \
  redis:latest \
  redis-server --appendonly yes \
  --user "$REDIS_USER" on ">$REDIS_PASSWORD" ~* allcommands \
  --user default off nopass nocommands \
  --maxmemory "$REDIS_MAX_MEMORY" --maxmemory-policy allkeys-lru

echo "sudo docker exec -it pgdb psql test test"
echo "sudo docker exec -it redisdb redis-cli --user $REDIS_USER --pass $REDIS_PASSWORD PING"
