简体   繁体   中英

How to abort the installation of an rpm package if some conditions are not met in specfile?

There are some more things that the Requires tag does not satisfy. So i wrote a script to verify these things but where do I place them ? And if not found then i want to quit installation prompting user to do the steps before attempting to install this rpm again.

writing exit 1 in %install tag fails to build the rpm using rpmbuild. says %install has a bad exit code.

EDIT: let me provide you an example. What i initially wanted to test was is if Oracle Java 6 is present. If not then provide the path to Java6. If user fails to provide one ... exit the RPM. Higher Java is not allowed and installation should not be successful without java. Cannot place it in Requires for a point if user does not want to install a java rpm package.

Hope i got my point through.

You can use the %pre section for this kind of task.

The %pre script executes just before the package is to be installed. It is the rare package that requires anything to be done prior to installation; none of the 350 packages that comprise Red Hat Linux Linux 4.0 make use of it.

Some guide to get you started; the script content (not used in a %pre section) comes from jpackage-utils, you will find some other good examples of scripts there:

  %pre
  # try to find jvm from java command

  # try javac first, or we might get the location of the jre instead - djw
  java=`which javac 2>/dev/null || :`

  # if we don't have the jdk, then maybe we have the jre - djw
  if [ -z "$java" ] ; then
    java=`which java 2>/dev/null || :`
  fi

  if [ -n "$java" ] ; then
    while [ -h "$java" ] ; do
      java=`readlink $java 2>/dev/null`
    done
    return
  fi

  echo "Can't find java virtual machine, aborting."
  exit 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM