#!/command/with-contenv bash
# shellcheck shell=bash
# Prepare the logs folder for s6-log

set -o errexit -o nounset -o pipefail

dirs=(/dev/shm/logs/frigate /dev/shm/logs/go2rtc /dev/shm/logs/nginx /dev/shm/logs/certsync)

mkdir -p "${dirs[@]}"

# logutil-service drops s6-log to nobody, so the dirs must stay nobody-owned
# in root mode. Under docker --user we are already the (only) target user,
# chown would fail, and the plain s6-log fallback in the *-log services
# writes as us (the mkdir above is sufficient, /dev/shm is 1777).
if [[ "$(id -u)" -eq 0 ]]; then
    chown nobody:nogroup "${dirs[@]}"
fi
chmod 02755 "${dirs[@]}"
