Saturday, June 11, 2016

Debian Package Creation


Debian Package Creation 

Packaging is Important : 
a. Consistency 
b. Policy 
c. Metadata 

Two Types of packages : 
a. Binary Packages 
b. Source Packages 

Debian Package Naming Convention
- The version of the debian Package 
- It should start with Version 1 - It gets incremented on every Release 
 - amd64 or x86_64 

Example: Package name
libguestfs_2.0-1_amd64.deb

Key Points :
•copyright also file needs to be edited. "License: Commercial and add HP License into it". 
• control file should have "Section: non-free" in there as we are commercial at not open source
  
Steps for the creation of debian package

Step1:     To make a debian package it is a must to have a version in the directory. ( that’s the reason I named as “1.0”)

Step2:     Execute #dh_make --createorig command    

               In order to create a package we need to have a debian directory structure. So to create a debian directory we need to execute the above command.

               After executing this command, automatically “debian” directory would be created inside your working directory.

Step3:     Get into debian directory. Here you can see all the configuration files which are helpful for making our module into .deb package.

 Following are the files need to be modified

              1. control
              2. changelog
              3. install
              4. postinst
              5. preinst 
              6. Postrm
              7. prerm

 Please go through these files and change the content accordingly.

Step4:    After changes are done then execute this command to create a .deb      

dpkg-buildpackage -us -uc

Step5:    It’s done you can see the .deb file under the parent directory of your project.

Example: Creation of debian package for libguestfs value add 

Step-1:  Rename the project folder name with the version number i.e., from libguestfs to libguestfs-2.0 

            mv libguestfs libguestfs-2.0

Step-2:  Execute the following command to create the debain folder structure

             cd libguestfs-2.0

libguestfs-2.0$ dh_make --createorig

Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch?
 [s/i/m/l/k/n] s

Maintainer name : gyani pillala
Email-Address : ubuntu@unknown
Date : Thu, 03 Dec 2015 23:11:10 -0800
Package Name : libguestfs
Version : 2.0
License : blank
Type of Package : Single
Hit to confirm:
Currently there is no top level Makefile. This may require additional tuning.
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the libguestfs Makefiles install into $DESTDIR and not in / .


Create/Edit the following files under debian directory

                    1. control

                          Edit the following sections in the file 

                               Section, Maintainer,  Depends, Description etc

                     2. changelog

                           Edit the version numbers and mail ids in the file

                     3. install      

                           Create the file and mention the src and destination paths of files in the file

                             eg:    

                                      test.txt   /opt/libguestfs

                              This means, the test.txt file will be copied to /opt/libguestfs directory while debian package installation

                     4. postinst

                           mv postinst.ex postinst

                           And write the post installation commands under configure section in the file

                     5. postrm       

                          mv postrm.ex postrm

                          And write the post removal commands under remove section

Execute the command to create debian package ie., .deb file

libguestfs-2.0$ sudo dpkg-buildpackage -us -uc
dpkg-buildpackage: source package libguestfs
dpkg-buildpackage: source version 2.0-1
dpkg-buildpackage: source distribution unstable
dpkg-buildpackage: source changed by gyani.pillala@xyz.com 
dpkg-buildpackage: host architecture amd64
 dpkg-source --before-build libguestfs-2.0
 debian/rules clean

....
 ....
 ...

 dpkg-deb: building package `libguestfs' in `../libguestfs_2.0-1_amd64.deb'.
 dpkg-genchanges >../libguestfs_2.0-1_amd64.changes
 dpkg-genchanges: including full source code in upload
 dpkg-source --after-build libguestfs-2.0
dpkg-buildpackage: full upload; Debian-native package (full source is included)

Debian package has been created under parent directory of libguestfs-2.0      

               libguestfs-2.0$ file ../libguestfs_2.0-1_amd64.deb

../libguestfs_2.0-1_amd64.deb: Debian binary package (format 2.0)



MORE INFO:  Depends on the Deb package Requirements, need to have below scripts 

The individual files are:

 preinst

This script executes before that package will be unpacked from its Debian archive (".deb") file. Many 'preinst' scripts stop services for packages which are being upgraded until their installation or upgrade is completed (following the successful execution of the 'postinst' script). 

postinst

This script typically completes any required configuration of the package. once package has been unpacked from its Debian archive (".deb") file. Often, 'postinst' scripts ask the user for input, and/or warn the user that if he accepts default values, he should remember to go back and re-configure that package as the situation warrants. Many 'postinst' scripts then execute any commands necessary to start or restart a service once a new package has been installed or upgraded.

prerm 

This script typically stops any daemons which are associated with a package. It is executed before the removal of files associated with the package. 

postrm 

This script typically modifies links or other files associated with Package, and/or removes files created by the package. postrm file needs to differ between and "apt-get remove" and a "apt-get purge" according to the Debian standard (where "remove" would leave the config files intact and "purge" would not)


No comments: