maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   The Grand DEB Packaging Thread! (https://talk.maemo.org/showthread.php?t=80914)

ammyt 2011-12-16 14:40

The Grand DEB Packaging Thread!
 
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:
http://i.imgur.com/6pna2.jpg
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

Estel 2011-12-16 14:48

Re: The Grand DEB Packaging Thread!
 
Thanks for this nice tutorial. Could you please consider transferring this whole post to Wiki, as Wiki page?

Also, post about using dput to transfer .deb into repositories (omitting autobuilder) could greatly increase packages couunt in repository, at the same time decreasing number of available-only-from-forum-threads-hidden-somewhere programs ;)

/Estel

ammyt 2011-12-16 14:52

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by Estel (Post 1138303)
Thanks for this nice tutorial. Could you please consider transferring this whole post to Wiki, as Wiki page?

Also, post about using dput to transfer .deb into repositories (omitting autobuilder) could greatly increase packages couunt in repository, at the same time decreasing number of available-only-from-forum-threads-hidden-somewhere programs ;)

/Estel

Lol, I guess that wink was pointed towards CPU Power Control eh? xD
Sure, I will add lots of more tutorials, this one took me 20 mins to write. Once all of them sum app and link to each other, I will create a page in the WIKI about deb packaging on the N900 or any Linux Distro. BTW, I heard that Xterminal on the N9 uses a trimmed down version of Busybox, is that so?
I mean, is GNU tar present? What about dpkg --build?

Estel 2011-12-16 15:04

Re: The Grand DEB Packaging Thread!
 
Actually, this wink wasn't meant at You program, as i don't use it (no offense). It was rather about plentora of posts like "I would put it into repos, but I don't have time to learn autobuilder, could someone do it for me?".

As for harmattan, I have no idea - thankfully, no need to even touch it ;)

ammyt 2011-12-16 15:17

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by Estel (Post 1138322)
Actually, this wink wasn't meant at You program, as i don't use it (no offense). It was rather about plentora of posts like "I would put it into repos, but I don't have time to learn autobuilder, could someone do it for me?".

As for harmattan, I have no idea - thankfully, no need to even touch it ;)

Sure, a good example would be MaeModder, I betchu' will search about 10 minutes till you find its .deb. I'm with ya.

I haven't touched it yet either, any body in here with an N9?

rcolistete 2011-12-16 15:47

Re: The Grand DEB Packaging Thread!
 
Yes, MeeGo 1.2 Harmattan has 'dpkg-dev' package (when Harmattan SDK repository is enabled). As well as 'build-essential' (installation of 93 MB). Also 'bsdtar' is available.

So 'dpkg-deb', g++, etc, are available in Nokia N9/N950.

ammyt 2011-12-16 15:55

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by rcolistete (Post 1138354)
Yes, MeeGo 1.2 Harmattan has 'dpkg-dev' package (when Harmattan SDK repository is enabled). As well as 'build-essential' (installation of 93 MB). Also 'bsdtar' is available.

So 'dpkg-deb', g++, etc, are available in Nokia N9/N950.

Good. This guide is also applicable on the N9/50, and IF I ever happened to buy an N9, I can pretty much package everything on it as I do right now on my good ol' N900.

sulu 2011-12-16 23:26

Re: The Grand DEB Packaging Thread!
 
This how-to does not take into account that the N900 has very limited space on / where /usr resides. Therefore it would be good to move all package contents from /usr to /opt and create symlinks in /usr. This is what Maemo users call "optification" of a package.

Except for that it's a nice tutorial.

rcolistete 2011-12-21 16:50

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by sulu (Post 1138534)
This how-to does not take into account that the N900 has very limited space on / where /usr resides. Therefore it would be good to move all package contents from /usr to /opt and create symlinks in /usr. This is what Maemo users call "optification" of a package.

Nokia N9/N950 don't have this optification problem : "/" has 3.9GB with 2-3 GB available when brand new.

ammyt 2011-12-21 17:42

Re: The Grand DEB Packaging Thread!
 
Well I have 12Gigs for installable applications, and the rest as MyDocs.

