Friday, May 29, 2009

Creating deb packages manually/Using alien to convert RPMs

Problem:

Although you can create debian packages using an automated installer at compile time using checkinstall at compile time. In this example, we will be using precompiled binary files that need to be ported from RPM packages to deb packages to port a program to a debian based system

Background:

I work for a Managed Service Provider, and we use a product called N-Able to do monitoring for our clients. We monitor servers on all platforms (Windows, Linux and Mac) and accordingly have to be able to install software for this on each operating system. The only issue was, for Linux, there was no Debian agent, (only red hat) so I decided to port it to Debian systems.

Solution:

In order to do this, you will need to have 2 tools installed: 1) alien and 2) ar. I used an Ubuntu 9.04 system for this process, though it should work on any system

Step 1: Convert the RPM to deb

to do this, simply type "alien packagename" You should now have a deb file with the same name as the origional (save for the extension)

Step 2: Extract the data from the deb archive

In this example, most of the files were converted and no additional work was necessary, however 1 of the packages required additional modifications, as the startup scripts it used were written for the red hat style startup/shutdown system using chkconfig, etc. This is very incompatible with Debian based systems. To correct this, I had to extract the deb package, so that I could modify these packages.


Start by creating a directory for each file and copying the deb into the folder:

mkdir nagent
cp nagent-rhel5.1_6.7.0.2169-3_i386.deb ./nagent


Then move into the directory and extract the data from the deb package:

cd nagent
ar x nagent-rhel5.1_6.7.0.2169-3_i386.deb


You should now have 3 additional files: control.tar.gz data.tar.gz and debian-binary
debian-binary can be ignored, as it only has a version # used by ar. This leaves us with data.tar.gz and control.tar.gz. data.tar.gz is all of the binary and configuration files needed by the program. If you extract this file, using tar, you will note that it mirrors the file structure of your base system. This is because dpkg just extracts this file with a working directory of root. In other words, if you have a file in ~/nagent/var, when you run dpkg nagent-rhel5.1_6.7.0.2169-3_i386.deb, after it has been repackaged, whatever files in ~/nagent/var will be extracted to /var on your system. I would reccomend creating a directory in your working directory, called data and extracting the data.tar.gz file in there. For the purposes of my project, I needed to update /etc/init.d/n-agent so that it worked correctly on a Debian system. I will not go into detail on bash scripting here, as that is well beyond the scope of this blog post. You can get some help by checking out /etc/init.d/skeleton on a debian system to get an idea of what your startup script might look like, or any of the other startup scripts in the /etc/init.d directory. After you are done making changes, simply re-compress the files to data.tar.gz and overwrite the one in your nagent (or comparable) directory. Next, comes the control.tar.gz file. In this archive are 6 files. conffiles contains a listing of configuration files. If removed using the dpkg --remove command, config files will be left behind (to remove said files, --purge wold be used.) control contains package information such as a description and dependancies that dpkg should check for before installing. alien should have already updated this for you. The md5sums file should be self explanatory and already taken care of for you by alien as well. The remaining files are used to configure non-static elements of you system at install/removal time. The preinst is a BASH script which runs before the installation of the debain package. Likewise postinst is run after installation. Finally prerm is used before removal. For my purposes, I only needed to modify postinst to add a user used by my program. This was because red hat and debian use different programs to add users.

Step 3: Repackageing your deb file

After updating and rearchiving you data.tar.gz and control.tar.gz directories, and cleaning up any work files/directories you used by deleting them, you must then repackage you deb file. This can be done with the command:

ar cr nagent-rhel5.1_6.7.0.2169-3_i386.deb


You can now run dpkg -i filename to verify that the changes you made worked correctly.

This should be everything you need to port a RPM package to a deb package. Good Luck!

3 comments:

Unknown said...
This comment has been removed by the author.
Unknown said...

Do you have the configuration of the file /etc/init.d/n-agent. I´m trying to install an N-agent in an Ubuntu server. I followed all the steps but I don't know what I need to change in the n-agent file. Can you help me?

James said...

Hey Kenneth, I don't have this anymore. Ubuntu has switched to a new start-up system, so unless you are using a fairly dated server this won't work for you. I no longer work with N-able's product so I don't have access to the RPM packages any longer. I also never ported for version 9 because we stopped deploying Linux agents in this manner. Check the N-able forums though or drop a line to Chris Reid (creid@n-able.com) as he may have an unofficial package.

Post a Comment