rag/script/install.sh
2025-07-16 15:06:59 +08:00

52 lines
1.4 KiB
Bash
Executable File
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.

#!/bin/bash
# 检查操作系统
OS=$(uname -s)
if [[ "$OS" != "Darwin" && "$OS" != "Linux" ]]; then
echo "错误:此脚本仅支持 macOS 和 Linux"
exit 1
fi
# 检查依赖文件
SERVICE_FILE="rag.service"
NGINX_FILE="rag.nginx"
if [[ ! -f "$SERVICE_FILE" || ! -f "$NGINX_FILE" ]]; then
echo "错误:缺少 $SERVICE_FILE$NGINX_FILE 文件"
exit 1
fi
# 1. 配置服务
if [[ "$OS" == "Darwin" ]]; then
# macOS: 使用 launchd
mkdir -p ~/Library/LaunchAgents
cp rag.service ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/rag.service
launchctl start rag.service
elif [[ "$OS" == "Linux" ]]; then
# Linux: 使用 Systemd
sudo cp rag.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable rag.service
sudo systemctl start rag.service
fi
# 2. 配置 Nginx
if ! command -v nginx &> /dev/null; then
echo "安装 Nginx..."
if [[ "$OS" == "Darwin" ]]; then
brew install nginx
elif [[ "$OS" == "Linux" ]]; then
sudo apt-get update && sudo apt-get install -y nginx
fi
fi
# 动态检测 Nginx 配置路径
NGINX_CONF_DIR="/etc/nginx/sites-enabled"
if [[ "$OS" == "Darwin" ]]; then
NGINX_CONF_DIR="/usr/local/etc/nginx/sites-enabled"
fi
mkdir -p "$NGINX_CONF_DIR"
cp rag.nginx "$NGINX_CONF_DIR/"
nginx -t && nginx -s reload || echo "错误Nginx 配置重载失败"
echo "安装完成!"