first commit
This commit is contained in:
135
rpmbuild/SPECS/smarttms-config.spec
Normal file
135
rpmbuild/SPECS/smarttms-config.spec
Normal file
@@ -0,0 +1,135 @@
|
||||
Name: smarttms
|
||||
Version: 1.0
|
||||
Release: 1%{?dist}
|
||||
Summary: SmartTMS application suite for managing smart devices.
|
||||
|
||||
# 禁用 debuginfo 包的生成
|
||||
%define debug_package %{nil}
|
||||
%global __debug_install_post %{nil}
|
||||
|
||||
License: Proprietary
|
||||
URL: https://your.company.com/smarttms
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
|
||||
# BuildRequires 是构建 RPM 包所需的工具,这里主要是复制和打包,所以通常不需要太多
|
||||
# BuildRequires: tar, gzip # 这些通常是系统自带的,不需要显式列出
|
||||
|
||||
# Requires 是安装 RPM 包后,应用程序运行时所需的依赖。
|
||||
# 如果你的 smarttms.service 依赖 Java 或特定的运行时环境,需要在这里添加。
|
||||
# 例如:Requires: java-1.8.0-openjdk
|
||||
|
||||
|
||||
%description
|
||||
This package installs the SmartTMS application suite, including a
|
||||
Tomcat server, a starter application, a custom command-line tool,
|
||||
and a systemd service for automatic startup. It also configures
|
||||
sudoers for the 'smart' user and places application shortcuts.
|
||||
|
||||
# --- 准备阶段 ---
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
# 修复模糊的 Python shebangs
|
||||
# 假设这些脚本是 Python 3。如果它们是 Python 2 脚本,请将 'python3' 改为 'python2'。
|
||||
# 查找所有 .py 文件,将 #!/usr/bin/env python 替换为 #!/usr/bin/env python3
|
||||
find . -type f -name "*.py" -exec sed -i 's|^#!/usr/bin/env python$|#!/usr/bin/env python3|g' {} +
|
||||
# 查找所有 .py 文件,将 #!/usr/bin/python 替换为 #!/usr/bin/python3
|
||||
find . -type f -name "*.py" -exec sed -i 's|^#!/usr/bin/python$|#!/usr/bin/python3|g' {} +
|
||||
# 针对日志中提到的 websockify/run 文件,它没有 .py 后缀
|
||||
sed -i 's|^#!/usr/bin/python$|#!/usr/bin/python3|g' apache-tomcat-7.0.63/webapps/noVNC-master/utils/websockify/run
|
||||
|
||||
|
||||
|
||||
# --- 构建阶段 ---
|
||||
%build
|
||||
# 你的原始脚本没有编译步骤,所以此部分为空。
|
||||
|
||||
# --- 安装阶段 ---
|
||||
%install
|
||||
# %{buildroot} 是一个临时目录,模拟最终的根文件系统。
|
||||
|
||||
# 1. 创建目标目录
|
||||
mkdir -p %{buildroot}/home/smart/.tms3/apache-tomcat-7.0.63
|
||||
mkdir -p %{buildroot}/home/smart/.tms3/starter
|
||||
mkdir -p %{buildroot}%{_bindir} # /usr/bin
|
||||
mkdir -p %{buildroot}%{_sysconfdir}/sudoers.d # /etc/sudoers.d
|
||||
mkdir -p %{buildroot}%{_unitdir} # /etc/systemd/system 或 /usr/lib/systemd/system
|
||||
mkdir -p %{buildroot}%{_datadir}/applications # /usr/share/applications
|
||||
|
||||
# 2. 复制文件
|
||||
cp -r apache-tomcat-7.0.63/* %{buildroot}/home/smart/.tms3/apache-tomcat-7.0.63/
|
||||
cp -r starter/* %{buildroot}/home/smart/.tms3/starter/
|
||||
cp smarttms %{buildroot}%{_bindir}/smarttms
|
||||
cp smart %{buildroot}%{_sysconfdir}/sudoers.d/smart # sudoers.d 文件
|
||||
cp smarttms.service %{buildroot}%{_unitdir}/smarttms.service # systemd 服务文件
|
||||
cp starter/tmsrestart.desktop %{buildroot}%{_datadir}/applications/tmsrestart.desktop # 桌面快捷方式
|
||||
|
||||
# --- 文件列表 ---
|
||||
%files
|
||||
# 列出 RPM 包中包含的所有文件和目录。
|
||||
# 路径必须是相对于根目录 (/) 的绝对路径。
|
||||
# %attr(MODE, USER, GROUP) 用于设置文件权限和所有者。
|
||||
# %dir 用于明确声明一个目录。
|
||||
|
||||
# /home/smart/.tms3 目录及其内容
|
||||
# 警告:此路径假设 /home/smart 存在且可写。
|
||||
# 777 权限非常开放,请确保这是你的意图。
|
||||
# 如果该目录可能包含用户生成的数据,RPM 卸载时不会强制删除非 RPM 跟踪的文件。
|
||||
%attr(0777, root, root) %dir /home/smart/.tms3
|
||||
%attr(0777, root, root) %dir /home/smart/.tms3/apache-tomcat-7.0.63
|
||||
/home/smart/.tms3/apache-tomcat-7.0.63/*
|
||||
%attr(0755, root, root) %dir /home/smart/.tms3/starter
|
||||
/home/smart/.tms3/starter/*
|
||||
|
||||
# /usr/bin/smarttms
|
||||
%attr(0755, root, root) %{_bindir}/smarttms
|
||||
|
||||
# /etc/sudoers.d/smart
|
||||
%attr(0440, root, root) %config(noreplace) %{_sysconfdir}/sudoers.d/smart
|
||||
|
||||
# /etc/systemd/system/smarttms.service
|
||||
%attr(0755, root, root) %config(noreplace) %{_unitdir}/smarttms.service
|
||||
|
||||
# /usr/share/applications/tmsrestart.desktop
|
||||
%attr(0644, root, root) %{_datadir}/applications/tmsrestart.desktop
|
||||
|
||||
|
||||
# --- 安装后脚本 ---
|
||||
%post
|
||||
# 这个脚本在 RPM 包安装完成后执行。
|
||||
# 1. 重新加载 systemd 配置,启用并启动服务
|
||||
systemctl daemon-reload >/dev/null 2>&1 || :
|
||||
systemctl enable smarttms.service >/dev/null 2>&1 || :
|
||||
systemctl start smarttms.service >/dev/null 2>&1 || :
|
||||
|
||||
# 2. 更新桌面快捷方式缓存 (重要,让系统识别新的 .desktop 文件)
|
||||
update-desktop-database %{_datadir}/applications >/dev/null 2>&1 || :
|
||||
|
||||
# --- 卸载前脚本 ---
|
||||
%preun
|
||||
# 这个脚本在 RPM 包卸载前执行。
|
||||
# 1. 停止并禁用 systemd 服务
|
||||
systemctl stop smarttms.service >/dev/null 2>&1 || :
|
||||
systemctl disable smarttms.service >/dev/null 2>&1 || :
|
||||
|
||||
%postun
|
||||
# 这个脚本在 RPM 包卸载后执行。
|
||||
# 1. 重新加载 systemd 配置 (清理服务配置)
|
||||
systemctl daemon-reload >/dev/null 2>&1 || :
|
||||
|
||||
# 2. 更新桌面快捷方式缓存 (移除旧的 .desktop 文件)
|
||||
update-desktop-database %{_datadir}/applications >/dev/null 2>&1 || :
|
||||
|
||||
# 3. 清理 /home/smart/.tms3 目录 (可选,如果确定没有用户数据)
|
||||
# 注意:RPM 会自动删除 %files 中列出的文件。
|
||||
# 如果该目录中存在非 RPM 安装的文件,RPM 不会删除该目录。
|
||||
# 如果你希望在卸载时强制删除整个 .tms3 目录,即使里面有其他文件,
|
||||
# 可以添加以下命令,但请慎重考虑数据丢失的风险。
|
||||
# if [ -d /home/smart/.tms3 ] && [ -z "$(ls -A /home/smart/.tms3)" ]; then
|
||||
# rmdir /home/smart/.tms3 >/dev/null 2>&1 || :
|
||||
# fi
|
||||
|
||||
%changelog
|
||||
* Fri Dec 05 2025 Your Name <your.email@example.com> - 1.0-1
|
||||
- Initial RPM packaging of SmartTMS application suite with systemd, sudoers.d,
|
||||
- and /usr/share/applications desktop shortcut.
|
||||
Reference in New Issue
Block a user