4

I find apt in terminal as the best way to install a program from a deb package. As I prefer it to other gui tools, I want that in the context menu for deb files or as a launcher among applications in order to install the deb by executing it with (double) click.

In Kubuntu with Dolphin I have created a service menu to create that context menu, also a desktop file in ~/.local/share/applications to achieve the same action by executing the deb file.

The file ~/.local/share/kservices5/ServiceMenus/install-deb.desktop:

[Desktop Entry]

Actions=install
Icon=dialog-information
MimeType=application/vnd.debian.binary-package
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
X-KDE-Priority=TopLevel


[Desktop Action install]
Exec=konsole --hold -e sudo apt install %f
Icon=dialog-information
Name=Install

The file ~/.local/share/applications/install_deb_term.desktop:

[Desktop Entry]
Name=Install in terminal with apt
Comment=Install deb files in terminal with apt
Exec=konsole --hold -e sudo apt install %f
Icon=gdebi
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel;System;

All is well, excepting the fact that without the --hold argument in konsole the terminal closes to quickly (which is not good in case of error), while with that argument the terminal stays open with a rather inconclusive message like so:

 Setting up <whatever_program> ...

which is not what I expect if the installation went fine.


Can I get some "OK" message at the end of the installation process with apt? Maybe through a script containing the apt command?


Update:

Following comments by @DKBose: modifying ~/.bashrc as in this answer I get the desired notification popup with a command in terminal like

sudo apt install /path/to/deb; alert

but not with the line

Exec=konsole --hold -e sudo apt install %f; alert

in the files above (installation works, but no popup).

For the alert argument to work at all, installation of libnotify-bin was needed.

  • @DKBose - That one gives far less info. When missing dependencies it doesn't say which. Apt in terminal, like gdebi, shows a lot more info. I am trying to avoid gdebi in kde. A script should do it. I just need an ok message at the end, and even that just for the fun of it. –  Dec 11 '18 at 13:32
  • 1
    So, apt install ... && echo OK? – muru Dec 11 '18 at 13:33
  • 1
    @DKBose - When missing dependencies cannot be installed (I just tested with an Exaile package in Kubuntu 18.04) they are not specified in qapt-deb-installer. –  Dec 11 '18 at 13:39
  • @muru - with the line Exec=konsole --hold -e sudo apt install %f && echo OK I get no ok message in terminal (tested by successfully installing Opera: in that case the last line is Processing triggers for libc-bin (2.27-3ubuntu1) ....) But maybe in a script. –  Dec 11 '18 at 13:43
  • 1
    And is https://askubuntu.com/questions/748860/how-can-i-use-the-eos-terminal-notification-in-ubuntu of help? – DK Bose Dec 11 '18 at 13:59
  • 1
    And this too: https://askubuntu.com/questions/749202/modify-the-alert-alias-in-bashrc – DK Bose Dec 11 '18 at 14:03
  • @DKBose - It was exaile_3.4.5-1_all.deb (just testing, I don't want that, there are more recent versions anyway I guess), also I will try the askubuntu notification solution as soon as possible. Thanks. –  Dec 11 '18 at 14:06
  • 1
    @DKBose - modifying ~/.bashrc as in this answer I get the desired notification popup with a command in terminal like sudo apt install /path/to/deb; alert, but not with the line Exec=konsole --hold -e sudo apt install %f; alert in the files above (installation works, but no popup). I will add that to question. –  Dec 12 '18 at 12:23
  • Please see if https://askubuntu.com/questions/1106774/wake-me-up-when-a-slow-command-line-process-wants-my-attention has something of use. – DK Bose Jan 04 '19 at 03:11
  • @DKBose - the answers under there are too complicated, for me, I do not know how to adjust those scripts to my use.. I learned that echo $? can be used at the end of a command, which gives 0 for ok. But it's the same as with alert: works when typed in terminal, but not with the terminal launched from the desktop file. –  Jan 13 '19 at 17:02
  • @DKBose OP's account seems to be deleted, maybe you can post an answer and remove this from the unanswered list? – muru May 27 '20 at 09:02
  • @muru, that user is cipricus who has apparently moved to XFCE. The question here has two parts: one seems to be answered with the alert feature in ~/.bashrc but the other aspect, involving the service menu route, is still very much open according to the last comment by user47206. And I don't have an answer for that second aspect. – DK Bose May 27 '20 at 09:27
  • @DKBose that is probably just a syntax error. Exec lines aren't really parsed like shell lines, so the ; alert probably should have been konsole --hold -e bash -c 'apt install "$@"; alert' _ %f. – muru May 27 '20 at 09:46
  • @muru I tried Exec=konsole --hold -e bash -c 'sudo apt install %f; alert' _ %f with sudo added and with %f because KDE service menus use %f (obtained when a file is clicked in Dolphin). The installation is fine, but no alert, instead, the terminal shows _: alert: command not found. – DK Bose May 27 '20 at 10:54
  • @DKBose that's good, alert is an alias in bashrc, so changing bash -c to bash -ic should fix that – muru May 27 '20 at 10:58
  • @muru Okay, with Exec=konsole --hold -e bash -ic 'sudo apt install %f; alert' _ %f, installation is fine, no alert, but now the last line is No summary specified. – DK Bose May 27 '20 at 11:02

1 Answers1

2

This answer addresses the issue of installing a .deb file using apt install via a service menu in Kubuntu 18.04.

First, we download a small .deb, gcolor2 which is not in the bionic repos, using the link provided by N0rbert here.

~/Downloads $ wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcolor2/gcolor2_0.4-2.1ubuntu1_amd64.deb

Next, based on the service menu .desktop file in the question and comments by muru, the following service menu .desktop file, ~/.local/share/kservices5/ServiceMenus/install-deb.desktop was constructed:

[Desktop Entry]
Actions=install-deb
Icon=dialog-information
MimeType=application/vnd.debian.binary-package
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
X-KDE-Priority=TopLevel

[Desktop Action install-deb]
Name=install-deb
Exec=konsole --hold -e bash -ic 'sudo apt install %f && notify-send --expire-time=50000 "DONE"'

From now on, if one right-clicks on a .deb file in Dolphin, the context menu offers "install-deb" as one of the options. Selecting "install-deb" will open up konsole and run sudo apt install %f, where %f in this case, refers to the gcolor .deb downloaded via wget.

This is what konsole's output looks like:

[sudo] password for dkb: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'gcolor2' instead of '/home/dkb/Downloads/gcolor2_0.4-2.1ubuntu1_amd64.deb'
The following NEW packages will be installed:
  gcolor2
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/25.4 kB of archives.
After this operation, 112 kB of additional disk space will be used.
Get:1 /home/dkb/Downloads/gcolor2_0.4-2.1ubuntu1_amd64.deb gcolor2 amd64 0.4-2.1ubuntu1 [25.4 kB]
Selecting previously unselected package gcolor2.
(Reading database ... 257481 files and directories currently installed.)
Preparing to unpack .../gcolor2_0.4-2.1ubuntu1_amd64.deb ...
Unpacking gcolor2 (0.4-2.1ubuntu1) ...
Setting up gcolor2 (0.4-2.1ubuntu1) ...
Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for mime-support (3.60ubuntu1) ...

Once the install is complete, konsole will have "Finished" in its titlebar but will remain open until it is closed via the window manager. Additionally, because of the notify-send bit, a notification will be visible for the number of milliseconds specified. (I don't know why but --urgency=critical doesn't make the notification persist.)


kdialog --passivepopup "whatever text string" seems better suited for this purpose than notify-send.

DK Bose
  • 42,548
  • 23
  • 127
  • 221