Howto Patch Source Rpm's

Arno Wilhelm

2003-01-20

Abstract:

This document describes howto unpack source rpm's, generate a patch (=diff file) from the changed sources and create a new souce rpm from the changed sources.


Contents

1 Unpacking the source rpm

Usually all rpm related software is kept under one directory which is usally /usr/src/redhat.

> l 

drwxr-xr-x 8 root root 4096 Jan 17 11:20 BUILD 

drwxr-xr-x 8 root root 4096 Mar 28 11:20 RPMS 

drwxr-xr-x 2 root root 4096 Jan 17 11:38 SOURCES 

drwxr-xr-x 2 root root 4096 Jan 17 10:29 SPECS 

drwxr-xr-x 2 root root 4096 Jan 20 11:09 SRPMS 

BUILD
in this directory the sources will be compiled. So they are going to be copied here from the SOURCES directory before beeing compiled.
RPMS
here the binary rpm's are located.
SOURCES
here the original sources are stored.
SPECS
all the spec files go here. Spec file are files that tell the rpm programm how to generate rpm files from the sources.
SRPMS
here the source rpm's are kept.
So copy the source rpm you wish to patch to the SRPMS directory and unpack the single files in the source rpm to directory it belongs to. ( Sources and patches go to the SOURCES directory, the spec file goes to the SPECS directory ):

> cp dhcpcd-1.3.22pl1-6.src.rpm /usr/src/redhat/SRPMS

> cd /usr/src/redhat/SRPMS

> rpm -Uvh dhcpcd-1.3.22pl1-6.src.rpm 

   1:dhcpcd           ########################################### [100%] 

> l ../SPECS/ 

-rw-r-r- 1 root root 7014 Jan 10 14:23 dhcpcd.spec 

> l ../SOURCES/ 

-rw-r-r- 1 root root 711    Feb 5 2002  dhcpcd-1.3.21-noMoFakery.patch

-rw-r-r- 1 root root 905    Feb 11 2002 dhcpcd-1.3.21-noNISfakery.patch -rw-r-r- 1 root root 802    Dec 30 2001 dhcpcd-1.3.21-post.patch

-rw-r-r- 1 root root 134557 Mar 22 2002 dhcpcd-1.3.22-pl1.tar.gz

-rw-r-r- 1 root root 46345  Jul 5 2002  dhcpcd-nonius.patch

-rwxr-xr-x 1 root root 376    Jan 7 10:49 syslog.dhcpcd

> rpm -bp dhcpcd.spec 

Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.42654 

+ umask 022 

+ cd /usr/src/redhat/BUILD 

+ cd /usr/src/redhat/BUILD 

+ rm -rf dhcpcd-1.3.22-pl1 

+ /bin/gzip -dc /usr/src/redhat/SOURCES/dhcpcd-1.3.22-pl1.tar.gz 

+ tar -xf - 

+ STATUS=0 + '[' 0 -ne 0 ']' 

+ cd dhcpcd-1.3.22-pl1 

++ /usr/bin/id -u + '[' 0 = 0 ']' 

+ /bin/chown -Rhf root . 

++ /usr/bin/id -u 

+ '[' 0 = 0 ']' 

+ /bin/chgrp -Rhf root . 

+ /bin/chmod -Rf a+rX,g-w,o-w . 

+ echo 'Patch #4 (dhcpcd-nonius.patch):' 

Patch #4 (dhcpcd-nonius.patch): 

+ patch -p1 -s 

+ exit 0

rpm -Uvh
-Uvh means update verbose hash: source rpm is beeing unpacked and the sources go to the SOURCES directory, the spec file goes to the SPECS directory.
rpm -bp
-bp means build prepare. Sources and patches from the SOURCE directory are copied into the BUILD directory. The patches are applied to the sources then in the BUILD directory.

2 Generating the patch

After you have unpacked the sources and patched them, you should make a copy of the prepared sources:

> cd ../BUILD 

> l 

drwxr-xr-x 4 root root 4096 Jan 20 11:45 dhcpcd-1.3.22-pl1 

> cp -avf dhcpcd-1.3.22-pl1/ dhcpcd-1.3.22-pl2

Then you change to the new source directory and make your changes there. Always test your changes and clean up the directory before you make the patch file. Then change back to the BUILD directory and create the patch (= diff ) file like this:

> diff -Naur dhcpcd-1.3.22-pl1/ dhcpcd-1.3.22-pl2 > dhcpcd-1.3.22-pl2.patch

