LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   RPM Package creation question (https://www.linuxquestions.org/questions/programming-9/rpm-package-creation-question-653051/)

rahulthewall3000 07-02-2008 07:05 AM

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.

w3bd3vil 07-02-2008 07:52 AM

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?

unSpawn 07-02-2008 08:13 AM

...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.


rahulthewall3000 07-02-2008 08:34 AM

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.

unSpawn 07-02-2008 09:16 AM

Quote:

Originally Posted by rahulthewall3000 (Post 3201466)
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 (Post 3201466)
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.

rahulthewall3000 07-02-2008 09:28 AM

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.

unSpawn 07-02-2008 03:01 PM

Quote:

Originally Posted by rahulthewall3000 (Post 3201543)
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 (Post 3201543)
However, I need the RPM package to be relocatable.

Prolly reading the wrong docs then. See Maximum RPM, chapter 15: Making a Relocatable Package.

rahulthewall3000 07-02-2008 06:29 PM

Quote:

Originally Posted by unSpawn (Post 3201947)
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 (Post 3201947)
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.

unSpawn 07-02-2008 06:45 PM

Quote:

Originally Posted by rahulthewall3000 (Post 3202176)
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.

rahulthewall3000 07-03-2008 02:50 AM

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. :(

rahulthewall3000 07-03-2008 03:27 AM

Two Changes and the problem is solved:

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

Relieved and Thankful
Rahul

rahulthewall3000 07-03-2008 04:20 AM

Again correction:

Prefix: .

unSpawn 07-03-2008 06:14 AM

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.

rahulthewall3000 07-03-2008 06:27 AM

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. :)


All times are GMT -5. The time now is 07:52 AM.