rpmbuild:使用 %pre 脚本中包中包含的脚本文件

发布于 2024-12-10 15:19:21 字数 266 浏览 0 评论 0 原文

在安装/升级 RPM 软件包之前,我必须对目标系统执行多次复杂的“健全性”检查。我想将该过程与其他附件文件(例如 SQL 脚本)一起包含在脚本(bash/python/php 或其他)中,这些文件不会与其他文件一起安装,但仅在 pre(安装|升级)。

我应该将 rpmbuild 的这些文件放在哪里,以及如何在 %pre 部分和主脚本内调用/引用它们(路径等)?如何引用随后要安装的数据文件(即 SQL 脚本)?

感谢您的任何帮助。

I have to perform multiple elaborate "sanity" checks on target system before an RPM package installs/upgrades. I want to contain the procedure in a script (bash/python/php or otherwise) alongside other accessory files (such as SQL scripts) which wouldn't be installed with other files but only used during pre(install|upgrade).

Where do I put these files for rpmbuild and how do I call/reference them (paths, etc.) inside %pre section and inside main script? How do I reference then-to-be-installed data files (said SQL scripts)?

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天邊彩虹 2024-12-17 15:19:21

RPM 没有这个功能。在我看来,您有两个选择:

  1. 打包文件,将它们编码为文本格式(例如 uuencode),然后在 %pre 中解码和解压它们。丑陋,但可能。

  2. 有一个单独的 RPM(例如 sql-dependencies)来提供这些文件。然后在现有的 RPM 中添加以下内容:

    需要(pre):sql-dependency。

RPM doesn't have this functionality. As I see it, you have two options:

  1. Tar up the files, encode them to a text format (e.g. uuencode) and decode and untar them in the %pre. Ugly, but possible.

  2. Have a separate RPM, say sql-dependencies, that provides these files. Then in your existing RPM add the following:

    Requires(pre) : sql-dependencies.

許願樹丅啲祈禱 2024-12-17 15:19:21

如果您将脚本放入自解压存档中,并将其设为 rpm 脚本,则可以实现这一点。这可以通过 Makeself (直接下载链接)。

使用 footest 作为示例名称,运行以下命令:

makeself.sh --base64 /path/to/footest \
    /path/to/rpm/sources/footest.sh "My foo test" ./run.sh

/path/to/footest 是包含要运行的脚本的目录,./run.sh< /code> 是 footest 目录中的脚本,在提取时运行。

在您的 .spec 文件中,添加 footest.sh 作为源,并将其作为脚本:

%pre -f footest.sh

当您查询 rpm 中的脚本时,它将显示以下内容footest.sh,这是一个 makeself,后跟要运行的测试套件的 base64 编码。

注意:为了使其工作,您必须应用补丁来使自己使用base64编码(当前版本没有此功能),并且rpm不喜欢其二进制数据脚本:

ma​​keself-2.1.5-base64.patch:

diff -ruNp makeself-2.1.5/makeself.sh makeself-2.1.5-base64/makeself.sh
--- makeself-2.1.5/makeself.sh  2008-01-04 16:53:49.000000000 -0700
+++ makeself-2.1.5-base64/makeself.sh   2012-01-17 06:01:42.000000000 -0700
@@ -91,6 +91,7 @@ MS_Usage()
     echo "    --gzip          : Compress using gzip (default if detected)"
     echo "    --bzip2         : Compress using bzip2 instead of gzip"
     echo "    --compress      : Compress using the UNIX 'compress' command"
+    echo "    --base64        : Instead of compressing, encode the data using base64"
     echo "    --nocomp        : Do not compress the data"
     echo "    --notemp        : The archive will create archive_dir in the"
     echo "                      current directory and uncompress in ./archive_dir"
@@ -150,6 +151,10 @@ do
    COMPRESS=Unix
    shift
    ;;
+    --base64)
+   COMPRESS=base64
+   shift
+   ;;
     --encrypt)
    COMPRESS=gpg
    shift
@@ -278,6 +283,10 @@ bzip2)
     GZIP_CMD="bzip2 -9"
     GUNZIP_CMD="bzip2 -d"
     ;;
+base64)
+    GZIP_CMD="base64"
+    GUNZIP_CMD="base64 -d -i"
+    ;;
 gpg)
     GZIP_CMD="gpg -ac -z9"
     GUNZIP_CMD="gpg -d"

This is possible if you put the scripts in a self-extracting archive, and make it the rpm script. This is possible with Makeself (direct link to download).

Using footest as an example name, run this:

makeself.sh --base64 /path/to/footest \
    /path/to/rpm/sources/footest.sh "My foo test" ./run.sh

The /path/to/footest is a directory with your scripts to run, and ./run.sh is the script inside the footest directory, which is ran upon extraction.

In your .spec file, add footest.sh as a source, and put this as the script:

%pre -f footest.sh

When you query your rpm for scripts, it'll show the contents of footest.sh, which is a makeself followed by the base64 encoding of your test suite to run.

NOTE: in order for this to work, you have to apply a patch to makeself to use the base64 encoding (the current release does not have this feature), and rpm doesn't like binary data in its scripts:

makeself-2.1.5-base64.patch:

diff -ruNp makeself-2.1.5/makeself.sh makeself-2.1.5-base64/makeself.sh
--- makeself-2.1.5/makeself.sh  2008-01-04 16:53:49.000000000 -0700
+++ makeself-2.1.5-base64/makeself.sh   2012-01-17 06:01:42.000000000 -0700
@@ -91,6 +91,7 @@ MS_Usage()
     echo "    --gzip          : Compress using gzip (default if detected)"
     echo "    --bzip2         : Compress using bzip2 instead of gzip"
     echo "    --compress      : Compress using the UNIX 'compress' command"
+    echo "    --base64        : Instead of compressing, encode the data using base64"
     echo "    --nocomp        : Do not compress the data"
     echo "    --notemp        : The archive will create archive_dir in the"
     echo "                      current directory and uncompress in ./archive_dir"
@@ -150,6 +151,10 @@ do
    COMPRESS=Unix
    shift
    ;;
+    --base64)
+   COMPRESS=base64
+   shift
+   ;;
     --encrypt)
    COMPRESS=gpg
    shift
@@ -278,6 +283,10 @@ bzip2)
     GZIP_CMD="bzip2 -9"
     GUNZIP_CMD="bzip2 -d"
     ;;
+base64)
+    GZIP_CMD="base64"
+    GUNZIP_CMD="base64 -d -i"
+    ;;
 gpg)
     GZIP_CMD="gpg -ac -z9"
     GUNZIP_CMD="gpg -d"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文