Easy Way to Create Simple Linux Packages

I just figured out how to create an installation package in any of the popular formats (deb, rpm, etc..) in under 30 seconds. This method is probably not something you’d want to use for a serious project, but it is perfect for small scale things such as shell scripts, or various perl/python/ruby concoctions you want to distribute.

Before i start, I must confess that I never really made a deb package from scratch. I did create debs before with stuff like checkinstall. For example I do it every time I install ffmpeg on one of my machines because for some reason that package is horribly, horribly broken in the repos and half the features are disabled. If you want a working copy, you have to grab the source and roll up a deb yourself.

I never created a deb for one of my own scripts because I never needed too. Most of the time stuff that I write ends up being a single script or an executable, which I stick in /usr/local/bin or just keep it in the home directory. If I distribute it, I always figured someone else could do exactly the same – grab the binary and stick it somewhere in the path.

But the other day I was like “maybe I’ll just make a deb for this one script here since I already have like a whole project page for it. And so I googled “How to make a deb” and got tons of excellent tutorials, each of which was at least 50 pages long. I figured I was doing something wrong because a simple thing like creating a package can’t be that complicated and the creators of these extremely detailed howto pages must simply be suffering from the common case of verbal diarrhea which seems to plague at least every third linux user.

I mean, it took me 10 minutes to write and debug this script. If wrapping it inside of a deb takes 3 hours, then we are in trouble. Fortunately I’m a very lazy individual, and instead of trying to follow one of these gargantuan howto articles, I decided to find a quicker way and installed the EPM package:

sudo aptitude install epm

EPM basically builds packages for you almost automatically. All you need to do in terms of setup is to create a single .list file in the same directory as your project. For example for Twimi I created the following file:

%product twimi
%copyright 2008 by Lukasz Grzegorz Maciak
%vendor Lukasz Grzegorz Maciak
%description A minimalistic, command line Twitter updater.
%version 0.4
%readme README
%license LICENSE
%requires curl
f 755 root sys /usr/bin/twimi twimi

I think the above is pretty much self explanatory. The first 8 lines are metadata which will be embedded in the deb – you know, the stuff that you can read when you do aptitude show. The last line specifies what to do with the project files during installation. The syntax for this command is pretty much this:

f  mode  user  group  destination  source

You can find more info about other prefixes (there is c for configuration files, d for creating directories and etc..) by running man epm.list. All I needed was to copy a single shell script to some directory in your path, and then make it executable, and that was accomplished with the single line above. No need for any other tinkering. I saved the file as twimi.list and created README and LICENSE files because apparently epm expects them. You can leave them empty, but they need to be there for some reason.

Once you have all of this set up, you can create a deb by running the following command (where you’d replace twimi with the name of your project naturally):

sudo epm -f deb twimi

KABLAM! The deb will magically appear in a subdirectory named after your platform and architecture – for me it was linux-2.6-intel. Added benefit is that you can use the same .list file to generate other types of packages. Observe:

sudo epm -f rpm twimi

In addition to basic linux packages can apparently also make osx and bsd ones as well – but you will need the prerequisite package management tools for those systems installed. So I couldn’t really create an osx package (and I don’t own a mac so I don’t know how would I test it), but the option is there if you need it.

Undoubtedly someone will probably tell me there is an easier and more straightforward way to do this kind of stuff. This method worked for me, but if there is another more proper, and equally straightforward way I’d love to hear about it.

This entry was posted in sysadmin notes and tagged , . Bookmark the permalink.

2 Responses to Easy Way to Create Simple Linux Packages

  1. jambarama UNITED STATES Mozilla Firefox Linux Terminalist says:

    Much better than the kludge I’ve used. Before debian was as friendly as it is now, I had spent years using redhat & mandrake (before it was mandriva). This was in my more technical days too, so I learned how to make an rpm. I understand this formerly arcane art is now a bit more user friendly too, but I basically did this.

    When I switched to debian, and now I’d never use anything but debian, I had all these custom rpms I used, and I wasn’t even sure I had kept all my source. It was nothing big, mostly scripts and handy extensions, but they were important to me. So then I found alien – it converted my rpms to debs, and they worked!

    So the once or twice in the last 3 years I’ve made a deb, I rolled everything into an rpm, like I was used to, then used alien to make it a deb. A horrible horrible kludge, but one that worked every time for me. However, this is much easier.

    Great post.

    Reply  |  Quote
  2. IceBrain PORTUGAL Mozilla Firefox Linux Terminalist says:

    That’s great, I’ve used checkinstall also (great tool btw) but I never understood the maze that it is to make a simple deb. I usually just put the scripts in a folder in my /home (usually hidden) and put it in the PATH, I don’t like to mix my small and humble scripts with normal binary blobs.

    Thank you for writing about this tool, I really like it!

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *