Refactor entrypoint script for improved configuration handling and migration logic
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -39,7 +39,6 @@ COPY docker/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
|||||||
USER xteve
|
USER xteve
|
||||||
|
|
||||||
EXPOSE 34400/tcp
|
EXPOSE 34400/tcp
|
||||||
VOLUME ["/xteve/config"]
|
|
||||||
|
|
||||||
ENV XTEVE_CONFIG=/xteve/config
|
ENV XTEVE_CONFIG=/xteve/config
|
||||||
ENV XTEVE_PORT=34400
|
ENV XTEVE_PORT=34400
|
||||||
|
|||||||
@@ -5,11 +5,16 @@ DEFAULT_CONFIG_DIR="/xteve/config"
|
|||||||
LEGACY_CONFIG_DIRS="/config /xteve /home/xteve/.xteve"
|
LEGACY_CONFIG_DIRS="/config /xteve /home/xteve/.xteve"
|
||||||
|
|
||||||
resolve_config_dir() {
|
resolve_config_dir() {
|
||||||
if [ -n "${XTEVE_CONFIG:-}" ]; then
|
if [ -n "${XTEVE_CONFIG:-}" ] && [ "${XTEVE_CONFIG}" != "${DEFAULT_CONFIG_DIR}" ]; then
|
||||||
printf "%s" "${XTEVE_CONFIG}"
|
printf "%s" "${XTEVE_CONFIG}"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f "${DEFAULT_CONFIG_DIR}/settings.json" ]; then
|
||||||
|
printf "%s" "${DEFAULT_CONFIG_DIR}"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
for dir in ${LEGACY_CONFIG_DIRS}; do
|
for dir in ${LEGACY_CONFIG_DIRS}; do
|
||||||
if [ -f "${dir}/settings.json" ]; then
|
if [ -f "${dir}/settings.json" ]; then
|
||||||
printf "%s" "${dir}"
|
printf "%s" "${dir}"
|
||||||
@@ -29,22 +34,40 @@ copy_if_missing() {
|
|||||||
fi
|
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)"
|
CONFIG_DIR="$(resolve_config_dir)"
|
||||||
PORT="${XTEVE_PORT:-34400}"
|
PORT="${XTEVE_PORT:-34400}"
|
||||||
|
|
||||||
mkdir -p "${CONFIG_DIR}"
|
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
|
for legacy_dir in ${LEGACY_CONFIG_DIRS}; do
|
||||||
if [ "${legacy_dir}" = "${CONFIG_DIR}" ]; then
|
if [ "${legacy_dir}" = "${CONFIG_DIR}" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
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}"
|
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
|
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
|
done
|
||||||
|
|
||||||
for dir_name in data cache backup tmp; do
|
for dir_name in data cache backup tmp; do
|
||||||
@@ -64,5 +87,8 @@ fi
|
|||||||
rm -f "${CONFIG_DIR}/.xteve-write-test"
|
rm -f "${CONFIG_DIR}/.xteve-write-test"
|
||||||
|
|
||||||
echo "[entrypoint] Using config directory: ${CONFIG_DIR}"
|
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}" "$@"
|
exec /usr/local/bin/xteve -config "${CONFIG_DIR}" -port "${PORT}" "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user