LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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

Reply
 
Search this Thread
Old 03-27-2013, 06:41 AM   #1
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 502

Rep: Reputation: 31
Create file in the *.spec for RPM


Hi,

I am going to write a spec file for RPM, which will create a file and insert contents into this file during yum install my.rpm.

Is this possible?
 
Old 03-27-2013, 11:51 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 281

Rep: Reputation: 118Reputation: 118
Hi there,

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
 
Old 03-28-2013, 03:20 AM   #3
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 502

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by cliffordw View Post
Hi there,

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 03:22 AM.
 
Old 04-02-2013, 03:03 AM   #4
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 502

Original Poster
Rep: Reputation: 31
up!
 
Old 04-02-2013, 10:52 AM   #5
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 281

Rep: Reputation: 118Reputation: 118
Quote:
Originally Posted by thomas2004ch View Post
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?
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.

Regards,

Clifford
 
Old 04-03-2013, 02:45 AM   #6
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 502

Original Poster
Rep: Reputation: 31
Hi,

Here is my situation and what I wnat to do:

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 03:00 AM.
 
Old 04-03-2013, 04:22 AM   #7
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 281

Rep: Reputation: 118Reputation: 118
Hi again,

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.

Good luck!
 
1 members found this post helpful.
Old 04-03-2013, 04:51 AM   #8
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 502

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by cliffordw View Post
Hi again,

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.

Good luck!
Many thanks!
 
Old 04-03-2013, 05:47 AM   #9
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 502

Original Poster
Rep: Reputation: 31
Hi,

Sorry again.

I did what you recommended that I put the xxx.properties under a directory and the spec looks as follow:

Code:
...
#### Files for the profile packages
%files -f %{_tmppath}/profile.filelist
%config(noreplace)%{cfg_basedir}/configuration/jboss_%{profile_name}_sysconfig
%defattr(-,%{runas_user},%{runas_group},-)
/opt/soe/svn-work/jboss-soe/build/propertie

...
But as I run the rpm I got error like:

Code:
...
[rpm] error: File not found: /opt/soe/svn-build/rpm/buildroot/jboss-eap6-test-6.0.1/opt/soe/svn-work/jboss-soe/build/propertie
[rpm]     File not found: /opt/soe/svn-build/rpm/buildroot/jboss-eap6-test-6.0.1/opt/soe/svn-work/jboss-soe/build/propertie
What could be the reason?

It seems it just read the files under '%{_tmppath}/profile.filelist'. This is quite strange.

Last edited by thomas2004ch; 04-03-2013 at 05:56 AM.
 
Old 04-03-2013, 05:59 AM   #10
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 281

Rep: Reputation: 118Reputation: 118
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LFS RPM SPEC files: Binutils RPM spec for x86 arch nocountryman Linux From Scratch 2 10-25-2010 10:09 AM
how to create a directory in RPM SPEC file? anadem Linux - Software 7 12-02-2008 06:40 PM
rpm spec file help AutoC Fedora 3 01-30-2008 09:25 AM
rpm spec file alrawab Linux - General 2 03-28-2007 07:39 AM
RPM Spec file adddy Linux - Software 8 11-07-2006 06:02 AM


All times are GMT -5. The time now is 04:15 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration