#!/usr/bin/env bash # Wrapper to run docker compose with the caller's UID/GID so generated files stay writable. set -euo pipefail if ! command -v docker >/dev/null 2>&1; then echo "Error: docker is not installed or not on PATH." >&2 exit 1 fi if docker compose version >/dev/null 2>&1; then COMPOSE_CMD=(docker compose) elif command -v docker-compose >/dev/null 2>&1; then COMPOSE_CMD=(docker-compose) else echo "Error: docker compose plugin or docker-compose binary is required." >&2 exit 1 fi CALLER_UID=$(id -u) CALLER_GID=$(id -g) detect_timezone() { if command -v timedatectl >/dev/null 2>&1; then local tz tz=$(timedatectl show --property=Timezone --value 2>/dev/null) if [ -n "${tz}" ]; then printf '%s\n' "${tz}" return 0 fi fi if [ -f /etc/timezone ]; then local tz tz=$(cat /etc/timezone 2>/dev/null) if [ -n "${tz}" ]; then printf '%s\n' "${tz}" return 0 fi fi if command -v readlink >/dev/null 2>&1; then local link link=$(readlink -f /etc/localtime 2>/dev/null || true) if [ -n "${link}" ] && [[ "${link}" == *zoneinfo/* ]]; then printf '%s\n' "${link##*/zoneinfo/}" return 0 fi fi printf '%s\n' "" } HOST_TZ=$(detect_timezone) SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # Run docker compose from the Docker directory so it picks up the bundled yaml. ( cd "${SCRIPT_DIR}" LOCAL_UID="${CALLER_UID}" LOCAL_GID="${CALLER_GID}" HOST_TZ="${HOST_TZ:-UTC}" "${COMPOSE_CMD[@]}" "$@" )