Centos – Building official SRPMs in CentOS. All the steps

centosredhatrpm

I am new to Centos and yum in general.

  1. How do I retreive the SRPM using yumdownloader --source? When I run the command it says the SRPMs are not found. How do I add the repository? I am talking about official CentOS packages here.
  2. Once downloaded, what is the command to unpack the SRPM so I can edit the files?
  3. Last, once I am done modifying, what is the command to rebuild the modified source RPM?
  4. From a SRPM, how does one create a RPM?

Best Answer

  • How do I retreive the SRPM using yumdownloader --source? When I run the command it says the SRPMs are not found. How do I add the repository? I am talking about official CentOS packages here.

This is an issue with CentOS: http://bugs.centos.org/view.php?id=1646

Assuming you're CentOS 5, create this file in /etc/yum.repos.d/CentOS-SRPMS.repo

[base-SRPMS]
name=CentOS-$releasever - Base SRPMS
baseurl=http://mirror.centos.org/centos/$releasever/os/SRPMS/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
enabled=1

#released updates
[update-SRPMS]
name=CentOS-$releasever - Updates SRPMS
baseurl=http://mirror.centos.org/centos/$releasever/updates/SRPMS/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
enabled=1

#packages used/produced in the build but not released
[addons-SRPMS]
name=CentOS-$releasever - Addons SRPMS
baseurl=http://mirror.centos.org/centos/$releasever/addons/SRPMS/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
enabled=1

#additional packages that may be useful
[extras-SRPMS]
name=CentOS-$releasever - Extras SRPMS
baseurl=http://mirror.centos.org/centos/$releasever/extras/SRPMS/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
enabled=1

#additional packages that extend functionality of existing packages
[centosplus-SRPMS]
name=CentOS-$releasever - Plus SRPMS
baseurl=http://mirror.centos.org/centos/$releasever/centosplus/SRPMS/
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1

#contrib - packages by Centos Users
[contrib-SRPMS]
name=CentOS-$releasever - Contrib SRPMS
baseurl=http://mirror.centos.org/centos/$releasever/contrib/SRPMS/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
  • Once downloaded, what is the command to unpack the SRPM so I can edit the files?

rpm -ivh your.src.rpm

This assumes you have necessary directories, if you don't run mkdir -p /usr/src/redhat/{BUILD,RPMS,SOURCES,SPECS,SRPMS} to create them.

The file you'll usually want to edit is the spec file in /usr/src/redhat/SPECS/packagename.spec.

  • Last, once I am done modifying, what is the command to rebuild the modified source RPM?

rpmbuild -bb /usr/src/redhat/SPECS/your.spec to just build the RPM

rpmbuild -ba /usr/src/redhat/SPECS/your.spec to just build the RPM and an SRPM

  • From a SRPM, how does one create a RPM?

rpmbuild --rebuild your.src.rpm

If you need to build RPMs you should look in to using mock.