#!/usr/bin/env bash set -euo pipefail if [[ "${EUID}" -ne 0 ]]; then echo "请使用 sudo 执行: sudo ./scripts/install.sh" >&2 exit 1 fi ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" bash -n "$ROOT_DIR/bin/cleanup-smartcam-data" # Disable the former unit name when upgrading an existing device. This does # not stop, restart, or modify the smart-cam Docker container. systemctl disable --now userdata-video-cleanup.timer 2>/dev/null || true install -d -o root -g root -m 0755 /var/lib/cleanup-smartcam-data install -o root -g root -m 0755 \ "$ROOT_DIR/bin/cleanup-smartcam-data" \ /usr/local/sbin/cleanup-smartcam-data install -o root -g root -m 0644 \ "$ROOT_DIR/systemd/cleanup-smartcam-data.service" \ /etc/systemd/system/cleanup-smartcam-data.service install -o root -g root -m 0644 \ "$ROOT_DIR/systemd/cleanup-smartcam-data.timer" \ /etc/systemd/system/cleanup-smartcam-data.timer install -o root -g root -m 0644 \ "$ROOT_DIR/systemd/cleanup-smartcam-data-resume.timer" \ /etc/systemd/system/cleanup-smartcam-data-resume.timer systemctl daemon-reload systemctl enable --now cleanup-smartcam-data.timer # The fast timer is started only while low disk space disables local recording. systemctl disable cleanup-smartcam-data-resume.timer 2>/dev/null || true if [[ -f /userdata/data/.recording-paused-low-disk || \ -f /var/lib/cleanup-smartcam-data/capture-paused || \ -f /var/lib/userdata-video-cleanup/capture-paused ]]; then systemctl start cleanup-smartcam-data-resume.timer else systemctl stop cleanup-smartcam-data-resume.timer 2>/dev/null || true fi # Remove obsolete installed names only after the new timer is active. rm -f \ /etc/systemd/system/userdata-video-cleanup.timer \ /etc/systemd/system/userdata-video-cleanup.service \ /usr/local/sbin/userdata-video-cleanup systemctl daemon-reload echo "安装完成。" echo "程序: /usr/local/sbin/cleanup-smartcam-data" echo "服务: /etc/systemd/system/cleanup-smartcam-data.service" echo "定时器: /etc/systemd/system/cleanup-smartcam-data.timer" echo "录像恢复定时器: /etc/systemd/system/cleanup-smartcam-data-resume.timer" systemctl --no-pager status cleanup-smartcam-data.timer || true