#!/bin/sh set -eu echo "Waiting for OpenBao to start..." sleep 5 INIT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://openbao:8200/v1/sys/init) if [ "$INIT_STATUS" = "200" ]; then echo "OpenBao is already initialized. Skipping init." exit 0 fi echo "Initializing OpenBao..." INIT_OUTPUT=$(curl -s -X PUT http://openbao:8200/v1/sys/init -d '{"secret_shares": 1, "secret_threshold": 1}') ROOT_TOKEN=$(echo "$INIT_OUTPUT" | grep -o '"root_token":"[^"]*' | cut -d'"' -f4) UNSEAL_KEY=$(echo "$INIT_OUTPUT" | grep -o '"keys":\["[^"]*' | cut -d'"' -f4) echo "Unsealing OpenBao..." curl -s -X PUT http://openbao:8200/v1/sys/unseal -d "{\"key\": \"$UNSEAL_KEY\"}" > /dev/null echo "Writing secrets to OpenBao..." curl -s -X POST -H "X-Vault-Token: $ROOT_TOKEN" http://openbao:8200/v1/sys/mounts/secret -d '{"type": "kv", "options": {"version": "2"}}' > /dev/null curl -s -X POST -H "X-Vault-Token: $ROOT_TOKEN" http://openbao:8200/v1/secret/data/messenger -d '{ "data": { "db_password": "messenger_password", "s3_access_key": "minioadmin", "s3_secret_key": "minioadmin", "broker_url": "amqp://guest:guest@broker:5672/" } }' > /dev/null echo "OpenBao initialization complete." echo "ROOT_TOKEN=$ROOT_TOKEN" echo "UNSEAL_KEY=$UNSEAL_KEY"