LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to build a rpm (http://www.linuxquestions.org/questions/linux-software-2/how-to-build-a-rpm-4175440929/)

project.linux.proj 12-11-2012 03:13 AM

how to build a rpm
 
How can i create a Python rpm version 2.7. Can anybody give me the easy way to write the spec file ?

Thanks,

linosaurusroot 12-11-2012 04:33 AM

I believe the modern way (that I've not used) involves a tool called "mock".

project.linux.proj 12-13-2012 11:32 PM

Hi,

I tried to build pkg using rpmbuild. I wrote specification as below but getting error when i check on the path /usr/src/redhat/BUILD . i get directory name starting with capital letter Python-3.3.0. As checked in error it tries to cd python-3.3.0 (starts with small letter). If it is the problem how to fix it?

==================================================
Specification

[root@localhost SPECS]# cat python-3.3.0.spec
Summary: python package
%define version 3.3.0
Group: Development/Application
Name: python
Prefix: /usr
Provides: python
Release: 0
License: GNU
Source: python-%{version}.tar
URL: http://www.python.org/download/release
Version: %{version}
Buildroot: /tmp/python
%description
The python is an application http://www.python.org/download/release

%prep

%setup -q

%build
./configure CXXFLAGS=-O3 --prefix=$RPM_BUILD_ROOT/usr
make

%install
rm -fr $RPM_BUILD_ROOT
make install

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
/usr/bin/python
%doc /usr/doc/python-%{version}/license.htm
%doc /usr/man/man1/python.1*


===============================================

Ran below command to build the pkg

[root@localhost SPECS]# rpmbuild -ba python-3.3.0.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.38534
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /usr/src/redhat/BUILD
+ rm -rf python-3.3.0
+ tar -xf /usr/src/redhat/SOURCES/python-3.3.0.tar
+ cd python-3.3.0
/var/tmp/rpm-tmp.38534: line 33: cd: python-3.3.0: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.38534 (%prep)


RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.38534 (%prep)
[root@localhost SPECS]# less python-3.3.0.spec
(reverse-i-search)`b ': cat /etc/fstab
[root@localhost SPECS]# rpmbuild -ba python-3.3.0.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.24452
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /usr/src/redhat/BUILD
+ rm -rf python-3.3.0
+ tar -xf /usr/src/redhat/SOURCES/python-3.3.0.tar
+ cd python-3.3.0
/var/tmp/rpm-tmp.24452: line 33: cd: python-3.3.0: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.24452 (%prep)


RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.24452 (%prep)




=====================================================

Error logs

#!/bin/sh

RPM_SOURCE_DIR="/usr/src/redhat/SOURCES"
RPM_BUILD_DIR="/usr/src/redhat/BUILD"
RPM_OPT_FLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables"
RPM_ARCH="i386"
RPM_OS="linux"
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
RPM_DOC_DIR="/usr/share/doc"
export RPM_DOC_DIR
RPM_PACKAGE_NAME="python"
RPM_PACKAGE_VERSION="3.3.0"
RPM_PACKAGE_RELEASE="0"
export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
RPM_BUILD_ROOT="/tmp/python"
export RPM_BUILD_ROOT

PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/share/pkgconfig"
export PKG_CONFIG_PATH

set -x
umask 022
cd /usr/src/redhat/BUILD

LANG=C
export LANG
unset DISPLAY


cd '/usr/src/redhat/BUILD'
rm -rf 'python-3.3.0'
tar -xf /usr/src/redhat/SOURCES/python-3.3.0.tar
cd 'python-3.3.0'
[ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .
[ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .
/bin/chmod -Rf a+rX,u+w,g-w,o-w .


exit 0




Thanks,
Mohit

knudfl 12-14-2012 05:07 AM

First : No need to be root to build rpms. Not recommended.

Please try : $ rpm -Uvh python-2.7.3-6.fc17.src.rpm
http://dl.fedoraproject.org/pub/fedo...6.fc17.src.rpm
.. and the source code will be unpacked to /home/<name>/rpm*///

The spec file can be found in SPECS/.
Then you have the example "python.spec" for python-2.7.3 .


My preferred rpmbuild setup ...
http://www.linuxquestions.org/questi...1-a-766486/#13

.

project.linux.proj 01-07-2013 12:49 PM

I am trying new spec still getting an error ... Below is the spec and error . I don't know why the path ( /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64 ) is being added as a prefix . Can anybody help plz

================================

# cat ocsinventory.spec
%define debug_package %{nil}

Name: ocsinventory-agent
Version: 2.0
Release: 0
Summary: ocsinventory-agent 2.0rc2
Group: Monitor
License: GPL
URL: http://glam.com/ocsagnet
Source: Ocsinventory-Agent-2.0rc2.tar.gz

Requires: perl , perl-Module* , perl-XML-Simple , perl-ExtUtils* , perl-Proc-PID-File , perl-Proc-Daemon.noarch , perl-Net-SNMP , perl-Net-IP

%description
Ocsinventory-Agent for Opera Solutions

#%prep
#%setup -n ocsinventory-agent

#%build
#cd /usr/src/redhat/BUILD/Ocsinventory-Agent-2.0
#make

#%install

%files
/etc/cron.d/ocsinventory-agent
/usr/local/share/man/man1/ocsinventory-agent.1
/usr/local/bin/ocsinventory-agent
/usr/lib64/perl5/perllocal.pod
%dir /root/Ocsinventory-Agent-2.0rc2/*
%dir /usr/local/share/perl5/Ocsinventory/*
%dir /var/lib/ocsinventory-agent/
%dir /etc/ocsinventory-agent/
%config(noreplace) /etc/ocsinventory-agent/modules.conf
%config(noreplace) /etc/ocsinventory-agent/ocsinventory-agent.cfg
#SSLeay
#end

Errors

# rpmbuild -bb ocsinventory.spec
Processing files: ocsinventory-agent-2.0-0.x86_64
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/cron.d/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/local/share/man/man1/ocsinventory-agent.1
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/local/bin/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/lib64/perl5/perllocal.pod
error: File not found by glob: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/root/Ocsinventory-Agent-2.0rc2/*
error: File not found by glob: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/local/share/perl5/Ocsinventory/*
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/var/lib/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/ocsinventory-agent/modules.conf
error: File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/ocsinventory-agent/ocsinventory-agent.cfg


RPM build errors:
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/cron.d/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/local/share/man/man1/ocsinventory-agent.1
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/local/bin/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/lib64/perl5/perllocal.pod
File not found by glob: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/root/Ocsinventory-Agent-2.0rc2/*
File not found by glob: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/usr/local/share/perl5/Ocsinventory/*
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/var/lib/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/ocsinventory-agent/modules.conf
File not found: /root/rpmbuild/BUILDROOT/ocsinventory-agent-2.0-0.x86_64/etc/ocsinventory-agent/ocsinventory-agent.cfg


# ll ../SOURCES/
total 1428
-rw-r--r-- 1 root root 1460018 Jan 7 13:11 Ocsinventory-Agent-2.0rc2.tar.gz

# pwd
/usr/src/redhat/SPECS

knudfl 01-07-2013 03:09 PM

# 5 : 'ocsinventory-agent 2.0rc2' is an old version, I'd guess.
Currently used stable versions are 2.0.4, 2.0.5 or 1.1.2.1 .

Suggest : Use an existing 'ocsinventory-agent.spec' file.
Available in SRC.RPMS for Fedora, Mandriva.

Example, Fedora 17 : ocsinventory-agent-2.0.5-1.fc17.src.rpm
http://dl.fedoraproject.org/pub/fedo...1.fc17.src.rpm

Which OS are you using ? Name and version, please.

.

project.linux.proj 01-08-2013 01:45 AM

below is the information

# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final

knudfl 01-08-2013 04:19 AM

# 7

# yum install ocsinventory-agent
( Providing version 1.1.2.1 ).

The package ocsinventory-agent is in the EPEL.repo
https://fedoraproject.org/wiki/EPEL >
# rpm -Uvh http://ftp.crc.dk/fedora-epel/6/i386...6-7.noarch.rpm

The CentOS 6.x ocsinventory-agent source package with a .spec file :
http://dl.fedoraproject.org/pub/epel...ory-agent.html
> http://dl.fedoraproject.org/pub/epel...-1.el6.src.rpm

.

project.linux.proj 01-08-2013 11:48 AM

knudfl

Can we fix the existing spec ? Why below errors

# rpmbuild -ba /root/rpmbuild/SPECS/ocsinventory.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.Hn4Kac
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf Ocsinventory-Agent-2.0rc2
+ /usr/bin/gzip -dc /root/rpmbuild/SOURCES/Ocsinventory-Agent-2.0rc2.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd Ocsinventory-Agent-2.0rc2
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Processing files: ocs-agent-2.0-0.x86_64
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/cron.d/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/local/share/man/man1/ocsinventory-agent.1
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/local/bin/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/lib64/perl5/perllocal.pod
error: File not found by glob: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/root/Ocsinventory-Agent-2.0rc2/*
error: File not found by glob: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/local/share/perl5/Ocsinventory/*
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/var/lib/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/ocsinventory-agent/modules.conf
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/ocsinventory-agent/ocsinventory-agent.cfg


RPM build errors:
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/cron.d/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/local/share/man/man1/ocsinventory-agent.1
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/local/bin/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/lib64/perl5/perllocal.pod
File not found by glob: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/root/Ocsinventory-Agent-2.0rc2/*
File not found by glob: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/local/share/perl5/Ocsinventory/*
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/var/lib/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/ocsinventory-agent
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/ocsinventory-agent/modules.conf
File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/ocsinventory-agent/ocsinventory-agent.cfg

unSpawn 01-08-2013 12:13 PM

Quote:

Originally Posted by project.linux.proj (Post 4865516)
Can we fix the existing spec ?

knudfl already pointed out that building packages isn't necessary if they are readily available. He also pointed out that you shouldn't use stale versions of software but use the current, stable, safe version. (And I'm adding to that that you should not build RPM packages as root account user.) Not responding to what knudlf said and stubbornly going your own way serves as further evidence that what you need isn't fixing %buildroot --prefix package building errors: you need to make a U-turn.

project.linux.proj 01-09-2013 05:29 AM

Unspawn/knudfl,

I am running this with root user because I am just copying configurations files/directories into the rpm as it is. Please correct me if i am doing mistake.I ran the below spec file on arch i386 and it ran successfully but when i ran on arch x86_64 it prefixes path "/root/rpmbuild/BUILDROOT" and gives error. It might be i need to change the buildroot value but i am not sure. Can you guys help me to diagnose it because i don't want U-Turn .

Spec on i386

%define debug_package %{nil}

Name: ocsinventory-agent
Version: 2.0
Release: 0
Summary: Ocsinventory-Agent-2.0rc2
Group: Monitor
License: GPL
URL: http://glam.com/ocsagnet
Source: Ocsinventory-Agent-2.0rc2.tar.gz

#Requires: perl-XML-Simple , perl-Compress-Zlib , perl-Net-IP , perl-Net-SSLeay , perl-Crypt-SSLeay , perl-Proc-Daemon , perl-Net-SNMP , perl-Proc-PID-File , pciutils , smartmontools
Requires: perl perl-Module* perl-XML-Simple perl-ExtUtils* perl-Proc-PID-File perl-Proc-Daemon.noarch perl-Net-SNMP perl-Net-IP

%description
Ocsinventory-Agent for Glam Techops team

#%prep
#%setup -n ocsinventory-agent

#%build
#cd /usr/src/redhat/BUILD/Ocsinventory-Agent-2.0
#make

#%install

%files
/usr/lib/perl5/site_perl/5.8.8/Ocsinventory/*
/usr/share/man/man1/ocsinventory-agent.1
/usr/share/man/man3/Ocsinventory::Agent::Common.3pm
/usr/share/man/man3/Ocsinventory::Agent::XML::Inventory.3pm
/usr/bin/ocsinventory-agent
/usr/bin/ipdiscover
%dir /var/lib/ocsinventory-agent/
%dir /etc/ocsinventory-agent/
%config(noreplace) /etc/ocsinventory-agent/modules.conf
%config(noreplace) /etc/ocsinventory-agent/ocsinventory-agent.cfg

#end


Error on x86_64
Processing files: ocs-agent-2.0-0.x86_64
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/etc/cron.d/ocsinventory-agent
error: File not found: /root/rpmbuild/BUILDROOT/ocs-agent-2.0-0.x86_64/usr/local/share/man/man1/ocsinventory-agent.1


Thanks,

unSpawn 01-09-2013 06:18 AM

Quote:

Originally Posted by project.linux.proj (Post 4866005)
I am running this with root user because I am just copying configurations files/directories into the rpm as it is.

Not a valid reason as you can 'sudo cp' configurations files/directories over. Plus any local customization shouldn't be part of stock packages as they're local to begin with.


Quote:

Originally Posted by project.linux.proj (Post 4866005)
i don't want U-Turn

Like I said before you should not build RPM packages as root account user. Continuing to do so for no valid reason isn't an incentive for me to help you. So I'll leave you telling you to add this line
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
to the end of your %install section and replace your %files section with this line
Code:

%files -f %{_tmppath}/%{name}_contents.txt


All times are GMT -5. The time now is 04:06 PM.