LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-13-2013, 07:52 AM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Rep: Reputation: 51
Need help building the RPM


Hi,

I have 2-3 RPMs (sam, alpha and beta)which I want to package into a single RPM. I extracted those RPMs as follow:


rpm2cpio sam-1.el6.x86_64.rpm | cpio -idmv

It showed me the related files installed at :

/opt/sam/toolkit directories.

While alpha and beta showed some to /usr and some to /opt/sam/toolkit directory.

Now I took all these packages and dumped it to one folder called sam-1.tar.gz


I created a directory structure as:

mkdir -p ~/rpms/{BUILD,RPMS,SOURCES,SPECS,SRPMS,tmp}

Now I modified ~/.rpmmacros as
Code:
 $cat .rpmmacros
%_topdir %(echo $HOME)/rpms
%_tmppath %(echo $HOME)/rpms/tmp
Then

cd ~/rpm/SOURCES
mkdir ~/rpm/SOURCES/sam-1
cp sam.tar.gz ~/rpm/SOURCES/sam-1
tar czvf sam-1.tar.gz sam-1/

I googled around for some spec file.Now while creating spec file, I need to understand few lines:



cd ~/rpm/SPECS
Code:
Summary: My first rpm script package
Name: sam
Version: 1
Release: 1
Source0: sam-1.tar.gz
License: GPL
Group: MyJunk
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-buildroot
%description
Make some relevant package description here
%prep
%setup -q
%build
%install
install -m 0755 -d $RPM_BUILD_ROOT/opt/sam                                     
install -m 0755 myscript.sh $RPM_BUILD_ROOT/opt/sam/myscript.sh
%clean
rm -rf $RPM_BUILD_ROOT
%post
echo " "
echo "This will display after rpm installs the package!"
%files
%dir /opt/sam
/opt/sam/myscript.sh
Question:

1. I believe that the sam-1.tar.gz has to be unzipped and send to respective /etc,/usr folders right?
Please correct me.
2. Do I just need to copy them or install them? Please clarify.

1. The %install section shows myscript.sh. Why we need it? Why are we using $RPM_BUILD_ROOT/opt/sam for?
2. What is the last %dir doing? Do I really need myscript.sh ? Will rpmbuild create that script?

Please suggest.

Last edited by your_shadow03; 05-14-2013 at 02:42 PM.
 
Old 05-13-2013, 04:13 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 28,184
Blog Entries: 54

Rep: Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143
Quote:
Originally Posted by your_shadow03 View Post
I have 2-3 RPMs (sam, alpha and beta)which I want to package into a single RPM.
Why? Packaging happens for a reason and RPM packaging more so. If you want to play with things fine, but else, if these packages are (part of) official packages and your intent is to distribute it I'd strongly advise against combining them.

*You also want to read something like http://docs.fedoraproject.org/en-US/...tml/RPM_Guide/ as it answers a lot of questions.


Quote:
Originally Posted by your_shadow03 View Post
I believe that the sam-1.tar.gz has to be unzipped and send to respective /etc,/usr folders right?
In the process of building the package the %{Source0} package will be extracted to the build root, think 'tar -C %{_tmppath}/%{name}-buildroot'.


Quote:
Originally Posted by your_shadow03 View Post
The %install section shows myscript.sh. Why we need it?
If you don't know what it does then you don't need it.


Quote:
Originally Posted by your_shadow03 View Post
Why are we using $RPM_BUILD_ROOT/opt/sam for?
Because you need a temporary directory to hold the package contents while it's getting built. The ${RPM_BUILD_ROOT} gets stripped so the package contains files with the leading "/opt/sam" directory names only.


Quote:
Originally Posted by your_shadow03 View Post
What is the last %dir doing?
%dir means it's not a %file.


Quote:
Originally Posted by your_shadow03 View Post
Will rpmbuild create that script?
If you tell it to. (Probably best as file in the %{_source} directory or else in the %post section as a "here document".)

Last edited by unSpawn; 05-14-2013 at 01:19 PM. Reason: //Typos
 
