OpenPKG Advent Calendar 2006

...every day a little pondering, backstage information, jokes, tips and tricks.
19
Tuesday 2006-12-19: Tips & Tricks
Tweaking Package Specifications

True hacking requires a piece of wood and an axe.

Some people want to tweak packaged applications beyond the finite options already avaiable or they even want to create their very own package. Ignoring the complexities of maintaining individual adjustments over time, here is a very simple way of hacking the package specification:

All examples assume you switch the identity to the management user of the instance. Trick: in case you just know the prefix use the following command to switch to the management user:

      # su - `prefix/bin/openpkg rpm --eval '%{l_musr}'`

Discover the problem

      # download and unpack source package and build binary package
      $ openpkg rpm --rebuild \
        ftp://ftp.openpkg.org/stable/2.20061018/SRC/CORE/make-3.81-2.20061018.src.rpm
      ...
      Wrote: prefix/RPM/PKG/make-3.81-2.20061018.arch-os-tag.rpm
      ...

Oops! Binary package already rolled. Package specification tweaking must happen between unpacking the source archive and before building the binary, so break the rebuild action into smaller pieces.

My 1st derivative package pair

      # download and unpack source package by installing it
      $ openpkg rpm -Uvh \
        ftp://ftp.openpkg.org/stable/2.20061018/SRC/CORE/make-3.81-2.20061018.src.rpm
    
      # find the package ingredients
      $ cd ~/RPM/SRC/make
      $ ls -l
      total 1538
      -rw-r--r— 1 openpkg openpkg 1564560 2006-04-01 19:09 make-3.81.tar.gz
      -rw-r--r— 1 openpkg openpkg     896 2006-04-01 20:25 make.patch
      -rw-r--r— 1 openpkg openpkg    3408 2006-10-16 16:31 make.spec
    
      # edit the package specification file (practice calls for an editor here)
      $ ~/lib/openpkg/shtool subst -i -e 's;^\(Release: .*\);\1.my.1st;' make.spec
    
      # build my packages (add --nodeps to workaround dependency issues)
      $ openpkg rpm -ba make.spec
      ...
      Wrote: prefix/RPM/PKG/make-3.81-2.20061018.my.1st.src.rpm
      Wrote: prefix/RPM/PKG/make-3.81-2.20061018.my.1st.arch-os-tag.rpm
      ... 

Woohoo. Your first source and binary package pair. Time to copy your work to a safe place. Keep in mind, the next time someone installs the source package, even indirectly via --rebuild and even more indirectly via "openpkg build" — your changes will be discarded. No questions asked. You have been warned.

      # install binary package
      $ openpkg rpm -Uvh \
        openpkg rpm -q --qf `openpkg rpm --eval '%{l_binrpmfilename}'` \
                    --specfile make.spec
    
      # build my source package to save my package specification along the required ingredients
      $ openpkg rpm -bs make.spec

More info and even smaller pieces

Well, the -ba builds all — source and binary can be broken down into -bs (build source) and -bb (build binary). Where in turn -bb is just the last in a sequence of -bp (prepare), -bc (build/compile), -bi (install), -bl (file list) and -bb. Those sequences reflect sections in the package specification, blocks of code identified by a leading % sign. Just try

      $ grep ^% make.spec
      %description
      %track
      %prep
      %buildcompile
      %install
      %files -f fileslist
      %clean

Running those sections independenty usually restarts the whole build from scratch and works all the way through the item specified. To continue where the previous step stopped, add a --short-circuit.

      $ openpkg rpm -bs make.spec
      $ openpkg rpm -bp make.spec
      $ openpkg rpm -bc make.spec --short-circuit
      $ openpkg rpm -bi make.spec --short-circuit
      $ openpkg rpm -bl make.spec --short-circuit
      $ openpkg rpm -bb make.spec --short-circuit
      $ openpkg rpm --clean make.spec