52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 KiB
Bash
Executable File
#!/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 "安装完成!" |