LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-02-2008, 07:05 AM   #1
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Rep: Reputation: 15
RPM Package creation question


Hello all,

I am trying to create an RPM package. I just want a collection of config files to reside on this package and they should replace their counterparts on the ramdisk that I have created. Therefore, there is nothing to compile and link.
Here is the spec file that I am using:

Code:
%define name patches
%define version 1.0
%define release 1

Summary: Patches some of the configuration files in the MontaVista filesystem.
Name: %{name}
Version: %{version}
Release: %{release}
Source:  %{name}-%{version}-%{release}.tar.gz
License: GPL
Group: System/Base
BuildRoot: %{_builddir}/%{name}
%description
This package changes the following configuration files:
/etc/resolv.conf
%prep
#this line simply unpacks the sources and cd's into the source directory, no need to modify it
%setup -q
%build
#Place commands to build the program here. Nothing to build, just a config file that needs to be copied over. 
%install
#RPM uses a build root, the directory where RPM does its work, compiling and linking the files, and finally getting the files from there when they need to be added to an RPM. When you install the RPM later on, the files will end up in their proper directories, i.e. $RPM_BUILD_ROOT will just be stripped off.

#this line creates a directory with the necessary parents (-p) starting from RPM_BUILD_ROOT (RPM_BUILD_ROOT is $HOME/RPM/BUILD/PROGRAM_NAME usually). Replace WHERE_TO_INSTALL with a meaningful path ( /temp/USERNAME, where USERNAME is your username, is good for testing purposes).
mkdir -p $RPM_BUILD_ROOT/temp/rahul
#this line copies the file PROGRAM_NAME to the destination directory, strips its symbol tables and sets permissions
install -s -m 755 resolv.conf $RPM_BUILD_ROOT/temp/rahul/resolv.conf
%files
# this line sets the permissions, owner and group of the files in this order. Replace USER and GROUP with your user and group (use the id command to find out username and group)
%defattr(755, root, root)
#List which files to put in the binary RPM (from the location where we installed them, look at the install section)
resolv.conf
And here is my build log
Code:
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.32076
+ umask 022
+ cd /home/rahul/RPM/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/rahul/RPM/BUILD
+ rm -rf patches-1.0
+ /usr/bin/gzip -dc /home/rahul/RPM/SOURCES/patches-1.0-1.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd patches-1.0
/var/tmp/rpm-tmp.32076: line 34: cd: patches-1.0: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.32076 (%prep)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.32076 (%prep)
If someone could point me where I am going wrong, I would be really thankful.
 
Old 07-02-2008, 07:52 AM   #2
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,189

Rep: Reputation: 49
by the error it seems that the program tries to cd into patches-1.0

What I think is you are missing a patches-%{version}-%{release}
"release part"

Have you posted the complete spec file?
 
Old 07-02-2008, 08:13 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
...not only that but also:
- Don't use comments that make no sense.
- Don't use "install -s" if there's nothing to strip.
- Don't install configuration files with octal mode 0755.
- Don't soil your own nest (build root) but use temp dir instead: (in your ~/.rpmmacros: %_topdir and %_tmppath).
- Do clean up your mess when you're done (rm build root).
* Do read the basic RPM.org docs and "Maximum RPM". It *will* help.

Try this:
Code:
%define debug_packages	%{nil}
%define debug_package %{nil}

%define name patches
%define version 1.0
%define release 1

Summary: Patch MontaVista filesystem configuration files.
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{version}-%{release}.tar.gz
License: GPL
Group: System/Base
BuildRoot: %{_tmppath}/%{name}-%{version}

%description
This package changes the following configuration files: /etc/resolv.conf

%prep

%setup -q

%build

%install
mkdir -p $RPM_BUILD_ROOT/etc
install -m 644 etc/resolv.conf $RPM_BUILD_ROOT/etc/resolv.conf

%clean
if [ "$RPM_BUILD_ROOT" = "%{_tmppath}/%{name}-%{version}" ]; then
	rm -rf $RPM_BUILD_ROOT
else
	echo Invalid Buildroot \'"$RPM_BUILD_ROOT"\'
	exit 1
fi

%files
%defattr(755, root, root)
%attr(644,root,root) %config %{_sysconfdir}/resolv.conf

%changelog
* Wed Jul 02 2008 %package - 
- Freeform changelog, fixed format date line. Newest entries top.
 
Old 07-02-2008, 08:34 AM   #4
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
The spec file that I posted was complete. Also, unSpawn thanks for your hints. I tried the spec file that you posted, however I still get the same error.
However, then I realized that the error there was my tar file was incorrect. I had named my folder simply patches wherein it was expected to be patches-1.0. Guess, I should have read the documentation but I am in a hurry.
And that solved my problem. However, if it is not too much of a bother, could you also tell me how to create this package to be specific for the arm architecture. The architecture is called arm_v5t_le. So, if I just create a folder with the arch name, and put it in the folder RPMS, that would compile a package for this arch?

Thanks for your answers and patience, I am quite a newbie when it comes to RPM in general.

EDIT: rpmbuild --target ....

Should have read the man pages.

Last edited by rahulthewall3000; 07-02-2008 at 09:12 AM.
 
