#!/bin/sh set -eu DEFAULT_CONFIG_DIR="/xteve/config" LEGACY_CONFIG_DIRS="/config /xteve /home/xteve/.xteve" resolve_config_dir() { if [ -n "${XTEVE_CONFIG:-}" ] && [ "${XTEVE_CONFIG}" != "${DEFAULT_CONFIG_DIR}" ]; then printf "%s" "${XTEVE_CONFIG}" return fi if [ -f "${DEFAULT_CONFIG_DIR}/settings.json" ]; then printf "%s" "${DEFAULT_CONFIG_DIR}" return fi for dir in ${LEGACY_CONFIG_DIRS}; do if [ -f "${dir}/settings.json" ]; then printf "%s" "${dir}" return fi done printf "%s" "${DEFAULT_CONFIG_DIR}" } copy_if_missing() { src="$1" dst="$2" if [ -e "${src}" ] && [ ! -e "${dst}" ]; then cp -R "${src}" "${dst}" fi } settings_initialized() { file="$1" if [ ! -s "${file}" ]; then return 1 fi if grep -q '"uuid"' "${file}" 2>/dev/null; then return 0 fi return 1 } CONFIG_DIR="$(resolve_config_dir)" PORT="${XTEVE_PORT:-34400}" mkdir -p "${CONFIG_DIR}" if ! settings_initialized "${CONFIG_DIR}/settings.json"; then for legacy_dir in ${LEGACY_CONFIG_DIRS}; do if [ "${legacy_dir}" = "${CONFIG_DIR}" ]; then continue fi if settings_initialized "${legacy_dir}/settings.json"; then echo "[entrypoint] Migrating existing configuration from ${legacy_dir} to ${CONFIG_DIR}" for file in authentication.json pms.json settings.json xepg.json urls.json; do if [ "${file}" = "settings.json" ] || [ "${file}" = "xepg.json" ] || [ "${file}" = "urls.json" ]; then cp -f "${legacy_dir}/${file}" "${CONFIG_DIR}/${file}" 2>/dev/null || true else copy_if_missing "${legacy_dir}/${file}" "${CONFIG_DIR}/${file}" fi done for dir_name in data cache backup tmp; do copy_if_missing "${legacy_dir}/${dir_name}" "${CONFIG_DIR}/${dir_name}" done break fi done fi if ! touch "${CONFIG_DIR}/.xteve-write-test" 2>/dev/null; then echo "[entrypoint] ERROR: Config directory is not writable: ${CONFIG_DIR}" >&2 echo "[entrypoint] Running as UID:GID $(id -u):$(id -g)" >&2 ls -ld "${CONFIG_DIR}" >&2 || true echo "[entrypoint] Hint: ensure host path ownership/permissions allow this UID:GID to write, or set matching container UID/GID at build time." >&2 exit 1 fi rm -f "${CONFIG_DIR}/.xteve-write-test" echo "[entrypoint] Using config directory: ${CONFIG_DIR}" echo "[entrypoint] Running as UID:GID $(id -u):$(id -g)" if [ -f "${CONFIG_DIR}/settings.json" ]; then echo "[entrypoint] settings.json details: $(ls -l "${CONFIG_DIR}/settings.json" | awk '{print $1, $3, $4, $5, $9}')" fi exec /usr/local/bin/xteve -config "${CONFIG_DIR}" -port "${PORT}" "$@"