Files
hassio-addons/scrutiny_fa/rootfs_overlay/etc/cont-init.d/01-configuration.sh
Alexandre bbaa0900a4 Fix Scrutiny 1.67 startup and InfluxDB migration (#2880)
* scrutiny: back up InfluxDB before 2.9 upgrade

* scrutiny: prepare InfluxDB 2.9 migration safely

* scrutiny: restore upstream s6 supervision

* scrutiny-fa: restore upstream s6 supervision

* scrutiny: validate backup contents before migration

* scrutiny: keep backup validation bounded

* scrutiny: document startup and migration fix

* scrutiny-fa: document startup and migration fix

* scrutiny: bump version to v1.67.0-3

* scrutiny-fa: bump version to v1.67.0-3

* scrutiny-fa: include migration helper in build context

* scrutiny-fa: copy migration helper explicitly

* scrutiny-fa: document build-context fix

* scrutiny-fa: bump version to v1.67.0-4

* scrutiny-fa: materialize Home Assistant rootfs overlay

* scrutiny-fa: use materialized rootfs overlay

* scrutiny-fa: bump version with changelog

* scrutiny: verify complete InfluxDB backup state

* scrutiny-fa: verify complete InfluxDB backup state

* scrutiny: support custom day intervals

* scrutiny-fa: support custom day intervals

* scrutiny: support absolute TLS paths

* scrutiny-fa: support absolute TLS paths

* scrutiny: harden collector configuration migration

* scrutiny-fa: harden collector configuration migration

* scrutiny: preserve legacy migration backups

* scrutiny-fa: preserve legacy migration backups

* scrutiny: restore initialization-only s6 hook

* scrutiny-fa: restore initialization-only s6 hook

* scrutiny: trigger reviewed release build

* scrutiny: finalize reviewed release

* scrutiny: finalize combined release metadata

* scrutiny: mark review-complete release

* scrutiny: normalize release metadata

* scrutiny: settle release metadata

* scrutiny: finalize metadata formatting

* scrutiny: synchronize reviewed release metadata

* scrutiny: run isolated reviewed build

* scrutiny-fa: run isolated reviewed build

* scrutiny: verify backup contents before migration

* scrutiny-fa: verify backup contents before migration

* scrutiny: test content-verified atomic backups

* scrutiny-fa: test content-verified atomic backups

* scrutiny: validate content-level backup integrity

* scrutiny: remove blocking FIFO test fixture

* scrutiny-fa: remove blocking FIFO test fixture

* scrutiny: run final content-integrity build

* scrutiny-fa: run final content-integrity build

* scrutiny: correct nginx readiness comment

* scrutiny-fa: correct nginx readiness comment

* scrutiny: skip collector symlinks during migration

* scrutiny-fa: skip collector symlinks during migration
2026-07-18 21:51:14 +02:00

130 lines
4.6 KiB
Bash
Executable File

#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
#################
# Create folder #
#################
DATABASELOCATION="/data"
echo "Updating folders structure"
mkdir -p "$DATABASELOCATION"/config
mkdir -p "$DATABASELOCATION"/influxdb
if [ -d /opt/scrutiny/config ]; then rm -r /opt/scrutiny/config; fi
if [ -d /opt/scrutiny/influxdb ]; then rm -r /opt/scrutiny/influxdb; fi
ln -s "$DATABASELOCATION"/config /opt/scrutiny
ln -s "$DATABASELOCATION"/influxdb /opt/scrutiny
# Upstream 1.67 upgrades InfluxDB from 2.2 to 2.9 and requires a confirmed
# offline backup before starting against existing data. Services have not
# started yet, so this is the safe point to create and verify that backup.
/usr/local/bin/scrutiny-ha-influxdb-preflight
###############################
# Migrating previous database #
###############################
if [ -f /data/scrutiny.db ]; then
bashio::log.warning "Previous database detected, migration will start. Backup stored in /share/scrutiny.db.bak"
cp /data/scrutiny.db /share/scrutiny.db.bak
mv /data/scrutiny.db "$DATABASELOCATION"/config/
fi
######
# TZ #
######
# Align timezone with options
if bashio::config.has_value "TZ"; then
TZ="$(bashio::config 'TZ')"
bashio::log.info "Timezone : $TZ"
sed -i "1a export TZ=$TZ" /etc/cont-init.d/01-timezone
fi
################
# CRON OPTIONS #
################
# Align update with options
FREQUENCY="$(bashio::config 'Updates')"
bashio::log.info "$FREQUENCY updates as defined in the 'Updates' option"
case "$FREQUENCY" in
"Quarterly")
sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"*/15 * * * *\"" /etc/cont-init.d/50-cron-config
;;
"Hourly")
sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 * * * *\"" /etc/cont-init.d/50-cron-config
;;
"Daily")
sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * *\"" /etc/cont-init.d/50-cron-config
;;
"Weekly")
sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * 0\"" /etc/cont-init.d/50-cron-config
;;
"Custom")
interval="$(bashio::config 'Updates_custom_time')"
bashio::log.info "... frequency is defined manually as $interval"
case "$interval" in
*m) # Matches intervals in minutes, like "5m" or "30m"
minutes="${interval%m}"
if [[ "$minutes" -gt 0 && "$minutes" -le 59 ]]; then
cron_schedule="*/$minutes * * * *"
else
bashio::log.error "Invalid minute interval: $interval"
fi
;;
*h) # Matches intervals in hours, like "2h"
hours="${interval%h}"
if [[ "$hours" -gt 0 && "$hours" -le 23 ]]; then
cron_schedule="0 */$hours * * *"
else
bashio::log.error "Invalid hour interval: $interval"
fi
;;
*d) # Matches intervals in days, like "10d"
days="${interval%d}"
if [[ "$days" -gt 0 && "$days" -le 31 ]]; then
cron_schedule="0 0 */$days * *"
else
bashio::log.error "Invalid day interval: $interval"
fi
;;
*w) # Matches intervals in weeks, like "1w"
weeks="${interval%w}"
if [[ "$weeks" -gt 0 && "$weeks" -le 4 ]]; then
cron_schedule="0 0 * * 0" # Weekly on Sunday (adjust if needed for multi-week)
else
bashio::log.error "Invalid week interval: $interval"
fi
;;
*mo) # Matches intervals in months, like "1mo"
months="${interval%mo}"
if [[ "$months" -gt 0 && "$months" -le 12 ]]; then
cron_schedule="0 0 1 */$months *" # Monthly on the 1st
else
bashio::log.error "Invalid month interval: $interval"
fi
;;
*)
bashio::log.error "Empty or unsupported custom interval. It should be in the format of 5m (every 5 minutes), 10d (every 10 days), 3w (every 3 weeks), 3mo (every 3 months)"
;;
esac
if [[ -n "$cron_schedule" ]]; then
sed -i "/customize the cron schedule/a export COLLECTOR_CRON_SCHEDULE=\"$cron_schedule\"" /etc/cont-init.d/50-cron-config
bashio::log.info "Custom cron schedule set to: $cron_schedule"
fi
;;
esac