From 8a329feede4703088bf79524a2953b337df17f1d Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Sun, 9 Mar 2025 15:14:30 -0300 Subject: [PATCH] Re-implement config migration for the add-on --- .../rootfs/etc/s6-overlay/s6-rc.d/frigate/run | 39 --------------- .../rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run | 50 +++++++++++++++++++ 2 files changed, 50 insertions(+), 39 deletions(-) diff --git a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run index c27f62d63..e66fa4021 100755 --- a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run +++ b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/frigate/run @@ -9,45 +9,6 @@ set -o errexit -o nounset -o pipefail # Tell S6-Overlay not to restart this service s6-svc -O . -function migrate_from_homeassistant_config() { - # Find old config file in yaml or yml, but prefer yaml - local ha_config_file="/homeassistant_config/config.yml" - local ha_config_file_yaml="${ha_config_file//.yml/.yaml}" - if [[ -f "${ha_config_file_yaml}" ]]; then - ha_config_file="${ha_config_file_yaml}" - elif [[ ! -f "${ha_config_file}" ]]; then - # Nothing to migrate - return 0 - fi - unset ha_config_file_yaml - - # Confirm there isn't a config yet in the target location - local config_file="${CONFIG_FILE:-"/config/config.yml"}" - local config_file_yaml="${config_file//.yml/.yaml}" - if [[ -f "${config_file_yaml}" || -f "${config_file}" ]]; then - echo "[ERROR] TODO" >&2 - return 1 - fi - unset config_file config_file_yaml - - local db_path - db_path=$(yq eval '.database.path' "${config_file}") - - if [[ "${db_path}" == "null" ]]; then - db_path="/config/frigate.db" - fi - - local previous_db_path="/homeassistant/frigate.db" - if [[ -f "${previous_db_path}" ]]; then - # /config is a mount point, move the db - echo "[INFO] Moving db from '${previous_db_path}' to '${db_path}'..." - # Move all files that starts with frigate.db to the new directory - mv -vf "${previous_db_path}"* "${new_db_dir}" # TODO FIX - fi - - # TODO migrate config -} - function migrate_db_from_media_to_config() { # Find config file in yaml or yml, but prefer yaml local config_file="${CONFIG_FILE:-"/config/config.yml"}" diff --git a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run index 2c3a7ab6f..eaff55ef8 100755 --- a/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run +++ b/docker/main/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run @@ -50,6 +50,56 @@ function set_libva_version() { export LIBAVFORMAT_VERSION_MAJOR } +function migrate_from_homeassistant_config() { + if ! mountpoint --quiet /homeassistant_config; then + # Not running as a Home Assistant add-on + return 0 + fi + + local new_config_file="/config/config.yml" + local new_config_file_yaml="${new_config_file//.yml/.yaml}" + if [[ -f "${new_config_file_yaml}" || -f "${new_config_file}" ]]; then + # Already migrated + return 0 + fi + unset new_config_file new_config_file_yaml + + local old_config_file="/homeassistant_config/frigate.yml" + local old_config_file_yaml="${old_config_file//.yml/.yaml}" + local new_config_file="/config/config.yml" + if [[ -f "${old_config_file_yaml}" ]]; then + old_config_file="${old_config_file_yaml}" + new_config_file="/config/config.yaml" + elif [[ ! -f "${old_config_file}" ]]; then + # Nothing to migrate + return 0 + fi + unset old_config_file_yaml + + local db_path + db_path=$(yq eval '.database.path' "${old_config_file}") + + if [[ "${db_path}" == "null" ]]; then + db_path="/config/frigate.db" + fi + + if [[ "${db_path}" == /config/* ]]; then + # replace /config/ prefix with /homeassistant_config/ + old_db_path="/homeassistant_config/${db_path:8}" + + if [[ -f "${old_db_path}" ]]; then + new_db_dir="$(dirname "${db_path}")" + echo "[INFO] Migrating database from '${old_db_path}' to '${db_path}'..." + mv -vf "${old_db_path}"* "${new_db_dir}" + fi + fi + + echo "[INFO] Migrating config from '${old_config_file}' to '${new_config_file}'..." + mv -vf "${old_config_file}" "${new_config_file}" +} + +migrate_from_homeassistant_config + set_libva_version if [[ -f "/dev/shm/go2rtc.yaml" ]]; then