blob: 58922ad5210773c18cfc9ef9472490ccb4bdb1ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
%define dist_tag %(sed -n 's/.*release \\([0-9]*\\)\.\\([0-9]*\\).*[Ss][Pp]\\([0-9]*\\).*/oe\\1\\2sp\\3/p; t; s/.*release \\([0-9]*\\)\.\\([0-9]*\\).*/oe\\1\\2/p' /etc/openEuler-release)
%global _unitdir /usr/lib/systemd/system
Name: aops-mcp
Version: 1.0.0
Release: 1.%{?dist_tag}
Summary: Aops MCP Service
License: MulanPSL-2.0
URL: https://gitee.com/Victeo/AOPS_MCP_Server
Source0: %{name}-%{version}.tar.gz
%global debug_package %{nil}
%global _enable_debug_package 0
BuildRequires: python3-setuptools
BuildRequires: python3-pip
Requires: python3
Requires: systemd
%description
Aops MCP Service packaged as RPM.
%prep
%setup -q
%build
# 创建构建目录
mkdir -p %{_builddir}/%{name}-build
# 创建虚拟环境
python3 -m venv %{_builddir}/%{name}-build/venv
# 激活虚拟环境并安装依赖
source %{_builddir}/%{name}-build/venv/bin/activate
pip install --upgrade pip -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
pip install . -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
deactivate
# 修复虚拟环境中的shebang
find %{_builddir}/%{name}-build/venv/bin -type f -name "*.py" -exec \
sed -i "1s|^#!.*|#!%{_builddir}/%{name}-build/venv/bin/python|" {} \;
# 检查主要的可执行文件是否存在
if [ ! -f "%{_builddir}/%{name}-build/venv/bin/aops-mcp" ]; then
echo "错误: aops-mcp 可执行文件未在虚拟环境中找到"
echo "虚拟环境中的文件:"
ls -la "%{_builddir}/%{name}-build/venv/bin/"
exit 1
fi
%install
rm -rf %{buildroot}
# 创建应用目录结构
mkdir -p %{buildroot}/opt/%{name}
mkdir -p %{buildroot}%{_unitdir}
mkdir -p %{buildroot}%{_bindir}
# 复制虚拟环境到目标位置
cp -r %{_builddir}/%{name}-build/venv %{buildroot}/opt/%{name}/
# 再次修复目标位置的shebang
find %{buildroot}/opt/%{name}/venv/bin -type f -exec \
grep -l "^#!" {} \; | xargs sed -i "1s|^#!.*|#!/opt/%{name}/venv/bin/python|"
# 确保可执行文件有正确权限
chmod 755 %{buildroot}/opt/%{name}/venv/bin/aops-mcp
# 安装systemd服务文件
install -m 644 aops-mcp.service %{buildroot}%{_unitdir}/
# 创建符号链接到/usr/bin
ln -sf /opt/%{name}/venv/bin/aops-mcp %{buildroot}%{_bindir}/aops-mcp
# 创建日志和运行目录(如果需要)
mkdir -p %{buildroot}/var/log/%{name}
mkdir -p %{buildroot}/var/run/%{name}
%pre
# 安装前脚本 - 创建必要的用户和组(如果需要)
# getent group aops >/dev/null 2>&1 || groupadd -r aops
# getent passwd aops >/dev/null 2>&1 || useradd -r -g aops -s /sbin/nologin -d /opt/%{name} aops
# 设置目录权限(如果需要特定用户)
# chown -R aops:aops /opt/%{name}
# chown -R aops:aops /var/log/%{name}
# chown -R aops:aops /var/run/%{name}
%files
%defattr(-,root,root,-)
%doc README.md LICENSE
%dir /opt/%{name}
/opt/%{name}/venv/
%{_bindir}/aops-mcp
%{_unitdir}/aops-mcp.service
%dir /var/log/%{name}
%dir /var/run/%{name}
%changelog
* Tue Sep 16 2025 ShiLei <845621916@qq.com> - 1.0.0-1
- Initial package
|