RPM change package epoch

 

Some RPM packages intentionally set the 'epoch' field in their SPEC file to work around issues in version detection or to give it special hints.

 

You can see how many of your installed packages actually use the epoch field like this:

 

root@rudderc1 ~ # rpm -qa --qf '%{E}\n' | sort | uniq -c | sort -nr 
    406 (none)
      1 2000

That'd mean there is only one package that has the epoch set at the moment, the other 406 have set it to None/Null/0.

Which one has the epoch "2000" - this is easiest to find like this:

root@rudderc1 ~ # rpm -qa --qf '%{E}:%{N}\n' | grep -v none
2000:jdk1.8.0_25

 

So this means someone thinks Java was created 2000 seconds after our calendar starts. Interesting.

 

My actual issue was slightly different - all agent packages of Rudder had the same epoch, causing a little problem where you could not update the agent.

The solution was to use "rpmrebuild" to modify the package. I generated a replacement package from the existing one.

First: Get rpmrebuild!

It can be found at sourceforge, I'm also attaching it here: rpmrebuild 2.11 noarch

Once downloaded, we create a working directory where re-packaged RPMs get stored

 

# wget ...rpmrebuild-2.11-1.noarch.rpm...
# rpm -i rpmrebuild-2.11-1.noarch.rpm
# mkdir outputs

The package is properly signed and the great moment here was finding the noarch RPM which worked flawless on my SLES system.

 

And this is how I used it to make a new package:

First we view the current epoch of the input package

root@rudderc1 ~ # rpm -pq --qf '%{E}:%{N}\n'  rudder-agent-3.0.4.release-1.SLES.11.x86_64.rpm 
1398866025:rudder-agent

 

 

one with the epoch reset, and then one more that has it to just a "newer" date than the original one:

# rpmrebuild -p --notest-install --change-spec-preamble='sed -e "s/^Epoch:.*/Epoch: 0/"' \
    --directory=output rudder-agent-3.0.4.release-1.SLES.11.x86_64.rpm && 
    mv output/x86_64/rudder-agent-3.0.4.release-1.SLES.11.x86_64.rpm  \
       output/x86_64/rudder-agent-3.0.4.release-1-ep0.SLES.11.x86_64.rpm
# rpmrebuild -p --notest-install --change-spec-preamble='sed -e "s/^Epoch:.*/Epoch: 1450745137/"'  \
    --directory=output rudder-agent-3.0.4.release-1.SLES.11.x86_64.rpm && 
    mv output/x86_64/rudder-agent-3.0.4.release-1.SLES.11.x86_64.rpm  \
       output/x86_64/rudder-agent-3.0.4.release-1-epnow.SLES.11.x86_64.rpm

 

here you can see the two changed files and the original:

root@rudderc1 ~ # find . -name "rudder-agent-3.0.4*" -print -exec rpm -pq --qf '%{E}:%{N}\n' {} +
./rudder-agent-3.0.4.release-1.SLES.11.x86_64.rpm
./output/x86_64/rudder-agent-3.0.4.release-1-epnow.SLES.11.x86_64.rpm
./output/x86_64/rudder-agent-3.0.4.release-1-ep0.SLES.11.x86_64.rpm
1398866025:rudder-agent
1450745137:rudder-agent
0:rudder-agent

Now if you want to modify something else, the official rpmrebuild documentation can be found here:

rpmrebuild(1)

 

What a wonderful little piece of software!