> l 

drwxr-xr-x 5 root root 4096  Jan 20 16:40 dhcpcd-1.3.22-pl1 

drwxr-xr-x 4 root root 4096  Jan 20 11:45 dhcpcd-1.3.22-pl2

-rw-r-r- 1 root root 77201 Jan 20 16:42 dhcpcd-1.3.22-pl2.patch

With the command: ``diff -Naur OLD-DIRCTORY NEW-DIRECTORY > PATCH_FILE'' you created a file that keeps all the differences between the old directory and the new one. That means that when you apply the patch-file against OLD-DIRCTORY you will get NEW-DIRECTORY. We will do this here in order to test wether the patch is ok:

> cd dhcpcd-1.3.22-pl1/ 

> patch -p1 < ../dhcpcd-1.3.22-pl2.patch 

patching file `arp.c' 

patching file `client.c' 

patching file `dhcpcd' 

patching file `dhcpcd.c' 

patching file `dhcpcd.exe' 

patching file `dhcpcd.spec' 

patching file `doc/log-messages.txt' 

patching file `signals.c' 

patching file `version'

> cd .. 

> diff -r dhcpcd-1.3.22-pl1 dhcpcd-1.3.22-pl2

>

First you change to the directory with the old sources and apply the patch in there. Then you change back to the parent directory and use the diff command in order to compare the to directories. Here you see that the patch has worked and there are no differences between the old and the new directory anymore.

3 Creating a new source rpm

Now we have to copy the patch file to the SOURCES directory and adjust the spec file, so that it applies our new patch to the old sources.

> mv dhcpcd-1.3.22-pl2.patch ../SOURCES/

> rm -rf dhcpcd-1.3.22-pl*

> cd ../SPECS/

3.1 Adding the changes to the spec file

  1. Increase the release number:
    Release: 7
  2. Then apend your patch to the file:
    Patch5: dhcpcd-1.3.22-pl2.patch
  3. Append the patch to the %prep section. This makes sure that the patch is applied to the old sources:
    %prep
    %setup -q -n dhcpcd-%{mainver}-%{patchlevel}
    %patch4 -p1
    %patch5 -p1
  4. Add the new release to the %changelog section:
    %changelog
    * Mo Jan 20 2003 yeda nasda <a.nasda@nonius.com>
    - 1.3.22pl1-7
    - Added identification numbers to log messages.
    - Added description of log id numbers in doc directory.

3.2 Creating the binary and source rpm

After you have edited the spec file you must rebuild the rpm packages from the sources:

> rpm -ba dhcpcd.spec

.....

Wrote: /usr/src/redhat/SRPMS/dhcpcd-1.3.22pl1-7.src.rpm  
Wrote: /usr/src/redhat/RPMS/i386/dhcpcd-1.3.22pl1-7.i386.rpm

.....

Now you there must be the new source rpm in the SRPMS directory and the binary RPM in the RPMS directory.

4 The spec file

%define mainver 1.3.22

%define patchlevel pl1

 

Summary: A DHCP (Dynamic Host Configuration Protocol) client.

Name: dhcpcd

Version: %{mainver}%{patchlevel}

Release: 7

License: GPL

Group: System Environment/Base

Source: http://www.phystech.com/ftp/dhcpcd-%{mainver}-%{patchlevel}.tar.gz

Source1: syslog.dhcpcd

Patch: dhcpcd-1.3.21-post.patch

#Patch1: dhcpcd-1.3.21-multicast.patch

Patch2: dhcpcd-1.3.21-noNISfakery.patch

Patch3: dhcpcd-1.3.21-noMoFakery.patch

Patch4: dhcpcd-nonius.patch

Patch5: dhcpcd-1.3.22-pl2.patch

URL: http://www.phystech.com/download/

BuildRoot: /var/tmp/dhcpd_client-root

Prereq: file, fileutils, grep

Requires: noniusetc_box >= 2.2-15

 

%description

DHCP (Dynamic Host Configuration Protocol) is a protocol which allows

individual devices on an IP network to get their own network

configuration information (IP address, subnetmask, broadcast address,

etc.) from a DHCP server.  The overall purpose of DHCP is to make it

easier to administer a large network.  The dhcpcd package includes a

DHCP client daemon.

 

If you're going to use DHCP on your network, you'll need to install

the server package (dhcp) on the server, and a client package on the

client machines. The dhcpcd package includes a DHCP client, but we

suggest that you instead install the DHCP client included in the pump

package, which provides a faster and simpler DHCP client.

 

%prep

%setup -q -n dhcpcd-%{mainver}-%{patchlevel}

#%patch -p1

#%patch1 -p1

#%patch2 -p1

#%patch3 -p1

%patch4 -p1

%patch5 -p1

 

%build

%configure -sbindir=/sbin

make CFLAGS="$RPM_OPT_FLAGS" %{?_smp_mflags}

 

%install

rm -rf $RPM_BUILD_ROOT

%makeinstall sbindir=$RPM_BUILD_ROOT/sbin

 

rm -rf $RPM_BUILD_ROOT/etc/dhcpc*

 

mkdir -p $RPM_BUILD_ROOT/etc/dhcpc

 

ln -s dhcpc $RPM_BUILD_ROOT/etc/dhcpcd

 

mkdir -p $RPM_BUILD_ROOT/etc/syslog.d

install %{SOURCE1} $RPM_BUILD_ROOT/etc/syslog.d/dhcpcd

%clean

rm -rf $RPM_BUILD_ROOT

 

%post

if [ ! -d /var/nonius/sys ]; then

    mkdir -p /var/nonius/sys/

fi

for a in Notice Warning Error Info Fatal Security Panic; do

    if [ ! -p /var/nonius/sys/Network_dhcpcd_$a ]; then

        mknod /var/nonius/sys/Network_dhcpcd_$a p

    fi

done   

 

%files

%defattr(-,root,root)

%doc README dhcpcd-eth0.exe

/etc/dhcpcd

/etc/syslog.d/dhcpcd

%dir /etc/dhcpc

/sbin/dhcpcd

%{_mandir}/man8/dhcpcd.8*

 

%pre

exec > /dev/null 2> /dev/null

# We can't replace a directory with a symlink, but this directory is supposed

# to be a symlink.

if [ -d /etc/dhcpcd ] ; then

        mv /etc/dhcpcd/* /etc/dhcpc

        mv /etc/dhcpcd /etc/dhcpcd.rpmsave

fi

# Remove the circular link which was in a previous version of this package.

if [ -L /etc/dhcpc/dhcpc ] ; then

        if file /etc/dhcpc/dhcpc | grep -q "symbolic link to dhcpc" ; then

                rm /etc/dhcpc/dhcpc

                # Leave a file for RPM to remove.

                touch /etc/dhcpc/dhcpc

        fi

fi

if [ -L /etc/dhcpc/dhcpcd ] && [ ! -f /etc/dhcpc/dhcpcd ]; then

        rm -f /etc/dhcpc/dhcpcd

fi

 

%changelog

* Mon Jan 20 2003 yeda nasda <a.nasda@nonius.com>

- 1.3.22pl1-7

- Added identification numbers to log messages.

- Added description of log id numbers in doc directory.

 

 

* Mon Feb 11 2002 Elliot Lee <sopwith@redhat.com> 1.3.21pl2-5

- (noNISfakery.patch) update this patch to setdomainname()

 

* Tue Feb 05 2002 Elliot Lee <sopwith@redhat.com> 1.3.21pl2-4

- (noMoFakery.patch) Don't write RESOLV_CONF or NTP_CONF either, unless we have some values from the DHCP

  server.

 

* Thu Jan 31 2002 Elliot Lee <sopwith@redhat.com> 1.3.21pl2-3

- (noNISfakery.patch) Don't write NIS_CONF out unless the server

  actually sent a value back to us.

 

* Wed Jan 09 2002 Tim Powers <timp@redhat.com>

- automated rebuild

 

* Fri Jan 04 2002 Elliot Lee <sopwith@redhat.com> 1.3.21pl2-1

- Update to pl2

- Fix #54600

 

 

* Tue Jul 08 1997 Erik Troan <ewt@redhat.com>

- built against glibc, updated to 0.65

 

* Mon Apr 21 1997 Otto Hammersmith <otto@redhat.com>

- fixed summary line... was a summary for tar.

About this document ...

Howto Patch Source Rpm's

This document was generated using the LaTeX2HTML translator Version 2002 (1.62)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -no_subdir -split 0 -show_section_numbers /tmp/lyx_tmpdir20661mKAAux/lyx_tmpbuf20661KDrWvz/SourceRpmPatch-Howto.tex