I'm trying to package a product consisting of many packages.
I'm successful with writing all the spec files, the dependencies between the packages and so on. They're all installed and work fine.
The one thing I do not succeed to do, is to run a pre-requisition test: In certain cases, I would like the packages not to be installed at all, and the user getting an error, explaining him what he needs to fix first, before he runs the packages installation.
For example: I want to verify that the user is running in runlevel 3, and if not, abort the whole installation, and ask the user to re-install CentOS in "Minimal" profile - as I don't want all the extra packages that comes with "Desktop". (This is just an example, I have a few such tests to perform).
The way I approached this problem is this:
I've created a sort of 'meta package', that its name appears in all the other packages 'Requires:' directive, so it would be installed first by YUM, and in that package spec file, in the %pre
section, I did the various tests I wanted to perform, outputting test errors when applicable, and then 'exit 1
'.
The reason I chose this approach is this: "If every package depends on this package, and this package cannot be installed, the transaction must fail, as soon as the package manager wants to install a package that depends on a package that failed installation... after all, the dependency has not been met". In Gentoo, for example, if a package fails installation, for whatever reason, emerge stops completely – even not for dependency issues; And there's a special flag to tell emerge to continue despite the error returned from one of the packages.
The problem is that indeed the package fails when the tests fails (RPM specifically says that it returned code 1), BUT... YUM doesn't really seem to care that this happens - and just continues to install everything else, including packages that depend on a package that is not installed (!). At the very end, it simply reports that all the packages were installed successfully, expect for the package that deliberately failed...
I'm guessing that the reason for that is that dependency checking happens before the transaction begins, and indeed, dependencies are met from the various repositories at YUM's disposal. Still, it does not make any sense to me that if a dependency eventually failed, the installation of dependent packages would continue.
Is my logic flawed? I doubt it's a bug, as someone would have encountered it by now (this is on CentOS 6.3 if it matters...) – but all my Google-foo yielded nothing. I didn't even find someone asking the same question... maybe I'm using the wrong keywords?
Am I approaching this wrong way? Any other idea (that fits into RPM specs or other YUM repository magic, even at the YUM .repo file... – but all contained within the YUM infrastructure, without external scripts to run before 'yum install') – would be greatly appreciated!