Estel 2011-12-22 03:49

Re: The Grand DEB Packaging Thread!
 
... which doesn't change the fact, that "Grand .deb packaging thread" on talk.maemo.org should take optification into account. ammyt, could You please fix instructions ASAP?

/Estel

ammyt 2011-12-22 08:15

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by Estel (Post 1140630)
... which doesn't change the fact, that "Grand .deb packaging thread" on talk.maemo.org should take optification into account. ammyt, could You please fix instructions ASAP?

/Estel

Calm down, I am adding them :D

ammyt 2011-12-22 08:34

Re: The Grand DEB Packaging Thread!
 
Done, now drawing a new map of the files.

marmistrz 2011-12-23 14:50

Re: The Grand DEB Packaging Thread!
 
Is it possible to make the .changes file this way?

niloy 2011-12-23 15:37

Re: The Grand DEB Packaging Thread!
 
thanks for the wonderful tutorial. can you also mention how to push to maemo repo?

marmistrz 2011-12-23 17:30

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by niloy (Post 1141201)
thanks for the wonderful tutorial. can you also mention how to push to maemo repo?

Yeah. This way it doesn't give the .changes file

sulu 2011-12-23 20:43

Re: The Grand DEB Packaging Thread!
 
Good start, but your optification link won't work since it points to the wrong directory.

Code:

ln -s /home/user/foopackage/opt/foopackage/foo /home/user/foopackage/usr/bin/foo
You link to /home/user/foopackage/opt/foopackage/foo which works fine during creation but will fail after the package is installed because the link target will still be /home/user/foopackage/opt/foopackage/foo while it actually would have to be /opt/foopackage/foo
So change your ln command accordingly:
Code:

ln -s /opt/foopackage/foo /home/user/foopackage/usr/bin/foo
If you check this link in your testing environment it won't work because you have no /opt/foopackage/foo but it will work after installing the package.

F2thaK 2011-12-24 08:53

Re: The Grand DEB Packaging Thread!
 
Ive got issues with installing my DEBs. They wont install.
"aegies rejecting control file"

Ive got 755 permissions on package files, DEBIAN folder and control file

Help?!

lopho 2011-12-24 09:11

Re: The Grand DEB Packaging Thread!
 
a note on the optification/symlinking

i guess it would be best to symlink in the postinst script, as symlinking to your build enviroment wont work and symlinking in your /usr/bin will only work on the machine you did the linking on.

another one on the control file:

most apps will have dependencies, how about you include info on dependency handling.

for example:

Code:

Package: acme
Version: 1.0
Section: web
Priority: optional
Architecture: all
Essential: no
Depends: libwww-perl, acme-base (>= 1.2)
Pre-Depends: perl
Recommends: mozilla | netscape 
Suggests: docbook
Installed-Size: 1024
Maintainer: Joe Brockmeier <jzb@dissociatedpress.net>
Conflicts: wile-e-coyote
Replaces: sam-sheepdog
Provides: acme
Description: The description can contain free-form text
            describing the function of the program, what
            kind of features it has, and so on.
.
More descriptive text.


F2thaK 2011-12-24 09:24

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by rcolistete (Post 1138354)
Yes, MeeGo 1.2 Harmattan has 'dpkg-dev' package (when Harmattan SDK repository is enabled). As well as 'build-essential' (installation of 93 MB). Also 'bsdtar' is available.

So 'dpkg-deb', g++, etc, are available in Nokia N9/N950.

Packaging does not work on my N9 even after installing the 3 apps mentioned above.

Quote:

dpkg-deb: subprocess tar -cf returned error exit status 1

marmistrz 2011-12-25 14:35

Re: The Grand DEB Packaging Thread!
 
How to create a .changes file this way?
Without it I cannot upload to extras-devel

marmistrz 2011-12-27 15:24

Re: The Grand DEB Packaging Thread!
 
How to create the .changes file this way?

Schturman 2011-12-31 00:38

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by ammyt (Post 1138356)
Good. This guide is also applicable on the N9/50, and IF I ever happened to buy an N9, I can pretty much package everything on it as I do right now on my good ol' N900.

