mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-07-30 13:48:07 +02:00
Re-implement config migration for the add-on
This commit is contained in:
parent
12460e65f2
commit
8a329feede
@ -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"}"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user