rpmbuild: using script files contained in the package in %pre script

前端 未结 2 1629
一个人的身影
一个人的身影 2020-12-20 07:15

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

相关标签:
2条回答
  • 2020-12-20 07:37

    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.

    0 讨论(0)
  • 2020-12-20 08:01

    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"
    
    0 讨论(0)
提交回复
热议问题