Old 07-02-2008, 09:16 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
Quote:
Originally Posted by rahulthewall3000 View Post
I should have read the documentation but I am in a hurry.
Doesn't that just means you got your priorities wrong? Sure, reading docs cost time but can save much more time. Anyway, it's your choice.


Quote:
Originally Posted by rahulthewall3000 View Post
how to create this package to be specific for the arm architecture. The architecture is called arm_v5t_le.
That's one thing I never tried, cross-compiling for another arch. However 'rpm rpm --showrc|egrep -wi "\%{.*(arch|os|cpu|platform)"' and {/etc/,~/.}rpmrc show enough pointers to tunables like _arch, _os, _target_platform to start your resarch with and I'm sure you'll find more in the RPM.org docs, "Maximum RPM" and the rpm mailing list archives.

Posting your solution would be appreciated.
 
Old 07-02-2008, 09:28 AM   #6
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Well, as I said the arm problem is solved. However, I need the RPM package to be relocatable. I am currently reading the docs for that but am not making much headway, if you could tell me how this is done it would be great.
 
Old 07-02-2008, 03:01 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
Quote:
Originally Posted by rahulthewall3000 View Post
Well, as I said the arm problem is solved.
Next time please don't edit in a solution like you did in post #4 but post it in a new post instead.


Quote:
Originally Posted by rahulthewall3000 View Post
However, I need the RPM package to be relocatable.
Prolly reading the wrong docs then. See Maximum RPM, chapter 15: Making a Relocatable Package.
 
Old 07-02-2008, 06:29 PM   #8
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by unSpawn View Post
Next time please don't edit in a solution like you did in post #4 but post it in a new post instead.
OK

Quote:
Originally Posted by unSpawn View Post
Prolly reading the wrong docs then. See Maximum RPM, chapter 15: Making a Relocatable Package.
Reading the same docs. However, if I make it relocatable the file is copied to / and not /etc. Do not know why this is happening.
 
Old 07-02-2008, 06:45 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
Quote:
Originally Posted by rahulthewall3000 View Post
if I make it relocatable the file is copied to / and not /etc.
That's the equivalent of saying "doesn't work" and from that I can't see what's wrong. It would be better to post your revised spec file and whatever commands you used to compile and install the package.
 
Old 07-03-2008, 02:50 AM   #10
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
The revise spec file:
Code:
%define debug_packages	%{nil}
%define debug_package %{nil}

%define name patches
%define version 1.0
%define release 1

Summary: Patch MontaVista filesystem configuration files.
Name: %{name}
Version: %{version}
Release: %{release}
Source: %{name}-%{version}-%{release}.tar.gz
Prefix: /etc
License: GPL
Group: System/Base
BuildRoot: %{_tmppath}/%{name}-%{version}

%description
This package changes the following configuration files: /etc/resolv.conf

%prep

%setup -q

%build

%install
mkdir -p $RPM_BUILD_ROOT/etc
install -m 644 /etc/resolv.conf $RPM_BUILD_ROOT/etc/resolv.conf

%clean
if [ "$RPM_BUILD_ROOT" = "%{_tmppath}/%{name}-%{version}" ]; then
	rm -rf $RPM_BUILD_ROOT
else
	echo Invalid Buildroot \'"$RPM_BUILD_ROOT"\'
	exit 1
fi

%files
%defattr(755, root, root)
%attr(644,root,root) %config /etc/resolv.conf

%changelog
* Wed Jul 02 2008 %package - 
- Freeform changelog, fixed format date line. Newest entries top.
As for the installation commands, that is a problem. I am using DevRocket -a tool provided by MontaVista to package the software on the Ramdisk. Therefore I have no idea as to what is the exact command it is using.
 
Old 07-03-2008, 03:27 AM   #11
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Two Changes and the problem is solved:

Prefix: /
install -m 644 etc/resolv.conf $RPM_BUILD_ROOT/etc/resolv.conf

Relieved and Thankful
Rahul
 
Old 07-03-2008, 04:20 AM   #12
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Again correction:

Prefix: .
 
Old 07-03-2008, 06:14 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
In a .spec file you use "Prefix" tags to mark directories for relocation, then on install you use for instance 'rpm --relocate /etc=/usr/local/etc package.rpm' to make stuff in /etc end up in /usr/local/etc. So using prefixes like you describe don't do *any* relocation as far as I know.
 
Old 07-03-2008, 06:27 AM   #14
rahulthewall3000
Member
 
Registered: Jan 2008
Location: Bremen
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Yes, I know that as well. The thing is that I am not interested in relocation per se, it is just that the tool that I am using requires the package to be relocatable. In this case, it is a quick and dirty fix, and nothing more.
 
  


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
RPM Spec file creation, %files section question davidas Linux - Software 1 09-13-2007 02:26 AM
.deb vs .rpm package creation uselpa Linux - Distributions 2 09-04-2007 12:45 AM
A little question about rpm package brazilian_user Linux - General 3 08-13-2006 03:38 PM
Creation of RPM package yashwantpinge Programming 1 03-06-2006 07:57 AM
RPM Package Question. rvijay Linux - Newbie 9 09-26-2003 09:05 PM


All times are GMT -5. The time now is 12:19 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