Files
karuo-ai/01_卡资(金)/金仓_存储备份/脚本/karuo_perf_guard_install.sh
2026-07-19 00:21:46 +08:00

55 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 安装/卸载 卡若AI 轻量防卡顿守护
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
LABEL="com.karuo.perf-guard"
PLIST_SRC="$ROOT/com.karuo.perf-guard.plist"
PLIST_DST="$HOME/Library/LaunchAgents/$LABEL.plist"
GUARD="$ROOT/karuo_perf_guard.sh"
LOG="$HOME/Library/Logs/karuo_perf_guard.log"
usage() {
cat <<EOF
用法: bash $(basename "$0") [install|uninstall|status|test]
install 安装 LaunchAgent每 15 分钟低优先级巡检)
uninstall 卸载守护
status 查看 launchd 状态 + 最近日志
test dry-run 一轮(只报告)
EOF
}
install_guard() {
chmod +x "$GUARD"
cp -f "$PLIST_SRC" "$PLIST_DST"
launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$PLIST_DST"
launchctl enable "gui/$(id -u)/$LABEL" 2>/dev/null || true
echo "✅ 已安装 $LABEL"
echo " 脚本: $GUARD"
echo " 日志: $LOG"
bash "$GUARD" --once
}
uninstall_guard() {
launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true
rm -f "$PLIST_DST"
echo "✅ 已卸载 $LABEL"
}
show_status() {
launchctl print "gui/$(id -u)/$LABEL" 2>/dev/null | head -20 || echo "未安装"
echo "--- 最近日志 ---"
tail -n 15 "$LOG" 2>/dev/null || echo "(无日志)"
}
cmd="${1:-install}"
case "$cmd" in
install) install_guard ;;
uninstall) uninstall_guard ;;
status) show_status ;;
test) bash "$GUARD" --dry-run ;;
*) usage; exit 1 ;;
esac