View Single Post
ammyt's Avatar
Posts: 1,918 | Thanked: 3,117 times | Joined on Oct 2010 @ My pants
#1
Packaging .deb files is easier than what you may think, it is mainly a 3 step procedure:
1. Having files of your package in /home/user/
2. Creating a folder inside the package's folder called DEBIAN, which consists of the Debian build files, we're interested in three of them:
2a) control: A file that tells dpkg how to build the package. (Mandatory)
2b) preinst: A script executed before the app installation. (Can be omitted)
2c) postinst: A script executed after the app installation. (Can be omitted)
3. The actual building of the package

Packaging Executable Apps
Let's take an example app that you have already coded, foo. Assuming the executable file foo is in ./MyDocs this is what should be done:
1. We are going to create a folder in /home/user called foopackage, which contains all the folder hierarchy. (NOTE: The path should be /home/user not /home/user/MyDocs since files there cannot have their permissions edited.)
Code:
mkdir -p /home/user/foopackage
2. First things first. In most if not all Linux distros, executable files should be placed in /usr/bin/ but since optification requires those files to be in /opt/ let's create both of these folders in the folder foopackage, then symlink them to /usr/bin.
Code:
mkdir -p /home/user/foopackage/opt
mkdir -p /home/user/foopackage/opt/foopackage
mkdir -p /home/user/foopackage/usr
mkdir -p /home/user/foopackage/usr/bin/
3. Now shift the actual executable app, foo, from MyDocs to foopackage/opt/foopackage and then symlink it to /usr/bin. Don't forget to give it executable permissions!
Code:
cp /home/user/MyDocs/foo /home/user/foopackage/opt/foopackage/
ln -s /opt/foopackage/foo /home/user/foopackage/usr/bin/foo
chmod +x /home/user/foopackage/opt/foopackage/foo
chmod +x /home/user/foopackage/usr/bin/foo
4. Why not create a neat icon in the apps grid which launches the app? Let's do it! Icons here use .desktop files that tell them what to do when tapped which should be located in /usr/share/applications/hildon/x.desktop Let's create this hierarchy in /foopackage, remember that we have already created /usr in /foopackage so we don't have to create that folder again!
Code:
mkdir -p /home/user/foopackage/usr/share
mkdir -p /home/user/foopackage/usr/share/applications
mkdir -p /home/user/foopackage/usr/share/applications/hildon
5. Now, we are going to assume that you had already created the corresponding foo.desktop file and that it is located in ./MyDocs (.desktop files will be further explained in another post.) Shift the file to the hierarchy built in the previous step.
Code:
cp /home/user/MyDocs/foo.desktop /home/user/foopackage/usr/share/applications/hildon/
6. Now for the image of the icon (foo.png )which is assumed to be located in ./MyDocs Note that it must be in .png format to appear. Icons are located in /usr/share/pixmaps so let's create that hierarchy and copy the icon to there.
Code:
mkdir -p /home/user/foopackage/usr/share/pixmaps
cp /home/user/foo.png /home/user/foopackage/usr/share/pixmaps/
(NOTE: The icon name should be set in the .desktop file, will be looked into later.)
7. This is all of the basic things prepared. If you use more files, say required by the app, then just create the corresponding hierarchies and copy them to there. In this context, foo is now complete. Final hierarchy to build is the DEBIAN folder, which consists of the files mentioned that state how to build the package. The DEBIAN folder and all files inside should have 755 permisions.
Code:
mkdir /home/user/foopackage/DEBIAN
chmod 755 /home/user/foopackage/DEBIAN
8. Now let's create and edit the mandatory control file:
Code:
leafpad or nano or vi or any text editor /home/user/foopackage/DEBIAN/control
This should launch leafpad for example with the control file. Observe the typical structure of a control file:
Code:
Package: The-Amazing-Foo
Name: The Amazing Foo
Version: 0.1
Architecture: armel
Description: Foo makes your dreams come true!* *Dreams not included. :P
Maintainer: ammyt <ammyt1@hotmail.com>
Author: ammyt <ammyt1@hotmail.com>
Section: user/Utilities+
<empty line>
Copy these lines to the control file opened by your text editor, and edit what you need to edit! Don't touch the Architecture however if you're aiming the N900 or the N9/50. Save and exit, then give it the 755 permissions:
Code:
chmod 755 /home/user/foopackage/DEBIAN/*
9. That's it! We are now ready to roll! BUT our lovely N900s do not have the specific version of tar installed (GNU) so we're gonna have to install it manually.
Code:
apt-get update
apt-get install tar-gnu
cp /usr/bin/gnu/tar /bin/
This should install the updated GNU version of tar.
10. Let's build!
Code:
dpkg-deb -b /home/user/foopackage
cp /home/user/foopackage.deb /home/user/MyDocs/
That's it! Now open the file manager and you should find foopackage.deb in Nokia N900!

Packaging a File or a Batch of Files
Take a theme for example, it is basically a folder with lots of folders and icons in it. It is much easier than an app. We are going to take a folder called themfoo, which is a folder containing many other files and folders in it, a typical theme.
1. First thing is to copy the whole folder to /home/user:
Code:
cp -rp /home/user/MyDocs/themefoo /home/user
2. Create the DEBIAN directory and give it 755 permissions:
Code:
mkdir -p /home/user/themefoo/DEBIAN
chmod 755 /home/user/themefoo/DEBIAN
3. Now let's create and edit the mandatory control file:
Code:
leafpad or nano or vi or any text editor /home/user/themfoo/DEBIAN/control
This should launch leafpad for example with the control file. Observe the typical structure of a control file:
Code:
Package: The-Amazing-Foo-Theme
Name: The Amazing Foo Theme
Version: 0.1
Architecture: armel
Description: Foo makes your dreams come true!* *Dreams not included. :P
Maintainer: ammyt <ammyt1@hotmail.com>
Author: ammyt <ammyt1@hotmail.com>
Section: user/Utilities+
<empty line>
Copy these lines to the control file opened by your text editor, and edit what you need to edit! Don't touch the Architecture however if you're aiming the N900 or the N9/50. Save and exit, then give it the 755 permissions:
Code:
chmod 755 /home/user/themefoo/DEBIAN/*
4. Let's build!
Code:
dpkg-deb -b /home/user/themefoo
cp /home/user/themefoo.deb /home/user/MyDocs/
That's it! Now open the file manager and you should find themefoo.deb in Nokia N900!

Summary
When a .deb package is installed, its contents get extracted to the folders in the hierarchy. If a package for example consists of a folder called gaga, and that folder contains a file called lady, then after the deb package is installed you will find a folder called gaga with a file called lady in it on your device. The process is very simple, just drop whatever files and folders you want extracted to their respective hierarchies, and create the DEBIAN directory with the control file then build the package and VOILA!
A diagram illustrating foopackage,deb:

So you know now that after installing the package the files foo.desktop will be extracted to usr/share/applications/hildon and that the file foo will be extracted to /usr/bin and that foo.png will be extracted to /usr/share/pixmaps

Last edited by ammyt; 2012-04-25 at 10:52.
 

The Following 45 Users Say Thank You to ammyt For This Useful Post: