RPM
RPM 打包
¥Packaging for RPM
:::note 注意
本指南中的某些部分是可选的。这包括配置脚本和某些其他步骤。请根据你的特定需求和要求随意调整说明。
¥Some sections in this guide are optional. This includes configuring scripts and certain other steps. Feel free to adapt the instructions based on your specific needs and requirements.
:::
本指南介绍如何分发和管理 RPM 包,包括检索包信息、配置脚本、设置依赖和签名包。
¥This guide covers how to distribute and manage RPM packages, including retrieving package information, configuring scripts, setting dependencies, and signing packages.
配置 RPM 包
¥Configuring the RPM package
Tauri 允许你通过添加脚本、设置依赖、添加许可证、包括自定义文件等来配置 RPM 包。有关可配置选项的详细信息,请参阅:RpmConfig。
¥Tauri allows you to configure the RPM package by adding scripts, setting dependencies, adding a license, including custom files, and more. For detailed information about configurable options, please refer to: RpmConfig.
向包添加发布、预安装/删除脚本
¥Add post, pre-install/remove script to the package
RPM 包管理器允许你在安装或删除包之前或之后运行脚本。例如,你可以使用这些脚本在安装包后启动服务。
¥The RPM package manager allows you to run scripts before or after the installation or removal of the package. For example, you can use these scripts to start a service after the package is installed.
以下是如何添加这些脚本的示例:
¥Here’s an example of how to add these scripts:
-
在项目的
src-tauri
目录中创建一个名为scripts
的文件夹。¥Create a folder named
scripts
in thesrc-tauri
directory in your project.
mkdir src-tauri/scripts
-
在文件夹中创建脚本文件。
¥Create the script files in the folder.
touch src-tauri/scripts/postinstall.sh \touch src-tauri/scripts/preinstall.sh \touch src-tauri/scripts/preremove.sh \touch src-tauri/scripts/postremove.sh
现在如果我们查看 /src-tauri/scripts
内部,我们将看到:
¥Now if we look inside /src-tauri/scripts
we will see:
ls src-tauri/scripts/postinstall.sh postremove.sh preinstall.sh preremove.sh
-
向脚本添加一些内容
¥Add some content to the scripts
echo "-------------"echo "This is pre"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"
echo "-------------"echo "This is post"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"
echo "-------------"echo "This is preun"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"
echo "-------------"echo "This is postun"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"
-
将脚本添加到
tauri.conf.json
文件¥Add the scripts to the
tauri.conf.json
file
{ "bundle": { "linux": { "rpm": { "epoch": 0, "files": {}, "release": "1", // add the script here "preInstallScript": "/path/to/your/project/src-tauri/scripts/prescript.sh", "postInstallScript": "/path/to/your/project/src-tauri/scripts/postscript.sh", "preRemoveScript": "/path/to/your/project/src-tauri/scripts/prescript.sh", "postRemoveScript": "/path/to/your/project/src-tauri/scripts/postscript.sh" } } }}
设置冲突、提供、依赖、文件、过时、桌面模板和纪元
¥Setting the Conflict, Provides, Depends, Files, Obsoletes, DesktopTemplate, and Epoch
-
冲突:如果软件包与另一个软件包冲突,则防止安装该软件包。例如,如果你更新应用所依赖的 RPM 包,而新版本与你的应用不兼容。
¥conflict: Prevents the installation of the package if it conflicts with another package. For example, if you update an RPM package that your app depends on and the new version is incompatible with your app.
-
提供:列出应用提供的 RPM 依赖。
¥provides: Lists the RPM dependencies that your application provides.
-
依赖:列出应用运行所需的 RPM 依赖。
¥depends: Lists the RPM dependencies that your application needs to run.
-
文件:指定要包含在包中的文件。
¥files: Specifies which files to include in the package.
-
已过时:列出你的应用所淘汰的 RPM 依赖。
¥obsoletes: Lists the RPM dependencies that your application obsoletes.
:::note 注意
如果安装了此软件包,则列出的“过时”软件包(如果存在)将自动删除。
¥If this package is installed, packages listed as “obsoletes” will be automatically removed if present.
:::
-
桌面模板:向包中添加自定义桌面文件。
¥desktopTemplate: Adds a custom desktop file to the package.
-
时代:根据版本号定义加权依赖。
¥epoch: Defines weighted dependencies based on version numbers.
:::caution 提醒
除非必要,否则不建议使用 epoch,因为它会改变包管理器比较包版本的方式。有关 epoch 的更多信息,请查看:RPM 打包指南。
¥It is not recommended to use epoch unless necessary, as it alters how the package manager compares package versions. For more information about epoch, please check: RPM Packaging Guide.
:::
要使用这些选项,请将以下内容添加到你的 tauri.conf.json
:
¥To use these options, add the following to your tauri.conf.json
:
{ "bundle": { "linux": { "rpm": { "postRemoveScript": "/path/to/your/project/src-tauri/scripts/postscript.sh", "conflicts": ["oldLib.rpm"], "depends": ["newLib.rpm"], "obsoletes": ["veryoldLib.rpm"], "provides": ["coolLib.rpm"], "desktopTemplate": "/path/to/your/project/src-tauri/desktop-template.desktop" } } }}
向包添加许可证
¥Add a license to the package
要向软件包添加许可证,请将以下内容添加到 src-tauri/cargo.toml
或 src-tauri/tauri.conf.json
文件中:
¥To add a license to the package, add the following to the src-tauri/cargo.toml
or in the src-tauri/tauri.conf.json
file:
[package]name = "tauri-app"version = "0.0.0"description = "A Tauri App"authors = ["you"]edition = "2021"license = "MIT" # add the license here# ... rest of the file
对于 src-tauri/tauri.conf.json
¥And for src-tauri/tauri.conf.json
{ "bundle": { "licenseFile": "../LICENSE", // put the path to the license file here "license": "MIT" // add the license here }}
构建 RPM 包
¥Building the RPM package
要构建 RPM 包,你可以使用以下命令:
¥To build the RPM package, you can use the following command:
npm run tauri build
yarn tauri build
pnpm tauri build
deno task tauri build
cargo tauri build
此命令将在 src-tauri/target/release/bundle/rpm
目录中构建 RPM 包。
¥This command will build the RPM package in the src-tauri/target/release/bundle/rpm
directory.
为 RPM 包签名
¥Signing the RPM package
Tauri 允许你在构建过程中使用系统中的密钥对包进行签名。为此,你需要生成 GPG 密钥。
¥Tauri allows you to sign the package with the key you have in your system during the build process. To do this, you will need to generate a GPG key.
生成 GPG 密钥
¥Generate a GPG key
要生成 GPG 密钥,你可以使用以下命令:
¥To generate a GPG key you can use the following command:
gpg --gen-key
按照说明生成密钥。
¥Follow the instruction to generate the key.
生成密钥后,你需要将其添加到环境变量中。你可以通过将以下内容添加到 .bashrc 或 .zshrc 文件或直接在终端中导出来执行此操作:
¥Once the key is generated, you will need to add it to your environment variable. You can do this by adding the following to your .bashrc or .zshrc file or just export it in the terminal:
export TAURI_SIGNING_RPM_KEY=$(cat /home/johndoe/my_super_private.key)
如果你有密钥的密码,你可以将其添加到环境变量中:
¥If you have a passphrase for the key, you can add it to the environment variable:
export TAURI_SIGNING_RPM_KEY_PASSPHRASE=password
现在你可以使用以下命令构建包:
¥Now you can build the package with the following command:
npm run tauri build
yarn tauri build
pnpm tauri build
deno task tauri build
cargo tauri build
验证签名
¥Verify the signature
:::note 注意
这应该只用于本地测试签名。
¥This should be done only to test the signature locally.
:::
在验证签名之前,你需要创建公钥并将其导入 RPM 数据库:
¥Before verifying the signature, you will need to create and import the public key to the RPM database:
gpg --export -a 'Tauri-App' > RPM-GPG-KEY-Tauri-App
sudo rpm --import RPM-GPG-KEY-Tauri-App
现在密钥已导入,我们必须编辑 ~/.rpmmacros
文件以使用该密钥。
¥Now that the key is imported, we have to edit the ~/.rpmmacros
file to utilize the key.
%_signature gpg%_gpg_path /home/johndoe/.gnupg%_gpg_name Tauri-App%_gpgbin /usr/bin/gpg2%__gpg_sign_cmd %{__gpg} \ gpg --force-v3-sigs --digest-algo=sha1 --batch --no-verbose --no-armor \ --passphrase-fd 3 --no-secmem-warning -u "%{_gpg_name}" \ -sbo %{__signature_filename} %{__plaintext_filename}
最后,你可以使用以下命令验证包:
¥Finally, you can verify the package using the following command:
rpm -v --checksig tauri-app-0.0.0-1.x86_64.rpm
调试 RPM 包
¥Debugging the RPM package
在本节中,我们将了解如何通过检查包的内容并获取有关包的信息来调试 RPM 包。
¥In this section, we will see how to debug the RPM package by checking the content of the package and getting information about the package.
获取有关包的信息
¥Getting information about the package
要获取有关软件包的信息,例如版本、发布和体系结构,请使用以下命令:
¥To get information about your package, such as the version, release, and architecture, use the following command:
rpm -qip package_name.rpm
查询有关包的特定信息
¥Query specific information about the package
例如,如果你想获取包的名称、版本、发布、架构和大小,请使用以下命令:
¥For example, if you want to get the name, version, release, architecture, and size of the package, use the following command:
rpm -qp --queryformat '[%{NAME} %{VERSION} %{RELEASE} %{ARCH} %{SIZE}\n]' package_name.rpm
:::note 注意
--queryformat
是一种格式字符串,可用于获取有关软件包的特定信息。可以检索的信息来自 rpm -qip 命令。
¥--queryformat
is a format string that can be used to get specific information about the package.
The information that can be retrieved is from the rpm -qip command.
:::
检查包的内容
¥Checking the content of the package
要检查包的内容,请使用以下命令:
¥To check the content of the package, use the following command:
rpm -qlp package_name.rpm
此命令将列出包中包含的所有文件。
¥This command will list all the files that are included in the package.
调试脚本
¥Debugging scripts
要调试安装后/安装前/删除脚本,请使用以下命令:
¥To debug post/pre-install/remove scripts, use the following command:
rpm -qp --scripts package_name.rpm
此命令将打印脚本的内容。
¥This command will print the content of the scripts.
检查依赖
¥Checking dependencies
要检查包的依赖,请使用以下命令:
¥To check the dependencies of the package, use the following command:
rpm -qp --requires package_name.rpm
列出依赖于特定软件包的软件包
¥List packages that depend on a specific package
要列出依赖于特定包的包,请使用以下命令:
¥To list the packages that depend on a specific package, use the following command:
rpm -q --whatrequires package_name.rpm
调试安装问题
¥Debugging Installation Issues
如果你在安装 RPM 包时遇到问题,可以使用 -vv
(非常详细)选项获取详细输出:
¥If you encounter issues during the installation of an RPM package,
you can use the -vv
(very verbose) option to get detailed output:
rpm -ivvh package_name.rpm
或者对于已安装的软件包:
¥Or for an already installed package:
rpm -Uvvh package_name.rpm
Tauri 中文网 - 粤ICP备13048890号