Monday, August 29, 2011

Creating basic *.deb packages for Debian or Ubuntu

Basic *.deb packages are easy to build, but it can turn more complicated due to the task it should do after or before the install process.

This is a simple  *.deb package.

Name-package_version_architecture/
|
|_DEBIAN/
|      |_control
|
|_Folders that contain the program from the root system/

The folder called DEBIAN is the most important, due to inside it we'll place the scripts for the installation. In this example we only use the control file, which is mandatory in a package.

Let's make this example. Let's say we have this little script called myPC.sh and we want to build it as a package.

Follow this steps:

1.  Make a folder in any place and call it myPC, inside create a folder like this myPC_0.1_all where myPC is the name of the package, 0.1 is the version and all is the architecture, in this example we use all because it doesn't matter if it is i386 or amd64. And the use of the underline(_) is for join the name.

2.  Inside myPC_0.1_all create a folder named as DEBIAN and inside it create a file called control.
Write this in the control file.

Package: myPC
Version: 0.1
Section: MyPrograms
Priority: optional 
Maintainer: Abel Bolaños Martínez <abelbmartinez@gmail.com>
Architecture: all 
Description: My first package
This program show my system name
.
I did it by myself.

The control file has a lot of field but for now we use only these. As you can appreciate we can write in the Description field  an information of our program.

Like this: 

myPC_0.1_all/
|
|_DEBIAN/
        |_control

3.  We want that our script install in /bin folder in our system, that help us to execute the script in any place. So, go to myPC_0.1_all folder and create the bin folder. Inside bin with any text editor create a file called myPC.sh and write this:
uname -a

Save it and open a terminal and change the properties of the file so it can be executed and not modified.
Write this in the terminal:
chmod 755 myPC.sh

We should have something like this:

myPC_0.1_all/
|
|_DEBIAN/
|      |_control
|
|_bin/
     |_myPC.sh

4.  Enough, let's build our package. Open a terminal and placed in myPC folder and type:
dpkg-deb --build myPC_0.1_all/

It's done! you'll see your myPC_0.1_all.deb inside myPC folder.

Now you can install it.



No comments:

Post a Comment