3

I started creating RPM packages for our software, but I am not confident that I am using the system as intended. I would like to create an RPM spec / source package, that I can build on different RPM systems, e.g. fedora, centos and opensuse (which is what I like about rpm).

However, I am starting to realize that many of the scripts in e.g. %pre and %post depend on the distribution. For example, my pre script stops Apache:

service httpd stop

However, this command doesn't work on OpenSUSE. This is just one example, there are many other things in my script that are different between distributions.

So what is the usual way to go about this? Should I just create separate .spec files for each distribution? Or are there tricks to make things portable?

Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207

1 Answers1

2

Add a shell script to the top of your spec file that does a command, something like this:

%define distribution %(sh -c "[ -f /etc/redhat-release ] && cat /etc/redhat-release | awk '{print $1}' || [ -f /etc/SuSE-release ] && head -n1 /etc/SuSE-release | awk '{print $1}' || echo 'Unknown'")

And further down in your %pre and %post etc scripts you can do:

distribution=${distribution}
case $distribution in
    "Fedora")
        # do fedora stuff
    ;;
    "openSUSE")
        # do suse stuff
    ;;
    *)
        # handle error condition
        exit 1
    ;;
esac

And add which ever distribution strings you need, and their assosiated scripting.

Corey Henderson
  • 7,239
  • 1
  • 39
  • 43