Deb is the Debian package or as an ‘installer’ for Debian-based distributions. There are two types of Debian packages, both with the same functionality to implement certain command, resource or resources.

I will address the creation of a Debian binary package, which is the most used between the two types of packages. Consists of multiple executables, configuration files, manual pages, proprietary information, and other documentation. Packages are commonly found with the extension ‘. Deb’.

For the establishment is required to follow certain rules regarding the structure:

  • It should create a folder to contain the files related to the package.
  • The Debian package is mainly composed of a folder named DEBIAN, which will control scripts and file.
  • The control file which contains all the needs and requirements for the implementation and installation of the package. Just like the name, version, description, among others.
  • The scripts are not necessary but are often used in the DEBIAN folder you can create scripts to before starting the installation (preinst) and removal (prerm), and after installation (postinst) and removal (postrm) . These files are commonly written in shell script.

On a Debian package is also possible to put certain files in certain folders. Just putting the folder with your name exactly as it will be in the folder and its path.

To illustrate, we will create a package for running a PHP.

Assuming that the name of our package is examplePHPDEB, the framework for creating it would be:

  • examplePHPDEB
  • DEBIAN
    • control
    • preinst
    • postinst
    • postrm
    • prerm
  • var
    • www
      • example.php

Structure Package

We create the package folder DEB examplePHPDEB , within the same, be the folder DEBIAN where scripts are run, to be executed during package installation, and file control having the package configurations.

Also our PHP file to be executed. Exactly in the folder where it should stay. is placed on the structure of the package the exact path where will be the same after installation, in our example the example.php file is in / var / www / example.php

Control

The control file is the most important file of creating the DEB package, without it, you can not create the package. In this file will be stored packet data created, such as name, version, description, dependencies, Maintainer, among others.

A Control file can be composed as follows, within the DEBIAN folder.

Content:

 Package: examplePHPDEB
Priority: optional
Version: 1.00
Architecture: i386
Maintainer:  Vinícius Muniz
Installed-size: 10
Section: devel
Depends: php5 (> = 5.2.1), apache2 (> = 2.2.3), php5-gd, php5-sqlite
Homepage: http://www.viniciusmuniz.com/
Description: Package example, to execute a php file 

.

To run scripts before or after installing the package, you can use the files in the folder DEBIAN:

  • Preinst – Executed before beginning installation;
  • postinst – Executed after the end of the installation;
  • prerm – Executed before removal;
  • postrm – Executed after removal
  • .

The scripts follow the same pattern. Using bash, sh, or ksh. Or if you know “make mallets”, you can use php, c, c + +, it would be a matter of making the call to the file with other language within the package scripts.

In our example there is no need to use one of these scripts. But we will use to create a menu icon to open the browser with the php file being executed.

postinst

 #! / Bin / sh
#
# Copyright (c) 2010 The Authors  Vinicius Muniz. All rights reserved.

# Add icons to all users.

User is in $ (ls / home), the
if [ ! -d /home/$usuario/.local/share/applications ]; then
mkdir /home/$user/.local/share/applications
phi
cp /usr/share/applications/examplePHPDEB.desktop /home/$user/.local/share/applications
done 

postinst

To use this script, we will create another file with the name examplePHPDEB.desktop where we will store the data shortcut. The file will be stored within / usr / share / applications / within the package, and after installation in the same way inside the server. [ 3×1002]

The contents of the shortcut will be:

 

 [Desktop Entry]
# Created by Vinícius Muniz 
Version = 1.0
Encoding = UTF-8
Name = examplePHPDEB
# Only use KDE 4 seems to GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-twentieth-based packages, version 9.04-20090413.
GenericName = examplePHPDEB

# Gnome and KDE 3 uses Comment.
Comment = Example DEB

Exec =/var/www/start.sh
Terminal = false
Type = Application
Categories = GTK; Application; Development; IDE;
StartupNotify = true 

examplePHPDEB.desktop

For the implementation of our file we will create another file in shell to open the browser with PHP script running. . The file is specified in the Exec desktop file will be the start.sh file, its content will be:

 

 #!/bin/sh
# Created by Vinícius Muniz 

sudo /etc/init.d/apache2 start

for i in google-chrome firefox mozilla konqueror, the
if test-x "/usr/bin/$i"; then
/usr/bin/$i http://localhost/example.php
exit $?
phi
done 

start.sh

After creating the entire structure, and edit all the scripts we want, we really have. Deb.

We will use the command dpkg-deb . With the syntax:

  dpkg-deb-b   

Okay, with that, we will DEB package generated

and to execute the same, we can use the command

   dpkg-i  path> package>.   

 

 

Written by vinicius