Files
cleanup-smartcam-data/scripts/install.sh
T
2026-07-15 13:58:32 +08:00

64 lines
2.3 KiB
Bash
Executable File

#!/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
if [[ -f /var/lib/userdata-video-cleanup/capture-paused && \
! -f /var/lib/cleanup-smartcam-data/capture-paused ]]; then
mv /var/lib/userdata-video-cleanup/capture-paused \
/var/lib/cleanup-smartcam-data/capture-paused
fi
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 by the cleanup program only while capture is paused.
systemctl disable cleanup-smartcam-data-resume.timer 2>/dev/null || true
if [[ -f /var/lib/cleanup-smartcam-data/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