Operating System - Linux
1828690 Members
2255 Online
109984 Solutions
New Discussion

Re: Redhat Linux package "rpmbuild" question

 
Allison1
Occasional Contributor

Redhat Linux package "rpmbuild" question

Hello,

How are you?

Sorry to bother, I just have a quick question regarding Redhat Linux 3.0 & 4.0 packaging via rpmbuild.

For some packages, we have to run shell scripts before package is installed and after package is installed. I know I can put shell scripts into "pkg.spec" file as "%pre" and "%post" before performing "rpmbuild". But this way will make the "pkg.sepc" file very long and not easy to troubleshoot. I would like to use seperate pre shell script and post shell script, but I am not sure how to integragte them into the "pkg.spec" file in order to run shell scripts before package instlalation, and after installation.

For instance, pkg.spec file

Summary: test
name: test

%pre

ksh /tmp/pkgpre.sh ????
(syntax to integrate the shell pre script; need to put shell into specific location?

% post
ksh /tmp/pkgpost.sh ???
syntax to integrate the shell pre script; need to put shell into specific location?


If you can advise when you get a chance, I would appreciate it.

Thank you in advance
4 REPLIES 4
Alexander Chuzhoy
Honored Contributor

Re: Redhat Linux package "rpmbuild" question

Hello,
I've never added shell scripts, but the document of creating RPM has these lines:
You can put scripts in that get run before and after the installation and uninstallation of binary packages. A main reason for this is to do things like run ldconfig after installing or removing packages that contain shared libraries. The macros for each of the scripts is as follows:


%pre is the macro to do pre-install scripts.

%post is the macro to do post-install scripts.

%preun is the macro to do pre-uninstall scripts.

%postun is the macro to do post-uninstall scripts.

The contents of these sections should just be any sh style script, though you do not need the #!/bin/sh.

So, I'd recommend you to get rid of the preceding ksh and so that in %post section for example you have only /tmp/pkgpost.sh

Hope it helps.
Allison1
Occasional Contributor

Re: Redhat Linux package "rpmbuild" question

Hello, Alexander

Thank you very much for the information.

The issue I have is that the shell scripts for pre, post are very long, if I put them into the "pkg.spec" file, it would make the spec file too long to read & throubleshooting.

I would think I can use seperate shell scripts, just not sure how to integrate them into the spec file. I went through some Linux package docs, none of them mentions it. Any recommendations?

Thanks again.
Stuart Browne
Honored Contributor

Re: Redhat Linux package "rpmbuild" question

The method you used was correct, assuming these files existed at this point (which they wouldn't in %pre, but possibly in %post).

I think what Alexander was mentioning was that most systems don't have 'ksh' installed on them.

For %pre, try to cut it down to the essentials, and put it in the SPEC file directly.

For the %post, you can do basically anything you want, as you can include any files you want in the RPM it's self.
One long-haired git at your service...
Manuel Wolfshant
Trusted Contributor

Re: Redhat Linux package "rpmbuild" question

rpm should NOT call external scripts, for the simple reasons that this would be a MAJOR security risk. How can you be sure that the script that will be run is indeed the script that YOU want to be run, and not a fake one with the same name ?

I strongly suggest to read the wiki pages located here:http://fedoraproject.org/wiki/Packaging/Guidelines