Old 05-14-2013, 06:18 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Original Poster
Rep: Reputation: 51
Here is my spec file. While I ran rpmbuild it tries to run ./configure which I dont want. All I need is when I run the RPM as root in other machine, it should put all the %files to correct location in the machine where I am going to install this RPM. I dont think I need to run ./configure. Am I correct? Please suggest
Code:
$cd /home/raj
$cd rpms/
$ls BUILD/ BUILDROOT/ SPECS/ SOURCES/ tmp/

$cd /home/raj/rpms/SOURCES
$ls sam-1.tar.gz

sam-1.tar.gz when extracted shows me few number of files under /etc

$tar -xvzf sam-1.tar.gz -C /tmp
$cd /tmp

/etc/ld.so.conf.d/leng.conf
/etc/ld.so.conf.d/leng-x86_64.conf
/etc/ld.so.conf.d/leng.conf
/etc/rc.d/init.d/negeng
/etc/rc.d/init.d/denpmi
/etc/rc.d/init.d/dencdrv
/usr...
/opt/...



Name:           sam-1
Version:        1.0.0
Release:        1%{?dist}
Summary:        Custom sam PKG

Group:          Development/Libraries
License:        GPL
URL:            NA
Source:        sam-1.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires:  gcc
Requires:       glibc

%description
                This is my test RPM

%prep
%setup -q


%build
%configure
make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%{_includedir}/etc/ld.so.conf.d/leng.conf
%{_includedir}//etc/ld.so.conf.d/leng-x86_64.conf
%{_includedir}//etc/ld.so.conf.d/leng.conf
%{_includedir}//etc/rc.d/init.d/negeng
%{_includedir}//etc/rc.d/init.d/denpmi
%{_includedir}//etc/rc.d/init.d/dencdrv

While I run it it threw me error saying:


 rpmbuild -bb new.spec
Executing(%prep): /bin/sh -e /home/raj/rpms/tmp/rpm-tmp.DXrMFt
+ umask 022
+ cd /home/raj/rpms/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/raj/rpms/BUILD
+ rm -rf sam-1
+ /usr/bin/gzip -dc /home/raj/rpms/SOURCES/sam-1.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd sam-1
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /home/raj/rpms/tmp/rpm-tmp.RdRvBN
+ umask 022
+ cd /home/raj/rpms/BUILD
+ cd raj-1.0.0
+ LANG=C
+ export LANG
+ unset DISPLAY
+ CFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protec                                                                                        tor --param=ssp-buffer-size=4 -m64 -mtune=generic'
+ export CFLAGS
+ CXXFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-prot                                                                                        ector --param=ssp-buffer-size=4 -m64 -mtune=generic'
+ export CXXFLAGS
+ FFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protec                                                                                        tor --param=ssp-buffer-size=4 -m64 -mtune=generic -I/usr/lib64/gfortran/modules'
+ export FFLAGS
+ ./configure --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu -                                                                                        -target=x86_64-redhat-linux-gnu --program-prefix= --prefix=/usr --exec-prefix=/u                                                                                        sr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share                                                                                         --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --locals                                                                                        tatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/sh                                                                                        are/info
/home/raj/rpms/tmp/rpm-tmp.RdRvBN: line 36: ./configure: No such file or direct                                                                                        ory
error: Bad exit status from /home/raj/rpms/tmp/rpm-tmp.RdRvBN (%build)


RPM build errors:
    Bad exit status from /home/raj/rpms/tmp/rpm-tmp.RdRvBN (%build)

Last edited by your_shadow03; 05-14-2013 at 02:41 PM.
 
Old 05-14-2013, 06:30 AM   #4
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Original Poster
Rep: Reputation: 51
I read that %install - This is where you tell the rpm to put the files that you want. The call to install other than the original %install is not a rpm specific command, it is a regular Linux command, similar to cp, or mv.


%files - This is one of the most important section, other than %install. This tells rpm what files have been installed and where they are.



Now if you take my case, do I really need %install or just %files will do?
If %install, what am I going to mention on this section?
 
Old 05-14-2013, 07:15 AM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2015, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 14,678

Rep: Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758
# 4 : %files will do, like this example ..
Code:
Summary:   None
Name:      
Version:   1.1.1
Release:   1
License:   GPL
Group:     None          
Packager:  Jerry Donut <jerry@donut.com>
BuildArchitectures: noarch
BuildRoot:

