2

I am building an RPM package that packages the various files that includes properties files, config files, scripts, JARs etc. Now when writing the %pre, %post, %preun and %postun scritptlets, I need to make use of some of the scripts that I have in say scripts/ folder (which has been packaged in RPM). So, I want to be able to do something like this:

%pre
export scripts/important.sh
someFunctionFromImportant parameter
%post
. scripts/anotherScript.sh
someFuncFromAnotherScript parameters

Now, since I want to be able to just copy paste this RPM on any system and just install it and the %pre and %post scriptlests must run. I have already gone through so many tutorials and still searching for a way to accomplish this. Note: My requirements do not allow me to have those scripts already present on that system where the RPM is being installed. It is like from the RPM file itself, everything should happen cleanly, the install along with the pre and post install scripts.

2

What you want to do isn't possible the way I understand your question. The %pre scriptlet is run before anything from the RPM is available on disk, so it cannot reference anything from the package. The %post scriptlet, on the other hand, is run after the package payload has been put into place, so that part is fine. For more details on the order in which operations occur for install/upgrade/removal of RPM packages, you can see https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Scriptlet_Ordering. While this URL is specific to the Fedora project, the information therein should be valid for any RPM-based linux distribution.

  • when %pre is to run, the RPM file (in non-extracted form) is available. I was wondering whether we could somehow reference files inside the RPM package like whatever is written in %pre section is available to trigger even though the RPM is still not extracted/installed. So, the way the code of %pre section is available somehow, I hope there will be some way that allows us to reference some other files directly in %pre section. – iamharish15 Feb 22 '16 at 19:27
  • No, you are not able to reference files inside the RPM payload from the %pre scriptlet. – John Feb 22 '16 at 19:31
  • okay. But could you suggest me any other workaround to achieve what I am trying to do? I mean where else can I put common scripts so that I can utilize them in my %pre scripts, invoke them etc. I am hopeful that there should be some workaround this to achieve that. – iamharish15 Mar 3 '16 at 19:06
0

If you have prerequisites that need to be available in %pre, create another rpm and depend on it. It's either that, or you do something terrible like curling in the files you need. I think a my-project-tools rpm or the like containing your prerequisites is best.

  • Personally, I build my rpms in gradle, so I actually assemble snippets of scripts and put them in both the %pre section so that they run on install, but are also included as files with 100% the same content, so developers can run them directly if they need to do something exotic. – Ajax Jun 26 '18 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.