#!/bin/sh

set -e

# Wait for FreedomBox first-boot setup to complete and the web server to
# start listening. App setup order is not deterministic, so a fixed sleep can
# expire before the apache app configures port 443. Poll instead of guessing.
for _ in $(seq 1 120); do
    if curl --fail --insecure --silent --output /dev/null \
            https://localhost/freedombox/status/; then
        break
    fi
    sleep 2
done

journalctl --unit=plinth --unit=freedombox-privileged

# Get FreedomBox status
curl --location --cookie "" --fail --write-out "%{response_code}" --insecure \
     --stderr - https://localhost/freedombox/status/

# Access FreedomBox interface
curl --location --cookie "" --fail --write-out "%{response_code}" --insecure \
     --stderr - https://localhost/freedombox/
