Create .deb Package for Femhub

Marat Mukhametshin edited this page Oct 13, 2013 · 28 revisions

In this tutorial, we'll go step by step through the process of creating .deb packages, starting with really simple packages.

A Debian package is basically a tar archive, consist of

  • control file, It contains information about a package
  • Installation scripts
  • data

step 1

Create a package directory named "my_package"

Create a sub directory named "my_package/DEBIAN"

step 2

Create a control file & installation scripts

  • my_package/DEBIAN/control
  • my_package/DEBIAN/preinst
  • my_package/DEBIAN/postinst
  • my_package/DEBIAN/prerm
  • my_package/DEBIAN/postrm

preinst, this script is responsible to do any task before installation starts

postinst, this script is responsible to do any task after extraction of the content of the package

prerm, this script is responsible to do any task before removal of any file installed by the package, like stopping some services etc.

postrm, this script is responsible to remove any file installed by the package

Note: permission of scripts should be 755

step 3

Add data files & directories that are to be copied during installation For eg, lets say we need few files to be copied in our system as

  • /usr/bin/my_file
  • /var/www/my_dir

then add these files and dirs as

  • my_package/usr/bin/my_file
  • my_package/var/www/my_dir

during installation all the content of my_package/ will be extracted in /

step 4

build the package

$ dpkg-deb --build my_package

this will create my_package.deb

Example of control file: my_package/DEBIAN/control

Package: femhub-online-lab-sdk-1.0.0
Version: 1.0.0
Architecture: amd64
Installed-Size: 1000
Depends: python2.6 (>= 2.6.5), python-numpy (>= 1.3.0), python-scipy (>= 0.7.0)
Priority: optional
Description: FEMhub Online Lab Software Development Kit (SDK)
 The purpose of this SDK is to facilitate the development of applications
 for the FEMhub Online Lab ( 
 The goal of the FEMhub Online Lab is to make computer modeling and
 simulation accessible to anyone, without a need to own expensive 
 hardware or software. The Online Lab operates inside the web browser 
 window that turns into a virtual computer desktop. The Online Lab is 
 accessible from PCs, laptops, netbooks, iPads, PDAs, and even 
 web-enabled smart phones.

Example of preinst file: my_package/DEBIAN/preinst

#! /bin/bash
set -e

if [ "$SPKG_LOCAL" = "" ]; then
    echo "SPKG_LOCAL undefined ... exiting";
    exit 1

Example of postinst file: my_package/DEBIAN/postinst

#! /bin/bash
set -e

if [ "$SPKG_LOCAL" = "" ]; then
    echo "SPKG_LOCAL undefined ... exiting";
    exit 1


# remove old install:
rm -rf $SPKG_LOCAL/lib/python/site-packages/onlinelab
CONFIG_DIR_BACKUP=`mktemp -d --tmpdir=$SPKG_LOCAL/share/`
mkdir -p $CONFIG_DIR 
echo "Old data are stored in: $CONFIG_DIR_BACKUP"

# install online lab
cp -pr onlinelab $SPKG_LOCAL/lib/python/site-packages/
cp bin/onlinelab $SPKG_LOCAL/bin
mkdir -p $CONFIG_DIR
cp -r ui $CONFIG_DIR/

# init the online lab
onlinelab sdk init --home=$CONFIG_DIR/sdk-home --ui-path=$CONFIG_DIR/ui

# allow to pass the os.environ into the engine Python process (so that
# LD_LIBRARY_PATH and other things are properly set):
echo "ENVIRON = True" >> $CONFIG_DIR/sdk-home/

# Try to copy the data from the old installation:
if [ -f "$CONFIG_DIR_BACKUP/onlinelab/sdk-home/onlinelab.db" ]; then
    echo "Copying old database into the new lab"
    cp "$CONFIG_DIR_BACKUP/onlinelab/sdk-home/onlinelab.db" $CONFIG_DIR/sdk-home/
    echo "No old database found, nothing copied."

if [ $? -ne 0 ]; then
    echo "Error installing femhub_online_lab_sdk"
    exit 1