%description
No description

%files
/usr/local/bin/file
 
Old 05-14-2013, 07:30 AM   #6
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Original Poster
Rep: Reputation: 51
Knudfl,

I just put it your way as shown below:
Code:
Summary: Custom PKg
Name: custom Pkg
Version: 1.0.0
Release: 1
Source0:custompkg-1.0.0.tar.gz
License: GPL
Group: Test
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-buildroot
%description
Make some relevant package description here
%prep
%setup -q
%build
%install
%clean
%post
echo " "
echo "This will display after rpm installs the package!"
%files
etc/ld.so.conf.d/deng.conf
ld.so.conf.d/dengx86_64.conf
...
but the error I am getting is:
Code:
Executing(%prep): /bin/sh -e /home/raj/rpms/tmp/rpm-tmp.1S5OCY
+ umask 022
+ cd /home/raj/rpms/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/raj/rpms/BUILD
+ rm -rf sam-1
+ /usr/bin/gzip -dc /home/raj/rpms/SOURCES/sam-1.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd sam-1
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /home/raj/rpms/tmp/rpm-tmp.DfvE9B
+ umask 022
+ cd /home/raj/rpms/BUILD
+ cd sam-1
+ LANG=C
+ export LANG
+ unset DISPLAY
+ exit 0
Executing(%install): /bin/sh -e /home/raj/rpms/tmp/rpm-tmp.T59QJf
+ umask 022
+ cd /home/raj/rpms/BUILD
+ '[' /home/raj/rpms/BUILDROOT/sam-1-1.x86_64 '!=' / ']'
+ rm -rf /home/raj/rpms/BUILDROOT/sam-1-1.x86_64
++ dirname /home/raj/rpms/BUILDROOT/sam-1-1.x86_64
+ mkdir -p /home/raj/rpms/BUILDROOT
+ mkdir /home/raj/rpms/BUILDROOT/sam-1-1.x86_64
+ cd sam-1
+ LANG=C
+ export LANG
+ unset DISPLAY
+ /usr/lib/rpm/find-debuginfo.sh --strict-build-id /home/raj/rpms/BUILD/sam-1
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/brp-python-bytecompile
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: sam-1-1.noarch
error: File not found: /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/ld.so.conf.d/deng.conf
error: File not found: /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/ld.so.conf.d/dengx86_64.conf
error: File not found: /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/ld.so.conf.d/vc.conf
error: File not found: /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/rc.d/init.d/eng
error: File not found: /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/rc.d/init.d/pmi
Seems like its not untaring it with %setup -q.

Last edited by your_shadow03; 05-14-2013 at 02:40 PM.
 
Old 05-14-2013, 09:09 AM   #7
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2015, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 14,678

Rep: Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758
# 6 :

mkdir -p /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/rc.d/init.d/

... and then copy the files into those folders. ( etc/, init.d/ ).
 
Old 05-14-2013, 11:19 AM   #8
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Original Poster
Rep: Reputation: 51
Do you mean I need to manually go to that folder and create or I need to put this command under % install
 
Old 05-14-2013, 12:21 PM   #9
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2015, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 14,678

Rep: Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758Reputation: 2758
# 8 .

$ mkdir -p /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/rc.d/init.d/
... is a command to be typed in a terminal. Then you have the missing folders.
And can repeat $ rpmbuild -bb ......
 
Old 05-14-2013, 01:24 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 28,184
Blog Entries: 54

Rep: Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143
Quote:
Originally Posted by knudfl View Post
$ mkdir -p /home/raj/rpms/BUILDROOT/sam-1-1.x86_64/etc/rc.d/init.d/
... is a command to be typed in a terminal.
Hmm. You could actually use the %install stage to facilitate running that command. (You're supposed to have a
Code:
%clean
rm -rf ${RPM_BUILD_ROOT}
stage, right?)
 
1 members found this post helpful.
Old 05-14-2013, 01:29 PM   #11
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Original Poster
Rep: Reputation: 51
If I add them manually do I really need %files.
Because I am facing an issue while I add conf files to directory and while I run I again some files being deleted.
I removed %files section and added all the files manually.

Though it successfully went fine I am not sure if that went correct or not.
 
