Recent

Author Topic: Creating .deb packages for Lazarus applications?  (Read 34437 times)

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Creating .deb packages for Lazarus applications?
« Reply #30 on: November 03, 2020, 08:52:00 am »
I use debuild, with that I can make a src package acceptable to Ubuntu in a PPA, https://launchpad.net/~d-bannon/+archive/ubuntu/ppa-tomboy-ng

 I am working on the legal aspects of Debian, if we can get over that, I hope to use the same model to make Debian SRC packages although I have seen hints they they might prefer pbuilder.
In fact, the main difference is that pbuilder does not assume that you have the packages installed on your system. So it can be useful to check that you have all the dependencies defined in control file. Apart from that, it seems debuild is fine and it is faster when building things over and over again.

Quote
At present my model is that I have a script (prepare.bash) that takes a zip file downloaded from GitHub containg all my source and it builds the directory structure of a debian src package.   Inside that scr package the make file does much of the usual build and install things but to actually compile the Pascal source, it calls another script (buildit.bash) that uses both lazbuild (to build a dependency) and fpc to build the actual app.

Not a simple process !
Yeah. Well as far as I understand it, whether it is a script or not, you need to provide a repository with all files necessary to build. Apparently they prefer it to be on https://salsa.debian.org. You can include the debian folder, so that (p)debuild can be run on top of it. You can use fpc and lazbuild as long as you add the build dependencies (fpc, lcl, lazarus and libqt5pas-dev).

After that, I am still a bit confused but I guess the next step is to sign the package with debsign, add your pgp key to https://mentors.debian.org and upload the generated files with dput command. You may discover new problems at this point and once you solved most of them, you need to get the attention of a Debian uploader.

Quote
The  Debian process is quite well documented in very many pages on the Debian website, I suggest that not be duplicated on our wiki. But how that official process needs to be fiddled to work with FPC/Lazarus would be useful indeed. Its a steep learning curve.
Well there is a lot of documentation, but it is not obvious to find what you are looking for. Also it is indeed not adapted to FreePascal. But yeah, it is better to make links to Debian documentation when possible.
Conscience is the debugger of the mind

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Creating .deb packages for Lazarus applications?
« Reply #31 on: November 12, 2020, 06:11:42 pm »
But you must keep in mind that, for example, when it recommends we need
Code: [Select]
shlibs:Depends=libatk1.0-0 (>= 1.12.4), libc6 (>= 2.2.5), libcairo2 (>= 1.2.4), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.12.0), libgtk2.0-0 (>= 2.24.0), libpango-1.0-0 (>= 1.18.0), libx11-6all the packages listed (except libgtk2.0-0) are, themselves dependencies of libgtk2.0-0.

@dbannon:

I've tried to redemonstrate your conclusions, with a Bash script, but I can't do it.
When I run the script below...

Code: Bash  [Select][+][-]
  1. ldd myAppli | awk '/=>/{print $(NF-1)}' | while read n; do dpkg -S $n; done | awk '{print $1}' | sed 's/:amd64://' | sort | uniq | while read n; do echo "------------> usefullness of package named *$n*...:"; apt-cache search ^$n; echo "...which installs the following files on the system:"; dpkg -L $n; echo "...and depends itself on the following packages on the system:"; apt-cache rdepends $n; done;

...it informs me that the libgtk2.0-0 package installs its own libraries, and depends on other packages. But I can't show that the installation of libgtk2.0-0 also installs (though dependencies?) libpango, libatk1, libpango, ...

How do you come to your conclusions?
« Last Edit: November 12, 2020, 06:18:28 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Creating .deb packages for Lazarus applications?
« Reply #32 on: November 13, 2020, 04:39:54 am »
How do you come to your conclusions?


* You need a clean distro that has not got gtk2 already, then install gtk2 and see what extra packages are listed as about to be installed.   For a while, Cannonical was shipping Ubuntu without gtk2 but they seem to have reversed that recently.

* Use synaptic, search for libgtk2.0-0 and right click, under properties the dependencies are displayed.

* Apt command ? apt-rdepends from memory.

Davo



Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Creating .deb packages for Lazarus applications?
« Reply #33 on: November 13, 2020, 05:31:20 am »
* Apt command ? apt-rdepends from memory.

