9

There's a .deb software that doesn't have a .desktop file, I created that file. I want to create another package for that software, when the user installs it, I want the .desktop file to be generated automatically and placed in /usr/share/applications/

How to do so?

2 Answers 2

7
+50

Sounds like all you want to do is extract your .deb archive, add your .desktop file and the rebuild the package. This is a fairly simple process. To extract:

dpkg-deb -R package.deb extract_dir

Note -R is a raw extract to get the control files as well. Next create /usr/share/applications/ if it doesn't already exist:

mkdir -p extract_dir/usr/share/applications/

Then just add your .desktop file (be careful the name isn't going to conflict with anything else you are likely to install) and rebuild:

cp desktop_file.desktop extract_dir/usr/share/applications/
dpkg-deb -b extract_dir package_new.deb

Note you can also use dpkg-deb -b extract_dir . to create the package with its canonical name, but you will probably have to move your original out of the way first or else it will be clobbered.

Sources:
2

If you create that package, you can run a script or execute some commands after user install it. That is the use of 'postinst' shell script located in the debian folder in the source package. From this, you can generate .desktop file or do anything else.

'postinst': This is a normal shell script containing all the commands to be executed (in order) after the installation of the package. dpkg will run this automatically.

So, all you need to do is create a shell script before packing your source package into a binary package, name it as 'postinst' and put it in the debian directory.

Read more about it: https://askubuntu.com/questions/101962/script-to-only-execute-during-first-install-of-a-package

4
  • okay, could you please show me the script that will generate .desktop file when a .deb file is executed? and where to place it exactly?
    – Lynob
    Feb 20, 2014 at 22:01
  • Since you had the .desktop by yourself, the easiest way is unpack this .deb package, put in .desktop file and rebuild it. $ dpkg-deb -extract name.deb folder => extract files tree $ dpkg-deb -e name.deb folder/DEBIAN => extract control files need for packages ... the "folder/" will show directory tree of files was included in package, so you just put your .desktop in there ... $ dpkg-deb -b folder => rebuilt package, generate new folder.deb that include your .desktop file
    – incous
    Feb 21, 2014 at 6:45
  • Sorry, I couldn't use format in my comment. Please take a look at this: g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/… I tested on my Debian.
    – incous
    Feb 21, 2014 at 6:54
  • Alternative to postinst is to create a .desktop file within a deb package. So if the package is extracted, the .desktop file is copied to desired directory. See also @Graeme's answer.
    – user55518
    Feb 22, 2014 at 2:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .