Simplest way to create debian package via fpm

Simplest way to create debian package via fpm

September 17,2015 by owaishanif786

Simplest way to create debian package via fpm

Debian Packaging

In this tutorial we will look through how to package some simple hello world script. A quote from debian maintainer's guide:

One thing is certain, though: to properly create and maintain Debian packages takes many hours. Make no mistake, for our system to work the maintainers need to be both technically competent and diligent.

We have many methods to create a Debian package In this tutorial we will use FPM.

VIA FPM

This method requires minimum effort follow this if you don't want to upload to PPA. However it requires ruby gem and package name FPM. check wiki for further details.

mkdir -p ~/via-fpm/debian/usr/bin/
cd ~/via-fpm/debian/
touch ~/via-fpm/debian/usr/bin/hello-via-fpm.sh
gedit ~/via-fpm/debian/usr/bin/hello-via-fpm.sh

Add following lines to script.

#!/bin/bash
echo "hello debian packaging via fpm"

Save and close that file. whatever folder structure you will put in your source folder it will automatically copied into respected folders. There is no need to to copy them. For example if you want to put some sources file in /opt/local/sources then you must have same structure in you application source. Similarly usr/bin/ files will automatically copied to their respected folder in this case that will be /usr/bin.

Next we will come towards the scripts that will automatically run like preinstall , post install , pre un-install and post un-install . If you want to create user, directories, set permissions then these scrips are for you. You can use bash here. In this demo we will use "postinst" script to set permission for ~/via-fpm/debian/usr/bin/hello-via-fpm.sh create postint file in described location and add the following code.

mkdir -p opt/local/
touch opt/local/postinst
gedit opt/local/postinst

Set so that user can execute command from shell.

#!/bin/bash
set -e
sudo chmod +x ~/via-fpm/debian/usr/bin/hello-via-fpm.sh 
exit 0

It't time for packaging.

cd ~/via-fpm
fpm --epoch 1 -s dir -e -C debian \
-a all -m "uncle demo <UncleDemo@example.com>" \
--description "our absurd debian package for demo via fpm" \
-v 1.0  -t deb  -n hello-via-fpm --after-install debian/opt/local/postinst 

Switches that we have used and their meaning

-epoch: Used for epoch value is somehow versioning number
-e: Edit the package spec before building. (default: false)
-C: Change directory to here before searching for files
-a: The architecture name. Usually matches 'uname -m'. For automatic values, you can use '-a all' or '-a: native'. These two strings will be translated into the correct value for your platform and target package type.
-m: The maintainer of this package. (default: "djhaskin987@djhaskin987-S301LA")
--description: add description
-v: specify version number
-t: output type
-n: Name to give to the package
--after-install: file to run after post install

Why FPM:

Because it will automatically create necessary files like control, rules and lot other necessary stuff for you. There are other proper ways to do that using official Debian package management through which you can upload your package to PPA. That we will discuss in next demo.

INSTALLATION:

To install that package either open via Ubuntu software center or run command sudo dpkg -i hello-via-fpm_1.0_all.deb

LAST CHECK:

Now try to run command from shell hello-via-fpm.sh to see that your package is installed now and further you can create your own with customizations.