apt show libgtk2.0-0 will do it; or, if apt is not available (oldish distro), apt-cache showpkg or apt-cache show. Similar commands for aptitude will serve too.

Note that apt-cache showpkg will show first the reverse dependencies (packages which depend on libgtk2), quite a looong list; just ignore it and look only for the "normal" dependencies (packages on which libgtk2 depends).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Creating .deb packages for Lazarus applications?
« Reply #34 on: November 13, 2020, 09:34:08 am »
Not sure why you would need to know all the dependencies. If you specify that you need gtk2, then all the rest will be installed. Or did I miss something?
Conscience is the debugger of the mind

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Creating .deb packages for Lazarus applications?
« Reply #35 on: November 13, 2020, 09:53:43 am »
* You need a clean distro that has not got gtk2 already, then install gtk2 and see what extra packages are listed as about to be installed.
* Apt command ? apt-rdepends from memory.
Thanks for the advice: I'll look in a virtual machine.
In fact, I've already tested with apt-rdepends. But with this command, I didn't get a satisfactory result in my Bash script, hence my question.


apt show libgtk2.0-0 will do it;
"apt show" displays the dependencies very well, exactly what I want. I can "redemonstrate" the conclusions of dbannon with my script now:
Code: Bash  [Select][+][-]
  1. ldd myAppli | awk '/=>/{print $(NF-1)}' | while read n; do dpkg -S $n; done | awk '{print $1}' | sed 's/:amd64://' | sort | uniq | while read n; do echo "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> Usefullness of package named $n*:"; apt-cache search ^$n; echo "...which installs the following libraries on the system:"; dpkg -L $n |grep .so; echo "...and which depends itself on the following packages on the system:"; apt show $n | grep Depends; done;
It returns this:
Code: Pascal  [Select][+][-]
  1. ...\...
  2. [snip]
  3. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> Usefullness of package named libgtk2.0-0*:
  4. libgtk2.0-0 - GTK graphical user interface library - old version
  5. ...which installs the following libraries on the system:
  6. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-am-et.so
  7. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-cedilla.so
  8. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-cyrillic-translit.so
  9. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-inuktitut.so
  10. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-ipa.so
  11. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-multipress.so
  12. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-thai.so
  13. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-ti-er.so
  14. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-ti-et.so
  15. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-viqr.so
  16. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/immodules/im-xim.so
  17. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/printbackends/libprintbackend-cups.so
  18. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/printbackends/libprintbackend-file.so
  19. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/printbackends/libprintbackend-lpr.so
  20. /usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/printbackends/libprintbackend-test.so
  21. /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0.2400.32
  22. /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.32
  23. /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
  24. /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
  25. ...and which depends itself on the following packages on the system:
  26. WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
  27. Depends: libgtk2.0-common, libatk1.0-0 (>= 1.32.0), libc6 (>= 2.29), libcairo2 (>= 1.6.4-6.1), libcups2 (>= 2.3~b6), libfontconfig1 (>= 2.12.6), libgdk-pixbuf2.0-0 (>= 2.22.1), libglib2.0-0 (>= 2.41.1), libpango-1.0-0 (>= 1.28.3), libpangocairo-1.0-0 (>= 1.28.3), libpangoft2-1.0-0 (>= 1.28.3), libx11-6 (>= 2:1.4.99.1), libxcomposite1 (>= 1:0.3-1), libxcursor1 (>> 1.1.2), libxdamage1 (>= 1:1.1), libxext6, libxfixes3, libxi6, libxinerama1, libxrandr2 (>= 2:1.5.0), libxrender1, adwaita-icon-theme | gnome-icon-theme, hicolor-icon-theme, shared-mime-info
  28. ...\...[/snip]


Not sure why you would need to know all the dependencies. If you specify that you need gtk2, then all the rest will be installed. Or did I miss something?
No, you didn't miss anything: I just wanted to automate - in a IT way - the series of commands (ldd, ...) described on the page https://wiki.freepascal.org/Deploying_Your_Application, to cross-check the results with the "official" Debian command dpkg-shlibdeps -O %s explained in https://wiki.freepascal.org/Debian_package_structure, and retrieve only the really necessary, needed packages.