No.. it's not work on N9...
When I run this command:
Code:

dpkg-deb -b /path/to/package
I always get this:
Code:

tar: unrecognized option '--format=gnu'
BusyBox v1.19.0.git (MeeGo 3:1.19-8+0m6) multi-call binary.
Usage: tar -[cxtzjhmvO] [-X FILE] [-T FILE] [-f TARFILE] [-C DIR] [FILE]...
dpkg-deb: subprocess tar -cf returned error exit status 1


F2thaK 2011-12-31 00:43

Re: The Grand DEB Packaging Thread!
 
Ive got issues with installing my DEBs. They wont install.
"aegies rejecting control file"

Ive got 755 permissions on package files, DEBIAN folder and control file

Help?!

Schturman 2011-12-31 00:51

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by F2thaK (Post 1143667)
Ive got issues with installing my DEBs. They wont install.
"aegies rejecting control file"

Ive got 755 permissions on package files, DEBIAN folder and control file

Help?!

What you have in DEBIAN folder ? Check this again.. I have the same issue (can't install) when I used postinst and postrm files...
But now I fixed this and It can be installable..

F2thaK 2011-12-31 01:04

Re: The Grand DEB Packaging Thread!
 
I havent tried any postinst and postrm files.. only control. my first few attempts at packaging worked. but now, doing it the same, they wont install.

Im thinking maybe theres a syntax error somewhere.

Heres my control file:
http://www.multiupload.com/4HNKC706KQ

If someone could take a look Id really appreciate it.

Schturman 2011-12-31 01:22

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by F2thaK (Post 1143671)
I havent tried any postinst and postrm files.. only control. my first few attempts at packaging worked. but now, doing it the same, they wont install.

Im thinking maybe theres a syntax error somewhere.

Heres my control file:
http://www.multiupload.com/4HNKC706KQ

If someone could take a look Id really appreciate it.

Try something...
1) this section:
Code:

XB-Maemo-Flags: visible
XB-Maemo-Display-Name: Faster Darker Better Theme

change to this:
Code:

Maemo-Flags: visible
Maemo-Display-Name: Faster Darker Better Theme

2) Giv the same name of your package in /home/user, like this:
Code:

/home/user/fdb-theme
3) try to change the "Maemo-Display-Name: Faster Darker Better Theme" to the shorter one like "Maemo-Display-Name: Faster Theme"

4) if 1+2+3 don't work, try to remove this line:
Code:

Installed-Size: 1200
5) if all this still don't work, tell me where your package will be installed and if this have copy something into MyDocs ?

F2thaK 2011-12-31 02:01

Re: The Grand DEB Packaging Thread!
 
This package doesnt install anything to MyDocs, but I have tried to packaged other things that install to MyDocs which also dont install and give same error as one above.

Thanks for your help.

Edit: I would also like to add postinstall and rm scripts if you could help me with that

ammyt 2011-12-31 08:44

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by F2thaK (Post 1141392)
Packaging does not work on my N9 even after installing the 3 apps mentioned above.

You sure the tar version you're using is GNU?
If not, you can download this tar then:
Code:

cp /where/you/downloaded/that/tar /usr/bin/tar

ammyt 2011-12-31 08:46

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by marmistrz (Post 1142362)
How to create the .changes file this way?

I'm gonna look into it, stop crying for god's sake!

ammyt 2011-12-31 08:52

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by sulu (Post 1141274)
...
So change your ln command accordingly:
Code:

ln -s /opt/foopackage/foo /home/user/foopackage/usr/bin/foo
If you check this link in your testing environment it won't work because you have no /opt/foopackage/foo but it will work after installing the package.

Wait, so users would have to install the package twice :confused:
As said, it is best to include the ls in the postinst install, that would be true optification :D

Just a heads-up, in the applications I have made, I only create a file in /usr/bin that executes the actual executable in /opt. Like, the file, say foo, in /usr/bin/ contains a one line command which is /opt/foopackage/foo which launches the actual application from /opt once that /usr/bin/foo file is executed.

