#!/bin/bash # SMS Forwarder 管理脚本 SERVICE_NAME="sms-forwarder" show_help() { echo "SMS Forwarder 管理脚本" echo "" echo "用法: $0 [命令]" echo "" echo "命令:" echo " start 启动服务" echo " stop 停止服务" echo " restart 重启服务" echo " status 查看服务状态" echo " logs 查看实时日志" echo " enable 启用开机自启" echo " disable 禁用开机自启" echo " test 发送测试通知" echo " update 更新依赖" echo " config 编辑配置文件" echo " install 安装 systemd 服务" echo " help 显示此帮助信息" } case "$1" in start) echo "🚀 启动 SMS Forwarder 服务..." sudo systemctl start $SERVICE_NAME ;; stop) echo "⏹️ 停止 SMS Forwarder 服务..." sudo systemctl stop $SERVICE_NAME ;; restart) echo "🔄 重启 SMS Forwarder 服务..." sudo systemctl restart $SERVICE_NAME ;; status) echo "📊 SMS Forwarder 服务状态:" sudo systemctl status $SERVICE_NAME --no-pager ;; logs) echo "📋 SMS Forwarder 实时日志 (Ctrl+C 退出):" sudo journalctl -u $SERVICE_NAME -f ;; enable) echo "✅ 启用 SMS Forwarder 开机自启..." sudo systemctl enable $SERVICE_NAME ;; disable) echo "❌ 禁用 SMS Forwarder 开机自启..." sudo systemctl disable $SERVICE_NAME ;; test) echo "🧪 发送测试通知..." if [ -f "config.yaml" ]; then API_KEY=$(grep "api_key:" config.yaml | awk '{print $2}' | tr -d '"') uv run python scripts/test_notification.py http://localhost:12152 "$API_KEY" else echo "❌ 配置文件不存在" fi ;; update) echo "📦 更新依赖..." uv sync echo "🔄 重启服务以应用更新..." sudo systemctl restart $SERVICE_NAME ;; config) echo "⚙️ 编辑配置文件..." ${EDITOR:-nano} config.yaml echo "是否重启服务以应用配置? (y/N)" read -r response if [[ "$response" =~ ^[Yy]$ ]]; then sudo systemctl restart $SERVICE_NAME fi ;; install) echo "🔧 安装 systemd 服务..." ./scripts/setup-systemd.sh ;; help|--help|-h) show_help ;; "") show_help ;; *) echo "❌ 未知命令: $1" echo "" show_help exit 1 ;; esac