From 4ee9a4494813d5fa6a1cbea426143ed05f25d571 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Sun, 23 Mar 2025 13:27:56 -0300 Subject: [PATCH] Align bash and python scripts to prefer config.yml over config.yaml --- .../rootfs/etc/s6-overlay/s6-rc.d/prepare/run | 15 +++++++++------ .../rootfs/usr/local/ffmpeg/get_ffmpeg_path.py | 10 ++-------- .../main/rootfs/usr/local/go2rtc/create_config.py | 9 ++------- .../rootfs/usr/local/nginx/get_tls_settings.py | 13 ++++++------- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/prepare/run b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/prepare/run index 02e5bb621..a9a7b71d4 100755 --- a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/prepare/run +++ b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/prepare/run @@ -24,10 +24,11 @@ function migrate_addon_config_dir() { local old_config_file="${home_assistant_config_dir}/frigate.yml" local old_config_file_yaml="${old_config_file//.yml/.yaml}" local new_config_file="${config_dir}/config.yml" - if [[ -f "${old_config_file_yaml}" ]]; then + if [[ -f "${old_config_file}" ]]; then + : + elif [[ -f "${old_config_file_yaml}" ]]; then old_config_file="${old_config_file_yaml}" - new_config_file="${new_config_file//.yml/.yaml}" - elif [[ ! -f "${old_config_file}" ]]; then + else # Nothing to migrate return 0 fi @@ -103,12 +104,14 @@ function migrate_addon_config_dir() { } function migrate_db_from_media_to_config() { - # Find config file in yaml or yml, but prefer yaml + # Find config file in yml or yaml, but prefer yml local config_file="${CONFIG_FILE:-"/config/config.yml"}" local config_file_yaml="${config_file//.yml/.yaml}" - if [[ -f "${config_file_yaml}" ]]; then + if [[ -f "${config_file}" ]]; then + : + elif [[ -f "${config_file_yaml}" ]]; then config_file="${config_file_yaml}" - elif [[ ! -f "${config_file}" ]]; then + else # Frigate will create the config file on startup return 0 fi diff --git a/docker/main/rootfs/usr/local/ffmpeg/get_ffmpeg_path.py b/docker/main/rootfs/usr/local/ffmpeg/get_ffmpeg_path.py index ed7f6a891..cf425ae74 100644 --- a/docker/main/rootfs/usr/local/ffmpeg/get_ffmpeg_path.py +++ b/docker/main/rootfs/usr/local/ffmpeg/get_ffmpeg_path.py @@ -1,5 +1,4 @@ import json -import os import sys from ruamel.yaml import YAML @@ -9,17 +8,12 @@ from frigate.const import ( DEFAULT_FFMPEG_VERSION, INCLUDED_FFMPEG_VERSIONS, ) - +from frigate.util.config import find_config_file sys.path.remove("/opt/frigate") yaml = YAML() -config_file = os.environ.get("CONFIG_FILE", "/config/config.yml") - -# Check if we can use .yaml instead of .yml -config_file_yaml = config_file.replace(".yml", ".yaml") -if os.path.isfile(config_file_yaml): - config_file = config_file_yaml +config_file = find_config_file() try: with open(config_file) as f: diff --git a/docker/main/rootfs/usr/local/go2rtc/create_config.py b/docker/main/rootfs/usr/local/go2rtc/create_config.py index d7c21c7f7..a203ea8b6 100644 --- a/docker/main/rootfs/usr/local/go2rtc/create_config.py +++ b/docker/main/rootfs/usr/local/go2rtc/create_config.py @@ -15,7 +15,7 @@ from frigate.const import ( LIBAVFORMAT_VERSION_MAJOR, ) from frigate.ffmpeg_presets import parse_preset_hardware_acceleration_encode - +from frigate.util.config import find_config_file sys.path.remove("/opt/frigate") yaml = YAML() @@ -29,12 +29,7 @@ if os.path.isdir("/run/secrets"): Path(os.path.join("/run/secrets", secret_file)).read_text().strip() ) -config_file = os.environ.get("CONFIG_FILE", "/config/config.yml") - -# Check if we can use .yaml instead of .yml -config_file_yaml = config_file.replace(".yml", ".yaml") -if os.path.isfile(config_file_yaml): - config_file = config_file_yaml +config_file = find_config_file() try: with open(config_file) as f: diff --git a/docker/main/rootfs/usr/local/nginx/get_tls_settings.py b/docker/main/rootfs/usr/local/nginx/get_tls_settings.py index f1a4c85de..6307917a9 100644 --- a/docker/main/rootfs/usr/local/nginx/get_tls_settings.py +++ b/docker/main/rootfs/usr/local/nginx/get_tls_settings.py @@ -1,18 +1,17 @@ """Prints the tls config as json to stdout.""" import json -import os +import sys from ruamel.yaml import YAML +sys.path.insert(0, "/opt/frigate") +from frigate.util.config import find_config_file +sys.path.remove("/opt/frigate") + yaml = YAML() -config_file = os.environ.get("CONFIG_FILE", "/config/config.yml") - -# Check if we can use .yaml instead of .yml -config_file_yaml = config_file.replace(".yml", ".yaml") -if os.path.isfile(config_file_yaml): - config_file = config_file_yaml +config_file = find_config_file() try: with open(config_file) as f: