#!/bin/sh

# make sure script does not hang forever
if [ -z "$1" ]; then
  exec timeout -k 60 120 $0 timeout
fi

set -e

printf "=== config ===\n"
booth-keygen
cat <<EOF | tee /etc/booth/booth.conf
authfile = /etc/booth/authkey
site = 127.0.0.1
site = 127.0.0.2
site = 127.0.0.3
ticket = "ticket-A"
EOF

printf "\n=== service ===\n"
systemctl daemon-reload
systemctl restart booth && sleep 3
systemctl status booth@booth
boothd daemon -D -s 127.0.0.2 2>&1
boothd daemon -D -s 127.0.0.3 2>&1

printf "\n=== status ===\n"
booth status
booth list

printf "\n=== grant ===\n"
booth grant ticket-A 2>&1
booth list

printf "\n=== revoke ===\n"
booth revoke ticket-A 2>&1
booth list

printf "\n=== geostore ===\n"
geostore set status GOOD 2>&1
geostore get status
geostore list
geostore delete status