How about that?

F2thaK 2011-12-31 09:09

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by ammyt (Post 1143758)
You sure the tar version you're using is GNU?
If not, you can download this tar then:
Code:

cp /where/you/downloaded/that/tar /usr/bin/tar

So I should be able to package on the N9?

ammyt 2011-12-31 09:26

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by F2thaK (Post 1143780)
So I should be able to package on the N9?

Yes, in theory, yes.

marmistrz 2011-12-31 09:49

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by ammyt (Post 1143761)
I'm gonna look into it, stop crying for god's sake!

It seemed that my question isn't even noticed ;)
Because of that I posted it :)

Estel 2011-12-31 11:17

Re: The Grand DEB Packaging Thread!
 
[off-topic]It's most likely going to be "unnoticed", if You would continue to repeat it over and over. Like You have quite a history of doing so, on this forum...[/off-topic]

Schturman 2011-12-31 11:57

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by F2thaK (Post 1143681)
Edit: I would also like to add postinstall and rm scripts if you could help me with that

The problem was with postinst and postrm because my package installed in to /home/user and from this location my postinst will need to be transfered one file into MyDocs/Documents..
I used this command:
Code:

#!/bin/sh

cp -f /home/user/N9QTweak/Nokia_N9_QuickTweak_script_v2.9.pdf /home/user/MyDocs/Documents

Problem here that if I want to transfer something from this location to MyDocs, I need to be USER, but my script run as ROOT.. For fixing I used this command:
Code:

#!/bin/sh

devel-su user -c "cp -f /home/user/N9QTweak/Nokia_N9_QuickTweak_script_v2.9.pdf /home/user/MyDocs/Documents"


Schturman 2011-12-31 12:32

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by ammyt (Post 1143758)
You sure the tar version you're using is GNU?
If not, you can download this tar then:
Code:

cp /where/you/downloaded/that/tar /usr/bin/tar

Not work..
I steel get the same error:
Code:

tar: unrecognized option '--format=gnu'
BusyBox v1.19.0.git (MeeGo 3:1.19-8+0m6) multi-call binary.
Usage: tar -[cxtzjhmvO] [-X FILE] [-T FILE] [-f TARFILE] [-C DIR] [FILE]...
dpkg-deb: subprocess tar -cf returned error exit status 1

I checked this folder (/usr/bin) before using your file, we don't have here any file or folder named "tar" or GNU..

ammyt 2011-12-31 12:49

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by Schturman (Post 1143874)
Not work..
I steel get the same error:
Code:

tar: unrecognized option '--format=gnu'
BusyBox v1.19.0.git (MeeGo 3:1.19-8+0m6) multi-call binary.
Usage: tar -[cxtzjhmvO] [-X FILE] [-T FILE] [-f TARFILE] [-C DIR] [FILE]...
dpkg-deb: subprocess tar -cf returned error exit status 1

I checked this folder (/usr/bin) before using your file, we don't have here any file or folder named "tar" or GNU..

Forget the commands I typed, just be sure to place the new tar in /usr/bin then chmod +x it.

I don't have an n9/50 thus I have no idea about aegis crap.

Schturman 2011-12-31 13:23

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by ammyt (Post 1143879)
Forget the commands I typed, just be sure to place the new tar in /usr/bin then chmod +x it.

I don't have an n9/50 thus I have no idea about aegis crap.

Now I got this:
Code:

/usr/bin/tar: line 1: /opt/maemo/usr/bin/gnu/tar: not found
gpkg-deb: subprocess tar -cf returned error exit status 127

It's because we don't have this folders (/maemo/usr/bin/gnu/tar) in /opt...

marmistrz 2011-12-31 14:35

Re: The Grand DEB Packaging Thread!
 
Quote:

Originally Posted by marmistrz (Post 1142362)
How to create the .changes file this way?

I might've found the way to do it:
http://www.debian.org/doc/manuals/ma.../build.en.html

It's dpkg-genchanges

I'll look into it soon


All times are GMT. The time now is 22:48.

vBulletin® Version 3.8.8