diff --git a/Dockerfile b/Dockerfile index c7d80c9..935b0f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,6 @@ COPY docker/entrypoint.sh /usr/local/bin/docker-entrypoint.sh USER xteve EXPOSE 34400/tcp -VOLUME ["/xteve/config"] ENV XTEVE_CONFIG=/xteve/config ENV XTEVE_PORT=34400 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 843343a..b45bb7b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -5,11 +5,16 @@ DEFAULT_CONFIG_DIR="/xteve/config" LEGACY_CONFIG_DIRS="/config /xteve /home/xteve/.xteve" resolve_config_dir() { - if [ -n "${XTEVE_CONFIG:-}" ]; then + 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}" @@ -29,22 +34,40 @@ copy_if_missing() { 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 [ ! -f "${CONFIG_DIR}/settings.json" ]; then +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 [ -f "${legacy_dir}/settings.json" ]; then + 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 - copy_if_missing "${legacy_dir}/${file}" "${CONFIG_DIR}/${file}" + 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 @@ -64,5 +87,8 @@ fi rm -f "${CONFIG_DIR}/.xteve-write-test" echo "[entrypoint] Using config directory: ${CONFIG_DIR}" +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}" "$@"