Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Yes, it is. If the contents of the file is static, then simply include in in the %files section of the spec file.
If the contents of the file is dynamic, and needs to be generated during installation, you can include shell code to run in a %post section in the spec file.
Yes, it is. If the contents of the file is static, then simply include in in the %files section of the spec file.
If the contents of the file is dynamic, and needs to be generated during installation, you can include shell code to run in a %post section in the spec file.
Regards,
Clifford
Hi,
Your answer is quite interessting. The contents of the file is dynamic. Maybe have you an example for me?
Besides, since I have to create several files dynamically, is it possible to put the shell code (for creatig one file) in a separated file?
Last edited by thomas2004ch; 03-28-2013 at 02:22 AM.
Your answer is quite interessting. The contents of the file is dynamic. Maybe have you an example for me?
Besides, since I have to create several files dynamically, is it possible to put the shell code (for creatig one file) in a separated file?
Hi there,
Providing an appropriate example is difficult without more info on what you are trying to do. There are plenty of examples online, though. The "Maximum RPM" guide contains some good documentation, and covers scripts in http://www.rpm.org/max-rpm/s1-rpm-inside-scripts.html. A good of example of a .spec file in general is OpenWall's openssl spec file at http://cvsweb.openwall.com/cgi/cvswe...e=text%2Fplain (see the %build and %install sections; %post could be equally complex).
Anything that can be done in a script can also be done from within the spec file. This includes invocation of any other commands. This implies that you could put the shell code into a separate file, include that in your %files, and then execute it from %post. I would not recommend that if you can avoid it though, as it would leave the unnecessary script behind on the target machine.
I hope this helps. If not, please provide more detail on what exactlyyou're trying to do, and if possible post your current .spec file, then I can try and help further.
I will create a RPM package, assumed it's called my.rpm. I will install this RPM package by means of 'yum install my.rpm'. By installing a file called xxx.properties (xxx is the machine name where the RPM package should be installed) will be created. But the contents in this file depends on the machine name since different machine hat different IP address and may have different JVM size etc. This means, during installation of the RPM packge it will check the LINUX-machine name and according to different machine name it will insert different contents to the file xxx.properties.
The following is a section of my spec file. You can see I use the function 'fill_xxx' to do the insertion. If there are only a few line to be filled, it's ok. But there should be more than 50 lines to be inserted into the file 'xxx.properties'. So I think if it is possible that I put each fill_xxx function into a seperated file.
Code:
...
%define property_file /opt/jboss/%{profile_name}.properties
...
...
%post
...
## Define the filling functions
fill_s001is62() {
echo "this is S001IS62" > %{property_file}
echo "host.address=123.12.23.45" > %{property_file}
...
(further more than 100 lines will be inserted to the %{property_file}
}
fill_s003ap19_test() {
echo "this is S003AP19-TEST" > %{property_file}
echo "host.address=234.22.23.55" > %{property_file}
...
(further more than 100 lines will be inserted to the %{property_file}
}
## Check machine
getent hosts | grep "s001is62$" > /dev/null
if [ $? -eq 0 ]; then
fill_s001is62
fi
getent hosts | grep "s003ap19-test" > /dev/null
if [ $? -eq 0 ]; then
fill_s003ap19_test
fi
...
Last edited by thomas2004ch; 04-03-2013 at 02:00 AM.
There's no limit to how many lines of code you can put in the spec file, but if you prefer to put into separate files, that would work too. Simply put the code into a script that is included in your %files section, and then run it from the %post section.
As an aside, if all the statements in the fill_xxxx() functions are simple echo statements as in the example above, it might be easier to just include the pre-filled %{profile_name}.properties files, say as /opt/jboss/%{profile_name}.properties.s001is62 and /opt/jboss/%{profile_name}.properties.s003ap19-test. Your %post code would then simply need to "cp -p" one of these to /opt/jboss/%{profile_name}.properties, shortening it significantly.
There's no limit to how many lines of code you can put in the spec file, but if you prefer to put into separate files, that would work too. Simply put the code into a script that is included in your %files section, and then run it from the %post section.
As an aside, if all the statements in the fill_xxxx() functions are simple echo statements as in the example above, it might be easier to just include the pre-filled %{profile_name}.properties files, say as /opt/jboss/%{profile_name}.properties.s001is62 and /opt/jboss/%{profile_name}.properties.s003ap19-test. Your %post code would then simply need to "cp -p" one of these to /opt/jboss/%{profile_name}.properties, shortening it significantly.
I'm a little rusty on these details, but I believe everything in %files needs to be under your BuildRoot. Is this the case, or is the /opt/soe/svn-work/jboss-soe/build an absolute path to where they are? If so, you probably want to copy them to the buildroot in your %prep section.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.