#!/bin/sh
# Repair ownership of mounted data volumes, then run the bot as an
# unprivileged user. Named volumes inherit the image ownership, but bind mounts
# created by the host are commonly root-owned, so this keeps both usable.
set -eu

if [ "$(id -u)" = "0" ]; then
    mkdir -p /app/data /app/downloads /app/logs
    chown botuser:botuser /app/data /app/downloads /app/logs 2>/dev/null || true
    exec gosu botuser "$@"
fi

exec "$@"
