Last Updated: February 25, 2016
·
1.362K
· quanghiem

Deb package surgery

I maintain a lot of the packages at Path. Usually I like to build from scratch using the awesome tool FPM written by Jordan Sissel. Sometimes I like to do surgery on existing deb packages from Ubuntu. This is how I frankenstein upgrade the outdated Ubuntu/Debian supervisor package from version 3.0a8-1.1 to the latest 3.0b1.

  1. Prep your workspace. Setup a fresh vagrant Ubuntu 12.04 server. Make sure you have FPM and python-setuptools installed.

    vagrant init precise64
    vagrant up
    vagrant ssh
    sudo aptitude install -y build-essential python-setuptools
    sudo gem install fpm
  2. Download the older supervisor-3.0a package from your apt repo explode it.

    mkdir -pv src/supervisor-3.0a/
    cd src/supervisor-3.0a/
    aptitude download supervisor
    ar xv supervisor_3.0a8-1.1_all.deb    
  3. Build the newer supervisor-3.0b package using fpm and explode that.

    cd ..
    mkdir -pv supervisor-3.0b/
    cd supervisor-3.0b/
    fpm -s python -t deb supervisor
    ar xv python-supervisor_3.0b1_all.deb
    tar xvfz data.tar.gz
    tar xvfz control.tar.gz
  4. Time to stitch both these packages back together. We will be using the original Ubuntu package base with init, post, and pre scripts with binaries from the newer package.

    cd ../..
    mkdir -pv path-supervisor_3.0b_all/DEBIAN
    cd path-supervisor_3.0b_all/
    tar xvfz ../src/supervisor-3.0a/data.tar.gz
    tar xvfz ../src/supervisor-3.0a/control.tar.gz -C DEBIAN/    
  5. Now that we have an untarred original base, let's replace the binaries with the newer 3.0b version.

    rm -rv usr/
    mv -v ../src/supervisor-3.0b/usr .
  6. Update the md5 and control files.

    find usr/ -type f -exec md5sum {} \; > DEBIAN/md5sums
    vi DEBIAN/control
  7. Time to build the deb package.

    cd ../
    dpkg-deb --build path-supervisor_3.0b_all/
    dpkg --info path-supervisor_3.0b_all.deb
    
    Package: path-supervisor
    Version: 3.0b1
    Architecture: all
    Maintainer: Richard Nghiem <richard@path.com>
    Installed-Size: 2382
    Depends: python-setuptools, python-meld3 (>= 0.6.5)
    Section: admin
    Priority: extra
    Homepage: http://supervisord.org/
    Description: A system for controlling process state
    Supervisor is a system for controlling and maintaining process state,
     similar to what init does, but not intended as an init replacement.
     .
     It will manage individual processess or groups of processes that
     need to be started and stopped in order, and it is possible to
     control individual process state via an rpc mechanism, thus allowing
     ordinary users to restart processes.