Old 05-14-2013, 01:52 PM   #12
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Original Poster
Rep: Reputation: 51
UnSpawn,

One thing I am unable to understand about is %install and %files.

Say, I have /home/raj/rpms/BUILDROOT/sam-1 directory mentioned under :
Code:
install -m 0755 -d $RPM_BUILD_ROOT/opt/mydirectory
install -m 0755 -d $RPM_BUILD_ROOT/etc/mydirectory
install -m 0755 -d $RPM_BUILD_ROOT/usr/mydirectory
%files
/opt/mydirectory/file1
/opt/mydirectory/file2

Do I need to mention like this?

I did tried. But once I ran, it deletes the files under /opt/mydirectory directory and hence File not found.

Please provide me with an example. I am really confused.

Last edited by your_shadow03; 05-14-2013 at 02:40 PM.
 
Old 05-14-2013, 02:22 PM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 28,184
Blog Entries: 54

Rep: Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143Reputation: 3143
Quote:
Originally Posted by your_shadow03 View Post
One thing I am unable to understand about is %install and %files.
If you would actually have read http://docs.fedoraproject.org/en-US/...tml/RPM_Guide/ then you would have encountered both the %install stage (http://docs.fedoraproject.org/en-US/...s02s03s04.html) and the %files section (http://docs.fedoraproject.org/en-US/...s02s03s06.html).


Quote:
Originally Posted by your_shadow03 View Post
Say, I have /home/raj/rpms/BUILDROOT/sam-1 directory mentioned under :

install -m 0755 -d $RPM_BUILD_ROOT/opt/mydirectory
install -m 0755 -d $RPM_BUILD_ROOT/etc/mydirectory
install -m 0755 -d $RPM_BUILD_ROOT/usr/mydirectory

%files
/opt/mydirectory/file1
/opt/mydirectory/file2

Do I need to mention like this?
Yes, or use
Code:
find $RPM_BUILD_ROOT -not -type d -printf "%%%attr(%%m,root,root) %%p\n" | sed -e "s|$RPM_BUILD_ROOT||g" > %{_tmppath}/%{name}_contents.txt
at the end of your %install stage and then replace the %files section with
Code:
%files -f %{_tmppath}/%{name}_contents.txt

Last edited by unSpawn; 05-14-2013 at 02:23 PM. Reason: //typo
 
Old 05-14-2013, 02:36 PM   #14
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,422
Blog Entries: 1

Rep: Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127
You gotta wrap those big posts into CODE tags! This thread is almost too big to read now.
 
Old 05-14-2013, 02:39 PM   #15
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,448
Blog Entries: 6

Original Poster
Rep: Reputation: 51
Unspawn,

You mentioned the link http://docs.fedoraproject.org/en-US/...s02s03s04.html which says:

%install
rm -fr $RPM_BUILD_ROOT
make install
The install section starts with an %install statement.

But here I am not doing make install but simply packaging the RPM.

See the #1 thread.
Code:
rpm2cpio sam-1.el6.x86_64.rpm | cpio -idmv

It showed me the related files installed at :

/opt/sam/toolkit directories.

While alpha and beta showed some to /usr and some to /opt/sam/toolkit directory.

Now I took all these packages and dumped it to one folder called sam-1.tar.gz
I dint understand those commands. Seems little complicated.

So what I understand is I do need both %install and %files.
%install will hold just directory while %files will be those files which gets created while I run rpmbuild right?

Last edited by your_shadow03; 05-14-2013 at 02:54 PM.
 
  


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
configure path for dependent rpm packages for building source rpm package embeddedlinuxforall Linux - Newbie 1 03-01-2013 12:39 PM
error in building rpm of open ldap from source using rpm package manager Infotechie Linux - Software 2 05-02-2012 02:10 AM
Building a RPM investmentbnker75 Linux - Newbie 3 03-22-2009 07:58 PM
Help building an .rpm from a .src.rpm ssenuta Linux - Software 6 04-10-2006 11:36 PM
Building RPM via src.Rpm ivanatora Linux - Newbie 2 02-20-2006 05:29 PM


All times are GMT -5. The time now is 03:56 PM.

Main Menu
Advertisement
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