1

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

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

谢谢你的帮助。

4

2 回答 2

3

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

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

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

    Requires(pre) : sql 依赖项。

于 2011-10-19T21:39:09.160 回答
1

如果您将脚本放在自解压存档中,并使其成为 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的脚本的目录,并且是footest 目录中的脚本,它在提取时运行。

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

%pre -f footest.sh

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

注意:为了让它工作,你必须应用一个补丁来 makeself 使用 base64 编码(当前版本没有这个功能),并且 rpm 不喜欢它的脚本中的二进制数据:

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"
于 2012-01-17T16:21:14.867 回答