Thanks a lot!
« Last Edit: November 13, 2020, 11:29:27 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Creating .deb packages for Lazarus applications?
« Reply #36 on: November 14, 2020, 12:03:32 am »
There is also a need to be careful about the difference between -

* The packages a particular package depends on and
* The packages that need to be installed to install a package on one machine at that point in time.

I suspect your script shows you what is missing right now.  Its quite possible you (or someone else) has already installed individual packages that also happen to be on (eg) gtk2.0's list. Obviously, in that case, they won't be reinstalled.

If you were to get really silly, you could argue that gtk2.0 depends on the kernel.....

And also remember that when you install something like gtk2.0 on an otherwise minimal system, it will install a lot of packages that your gtk2.0 app will not, in fact ever use.  But it is convenient to bundle a superset under the name gtk2.0

Davo 
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Creating .deb packages for Lazarus applications?
« Reply #37 on: November 19, 2020, 05:54:33 pm »
Help!

I encounter a problem, with the user's /home directory (the /home directory of the user who is installing the package), creating a Debian package, with the following scenario:
- a user named user_1 wants to install an application packaged in an the_appli.deb file.
- he starts the installation (of the_appli.deb file).
- the package the_appli.deb is then launched under the user_1 account (no?).
- a dependency is found, and it must be installed (actually, I'm thinking of Firebird). So, the installer will ask you to log in as root in order to fetch and to install Firebird from PPAs.
- the installation continues.
Very good. But, at some point (which? where? how?), I need to install in the directory /home/user_1/.config/the_appli, a file named referential.xml.

Do you know if it's possible to do this, and possibly how to do it properly with a Debian package ( honestly, after researching on the internet, I have the feeling that this is not possible %) )?
« Last Edit: November 19, 2020, 06:04:03 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Creating .deb packages for Lazarus applications?
« Reply #38 on: November 19, 2020, 07:34:59 pm »
Oh I see. Indeed when you install, you are as root, and so you don't know the user folder.

One way to deal with it though is to install this file as a resource (in /usr/share/the_appli) and when your application starts, to check if the file exists in the .config directory. If not to copy it from the resource directory.
Conscience is the debugger of the mind

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Creating .deb packages for Lazarus applications?
« Reply #39 on: November 19, 2020, 10:30:12 pm »
Help!

I encounter a problem, with the user's /home directory (the /home directory of the user who is installing the package), creating a Debian package, with the following scenario:
- a user named user_1 wants to install an application packaged in an the_appli.deb file.
- he starts the installation (of the_appli.deb file).
.....

At this stage, the install should be running as root and if it has dependencies, apt installs them first.  Apt install never makes changes at the user level, if, for example, the user will need some config files or directories created, that should happen when, later, they run the application for the first time.

Don't forget linux/unix is a multiuser system, once installed, an application should be usable by every user, including ones who did not exist when the application was first installed.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Creating .deb packages for Lazarus applications?
« Reply #40 on: November 20, 2020, 07:38:45 am »
Here is a more general documentation I just wrote:
https://wiki.freepascal.org/Debian_package_structure

And thank you, Thank You indeed!

You just solved my lintian "hardening-no-pie" message that has been plaguing me for months !  What a beautiful page !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Creating .deb packages for Lazarus applications?
« Reply #41 on: November 20, 2020, 09:22:00 am »
I am happy that it is useful to you.  :)

It was suggested to me on mentors if I recall well.
Conscience is the debugger of the mind

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Creating .deb packages for Lazarus applications?
« Reply #42 on: November 20, 2020, 10:12:03 am »
One way to deal with it though is to install this file as a resource (in /usr/share/the_appli) and when your application starts, to check if the file exists in the .config directory. If not to copy it from the resource directory.

Indeed, by rereading https://wiki.freepascal.org/Debian_package_structure, it is clear and certain that everything which is an external resource, in read-only mode for the application (excluding documentation) such as i18n, external images to link at run-time, and therefore also read-only referential, must be in /usr/share/$(TargetFile)/ (like /usr/share/$(TargetFile)/i18n, ...).



Don't forget linux/unix is a multiuser system, once installed, an application should be usable by every user, including ones who did not exist when the application was first installed.

