rpmbuild: using script files contained in the pack

2019-01-27 04:08发布

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.

标签: rpm rpmbuild
2条回答
地球回转人心会变
2楼-- · 2019-01-27 04:41

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"
查看更多
劫难
3楼-- · 2019-01-27 04:48

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.

查看更多
登录 后发表回答