Initial commit: SMS Forwarder project with Docker support
This commit is contained in:
128
scripts/install.sh
Executable file
128
scripts/install.sh
Executable file
@ -0,0 +1,128 @@
|
||||
#!/bin/bash
|
||||
|
||||
# SMS Forwarder 安装脚本
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 开始安装 SMS Forwarder..."
|
||||
|
||||
# 检查 Python 版本
|
||||
check_python() {
|
||||
if command -v python3 &> /dev/null; then
|
||||
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
|
||||
if [[ $(echo "$PYTHON_VERSION >= 3.10" | bc -l) -eq 1 ]]; then
|
||||
echo "✅ Python $PYTHON_VERSION 已安装"
|
||||
else
|
||||
echo "❌ 需要 Python 3.10 或更高版本,当前版本: $PYTHON_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "❌ 未找到 Python 3,请先安装 Python 3.10+"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 安装 uv
|
||||
install_uv() {
|
||||
if command -v uv &> /dev/null; then
|
||||
echo "✅ uv 已安装"
|
||||
else
|
||||
echo "📦 安装 uv..."
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
source $HOME/.cargo/env
|
||||
fi
|
||||
}
|
||||
|
||||
# 安装依赖
|
||||
install_dependencies() {
|
||||
echo "📦 安装项目依赖..."
|
||||
uv sync
|
||||
}
|
||||
|
||||
# 创建配置文件
|
||||
setup_config() {
|
||||
if [ ! -f "config.yaml" ]; then
|
||||
echo "⚙️ 创建配置文件..."
|
||||
cp config.example.yaml config.yaml
|
||||
echo "📝 请编辑 config.yaml 文件配置你的推送服务"
|
||||
else
|
||||
echo "✅ 配置文件已存在"
|
||||
fi
|
||||
}
|
||||
|
||||
# 创建必要目录
|
||||
create_directories() {
|
||||
echo "📁 创建必要目录..."
|
||||
mkdir -p logs
|
||||
mkdir -p data
|
||||
}
|
||||
|
||||
# 生成 API 密钥
|
||||
generate_api_key() {
|
||||
if command -v python3 &> /dev/null; then
|
||||
API_KEY=$(python3 -c "import secrets; print(secrets.token_urlsafe(32))")
|
||||
echo "🔑 生成的 API 密钥: $API_KEY"
|
||||
echo "请将此密钥添加到 config.yaml 文件中的 server.api_key 字段"
|
||||
fi
|
||||
}
|
||||
|
||||
# 创建 systemd 服务文件
|
||||
create_systemd_service() {
|
||||
read -p "是否创建 systemd 服务? (y/N): " create_service
|
||||
if [[ $create_service =~ ^[Yy]$ ]]; then
|
||||
CURRENT_DIR=$(pwd)
|
||||
USER=$(whoami)
|
||||
|
||||
cat > sms-forwarder.service << EOF
|
||||
[Unit]
|
||||
Description=SMS Forwarder Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
WorkingDirectory=$CURRENT_DIR
|
||||
Environment=PATH=$CURRENT_DIR/.venv/bin
|
||||
ExecStart=$CURRENT_DIR/.venv/bin/python -m sms_forwarder.main
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
echo "📄 systemd 服务文件已创建: sms-forwarder.service"
|
||||
echo "运行以下命令安装服务:"
|
||||
echo " sudo cp sms-forwarder.service /etc/systemd/system/"
|
||||
echo " sudo systemctl daemon-reload"
|
||||
echo " sudo systemctl enable sms-forwarder"
|
||||
echo " sudo systemctl start sms-forwarder"
|
||||
fi
|
||||
}
|
||||
|
||||
# 主安装流程
|
||||
main() {
|
||||
echo "SMS Forwarder 安装程序"
|
||||
echo "======================"
|
||||
|
||||
check_python
|
||||
install_uv
|
||||
install_dependencies
|
||||
create_directories
|
||||
setup_config
|
||||
generate_api_key
|
||||
create_systemd_service
|
||||
|
||||
echo ""
|
||||
echo "🎉 安装完成!"
|
||||
echo ""
|
||||
echo "下一步:"
|
||||
echo "1. 编辑 config.yaml 文件配置推送服务"
|
||||
echo "2. 运行 'uv run sms-forwarder' 启动服务器"
|
||||
echo "3. 访问 http://localhost:8000/docs 查看 API 文档"
|
||||
echo "4. 参考 docs/iphone-setup.md 配置 iPhone 快捷指令"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# 运行主函数
|
||||
main "$@"
|
Reference in New Issue
Block a user