Thursday, July 28, 2011

Creating Debian Packages with FPM for the Impatient

So I've been aware of FPM for a while, but I actually hadn't got around to using it. This is an example on Debian but it should work on Ubuntu just fine.

1) Use the package maintainers version of Ruby and RubyGems.

root@debian64-10:~/tmp# apt-get install ruby ruby-dev rubygems
[snip]
Get:1 http://ftp.us.debian.org/debian/ squeeze/main rubygems1.8 all 1.3.7-3 [202 kB]
Get:2 http://ftp.us.debian.org/debian/ squeeze/main rubygems all 1.3.7-3 [66.7 kB]
Fetched 269 kB in 0s (518 kB/s)
Selecting previously deselected package rubygems1.8.
(Reading database ... 50363 files and directories currently installed.)
Unpacking rubygems1.8 (from .../rubygems1.8_1.3.7-3_all.deb) ...
Selecting previously deselected package rubygems.
Unpacking rubygems (from .../rubygems_1.3.7-3_all.deb) ...
Processing triggers for man-db ...
Setting up rubygems1.8 (1.3.7-3) ...
Setting up rubygems (1.3.7-3) ..


2) Install FPM

root@debian64-10:~/tmp# gem update; gem install fpm
Updating installed gems
Nothing to update
Building native extensions. This could take a while...
Successfully installed json-1.5.3
Successfully installed fpm-0.3.7


3) This installed it but where does the script go? It isn't in /usr/local/bin. Nah that would be too obvious.

root@debian64-10:/# find / -name "fpm"
/var/lib/gems/1.8/bin/fpm
/var/lib/gems/1.8/doc/fpm-0.3.7/rdoc/files/lib/fpm
/var/lib/gems/1.8/gems/fpm-0.3.7/bin/fpm
/var/lib/gems/1.8/gems/fpm-0.3.7/lib/fpm


4) Update your path to included the gem wrappers and confirm that it runs

root@debian64-10:/# export PATH=$PATH:/var/lib/gems/1.8/bin
root@debian64-10:/# fpm
Missing package target type (no -t flag?)
Missing package source type (no -s flag?)
There were errors; see above.

Usage: fpm [options]
-p, --package PACKAGEFILE Th


To make it interesting, let's create a package that requires a dependency. The app I'm doing this for at work requires Java unfortunately, but I'll do Mono here for fun.

(I'm skipping the part here where I google for a lame Hello World C# app because I haven't touched the language since 2005 but the bottom line is I end up with .exe that will go in /usr/local/bin) so we have something like.


root@debian64-10:~/hellomono# pwd
/root/hellomono
root@debian64-10:~/hellomono# ls -al usr/local/bin/hellomono.exe
-rwxr-xr-x 1 root root 4096 Jul 28 21:39 usr/local/bin/hellomono.exe


All we are doing here is specifying the source (a directory) and a destination target (.deb). I assume we could do the same thing for an RPM or even creepier build a Ruby gem that contained a Mono app.


root@debian64-10:~/hellomono# fpm -s dir -t deb -d mono-runtime .


This created a .deb based on your current directory


tar: ./build-deb-hellomono_1.0_amd64.deb/data.tar: file is the archive; not dumped
Created /root/hellomono/hellomono_1.0_amd64.deb
root@debian64-10:~/hellomono# ls
hellomono_1.0_amd64.deb usr


And if we open it up


root@debian64-10:/tmp# ar -x hellomono_1.0_amd64.deb
root@debian64-10:/tmp# ls
control.tar.gz data.tar.gz debian-binary hellomono_1.0_amd64.deb hsperfdata_root
root@debian64-10:/tmp# tar xzvf control.tar.gz
control
md5sums
root@debian64-10:/tmp# cat control
Package: hellomono
Version: 1.0
Architecture: amd64
Maintainer:
Depends: mono-runtime
Standards-Version: 3.9.1
Section: default
Priority: extra
Homepage: http://nourlgiven.example.com/no/url/given
Description: no description given
root@debian64-10:/tmp# ls
control control.tar.gz data.tar.gz debian-binary hellomono_1.0_amd64.deb hsperfdata_root md5sums
root@debian64-10:/tmp# tar xzvf data.tar.gz
./
./build-deb-hellomono_1.0_amd64.deb/
./usr/
./usr/local/
./usr/local/bin/
./usr/local/bin/hellomono.exe


Now I scp it over to an Ubuntu LTS box and install


virtual@ubuntu14:~$ sudo dpkg -i hellomono_1.0_amd64.deb
[sudo] password for virtual:
Selecting previously deselected package hellomono.
(Reading database ... 73505 files and directories currently installed.)
Unpacking hellomono (from hellomono_1.0_amd64.deb) ...
dpkg: dependency problems prevent configuration of hellomono:
hellomono depends on mono-runtime; however:
Package mono-runtime is not installed.
dpkg: error processing hellomono (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
hellomono


Fix the dependencies

virtual@ubuntu14:~$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree
[snip]
Setting up hellomono (1.0) ...
Setting up libmono-system2.0-cil (2.4.4~svn151842-1ubuntu4) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place


And it runs!


virtual@ubuntu14:~$ /usr/local/bin/hellomono.exe
Hello World
virtual@ubuntu14:~$ dpkg -l | grep hello
ii hellomono 1.0 no description given

No comments: