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

46 lines
1.0 KiB
Bash

#!/bin/bash
HOME_DIR="/share/wangmeihua"
RAG_DIR="/share/wangmeihua/rag"
PYTHON_VERSION="python3"
# 检查 Python 版本
if ! command -v "$PYTHON_VERSION" &> /dev/null; then
echo "错误:未找到 Python3"
exit 1
fi
# 检查 requirements.txt
if [[ ! -f "${RAG_DIR}/requirements.txt" ]]; then
echo "错误:${RAG_DIR}/requirements.txt 不存在"
exit 1
fi
# 创建虚拟环境
mkdir -p "${HOME_DIR}/bin"
"$PYTHON_VERSION" -m venv "${HOME_DIR}/py3"
source "${HOME_DIR}/py3/bin/activate"
# 备份 .bashrc
if [[ -f "${HOME_DIR}/.bashrc" ]]; then
cp "${HOME_DIR}/.bashrc" "${HOME_DIR}/.bashrc.bak"
fi
# 配置环境变量
cat >> "${HOME_DIR}/.bashrc" << EOF
export PATH="${HOME_DIR}/bin:${HOME_DIR}/py3/bin:\$PATH"
source "${HOME_DIR}/py3/bin/activate"
EOF
# 安装依赖
pip install -r "${RAG_DIR}/requirements.txt"
if [[ $? -ne 0 ]]; then
echo "错误:依赖安装失败"
exit 1
fi
# 复制并授权 killname
cp killname "${HOME_DIR}/bin"
chmod +x "${HOME_DIR}/bin/killname"
echo "环境配置完成!"