It is certain that I am always too influenced by Windows installations :-[ .
I try to do the same thing again and again, more or less: ask where to install, then put everything in the same directory near the executable: database, configuration file, documentation and referentials where I can pick.



At this stage, the install should be running as root and if it has dependencies, apt installs them first.  Apt install never makes changes at the user level, if, for example, the user will need some config files or directories created, that should happen when, later, they run the application for the first time.

Yes: the installation system manager is root, and only root. Even if the "original double click" to install is done by a simple user. So, I'm gonna install in /usr/share/$(TargetFile)/.


[Aside on]
However, I found on the net a trick, less clean but which can be useful: it is possible to code Bash\Shell scripts in 4 events named preinst, postinst, prerm, and postrm (they are thrown, if they are coded, during a Debian installation).
In the postinst event during the installation, all files are unpacked and therefore accessible. And Linux seems to keep a track of the user that was active (who made the "original double click" to install) before running the root installer. From this information, some people code (copy-paste from https://unix.stackexchange.com/questions/23463/how-to-create-debian-package-to-install-files-to-home-user)https://unix.stackexchange.com/questions/23463/how-to-create-debian-package-to-install-files-to-home-user) a script like this...:
Code: Bash  [Select][+][-]
  1. # For every user in /home/ ...
  2. for HOME_U in /home/*?; do
  3.  
  4. # Obtain the username
  5. USER=$( basename ${HOME_U} )
  6.  
  7. # In case the user is active (exists in /etc/shadow) ...
  8. if [ $( grep -c "${USER}:.*:.*:.*:.*:.*:::" /etc/shadow ) == 1 ] \
  9. && [ $( grep -c "${USER}:.*:.*:.*:.*:.*:/bin/.*sh" /etc/passwd ) == 1 ] \
  10. && [ -d ${HOME_U}/.config ] \
  11. && [ -d ${HOME_U} ]; then
  12.  
  13. # Making sure .config/your-package/ exists
  14. mkdir -p /home/${USER}/.config/your-package/
  15.  
  16. # with appropiate permissions
  17. chown ${USER}:${USER} /home/${USER}/.config/your-package/
  18.  
  19. # copy what we need
  20. cp /etc/skel/.config/your-package/x.conf /home/${USER}/.config/your-package/
  21. cp /etc/skel/.config/your-package/y.conf /home/${USER}/.config/your-package/
  22. cp ... /home/${USER}/.config/your-package/
  23.  
  24. # with appropiate permissions
  25. chown ${USER}:${USER} /home/${USER}/.config/your-package/x.conf
  26. chown ${USER}:${USER} /home/${USER}/.config/your-package/y.conf
  27. ...
  28. fi
  29. done
  30.  
...which - in theory - allows to install a *single-user* application (certainly, against the nature of Linux). Nevertheless, some create an installation by relocating (all paths in the executable must be relative) /usr, /usr/bin, /usr/share/, ... into $HOME/.local/$(TargetFile)/usr/... and in /home/${USER}/.config/your-package/$(TargetFile).conf, for example. This seems to be more and more in the spirit of some Linux Desktop editions (I'm thinking of new packaging formats such as snap, flatpack which are - caricaturally - somehow fractalization \ miniaturization of /usr notable directories and files into the /home/${USER}/snap_or_flatpack_or_appImage/a_package, with a level of confinement).
[Aside off]

Thanks to all!
« Last Edit: February 03, 2021, 02:33:01 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Creating .deb packages for Lazarus applications?
« Reply #43 on: November 20, 2020, 10:26:37 am »
Interesting. It seems to me though that. this scripts copy the config for all users.

Note: the URL is kind of duplicated
Conscience is the debugger of the mind

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Creating .deb packages for Lazarus applications?
« Reply #44 on: November 20, 2020, 11:28:21 am »
this scripts copy the config for all users.
Indeed. So, not a real one  *single-user* application's installation :-\ .
==> I'm coming back to the lack of a record somewhere in Linux of who was actively logged in, before the root installation ("original double click"), if it wasn't already root. That's strange , because I think it could be useful...

Morover, a postrm script must also be written (and shipped inside the *.deb), in order to remove everything created in the postinst script.
« Last Edit: November 20, 2020, 02:16:22 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

 

TinyPortal © 2005-2018