appmenus: send only persistent appmenus entries, use $XDG_DATA_*
It may be useful to create AppVM-specific menu entries in AppVM itself.
It may be an application installed there (in /usr/local, or using snap
QubesOS/qubes-issues#2766), but it may be also some user custom
shortcut.
To support this, dom0 will accept menu entries also from
TemplateBasedVMs. But to avoid duplicates, qubes.GetAppmenus service
should send only menu entries actually stored in that VM, not inherited
from its template. To distingush them, first check what type of
persistence this VM has (from qubesdb-read /qubes-vm-persistence). If
it's rw-only, send only entries stored on /rw.
To make it more robust, use $XDG_DATA_DIRS and $XDG_DATA_HOME to
discover directories, instead of looking only for
/usr/{,local/}share/applications. This makes snap and flatpak handled
for free.
Fixes QubesOS/qubes-issues#4152
2018-09-29 11:36:44 +02:00
|
|
|
#!/bin/bash
|
2017-09-30 04:45:31 +02:00
|
|
|
# shellcheck disable=SC2016
|
appmenus: send only persistent appmenus entries, use $XDG_DATA_*
It may be useful to create AppVM-specific menu entries in AppVM itself.
It may be an application installed there (in /usr/local, or using snap
QubesOS/qubes-issues#2766), but it may be also some user custom
shortcut.
To support this, dom0 will accept menu entries also from
TemplateBasedVMs. But to avoid duplicates, qubes.GetAppmenus service
should send only menu entries actually stored in that VM, not inherited
from its template. To distingush them, first check what type of
persistence this VM has (from qubesdb-read /qubes-vm-persistence). If
it's rw-only, send only entries stored on /rw.
To make it more robust, use $XDG_DATA_DIRS and $XDG_DATA_HOME to
discover directories, instead of looking only for
/usr/{,local/}share/applications. This makes snap and flatpak handled
for free.
Fixes QubesOS/qubes-issues#4152
2018-09-29 11:36:44 +02:00
|
|
|
|
|
|
|
# send .desktop files from directories persisting across VM restarts, specifically:
|
|
|
|
# - any directory in case of "full" persistence
|
|
|
|
# - directories stored on /rw in case of "rw-only" persistence
|
|
|
|
# - nothing, otherwise
|
|
|
|
|
2020-01-07 15:45:05 +01:00
|
|
|
# Reload scripts in /etc/profile.d/, in case they register additional
|
|
|
|
# directories in XDG_DATA_DIRS and we forgot them
|
|
|
|
# (e.g. because we are running under sudo).
|
|
|
|
for i in /etc/profile.d/*.sh ; do
|
|
|
|
if [ -r "$i" ]; then
|
|
|
|
. "$i" >/dev/null
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
appmenus: send only persistent appmenus entries, use $XDG_DATA_*
It may be useful to create AppVM-specific menu entries in AppVM itself.
It may be an application installed there (in /usr/local, or using snap
QubesOS/qubes-issues#2766), but it may be also some user custom
shortcut.
To support this, dom0 will accept menu entries also from
TemplateBasedVMs. But to avoid duplicates, qubes.GetAppmenus service
should send only menu entries actually stored in that VM, not inherited
from its template. To distingush them, first check what type of
persistence this VM has (from qubesdb-read /qubes-vm-persistence). If
it's rw-only, send only entries stored on /rw.
To make it more robust, use $XDG_DATA_DIRS and $XDG_DATA_HOME to
discover directories, instead of looking only for
/usr/{,local/}share/applications. This makes snap and flatpak handled
for free.
Fixes QubesOS/qubes-issues#4152
2018-09-29 11:36:44 +02:00
|
|
|
if [ -z "$XDG_DATA_HOME" ]; then
|
|
|
|
XDG_DATA_HOME="$HOME/.local/share"
|
|
|
|
fi
|
|
|
|
if [ -z "$XDG_DATA_DIRS" ]; then
|
|
|
|
XDG_DATA_DIRS="/usr/local/share/:/usr/share/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# if read fails for some reason, default to full
|
|
|
|
persistence=$(qubesdb-read /qubes-vm-persistence || echo full)
|
|
|
|
rw_devno=$(stat -c %D /rw)
|
|
|
|
|
|
|
|
apps_dirs_to_consider=( "$XDG_DATA_HOME" )
|
|
|
|
old_IFS="$IFS"
|
|
|
|
IFS=:
|
|
|
|
# shellcheck disable=SC2206
|
|
|
|
apps_dirs_to_consider+=( $XDG_DATA_DIRS )
|
|
|
|
IFS="$old_IFS"
|
|
|
|
|
|
|
|
apps_dirs=()
|
|
|
|
for dir in "${apps_dirs_to_consider[@]}"; do
|
|
|
|
if [ "$persistence" = "full" ]; then
|
|
|
|
apps_dirs+=( "$dir/applications" )
|
|
|
|
elif [ "$persistence" = "rw-only" ] && \
|
|
|
|
[ "$(stat -c %D "$dir")" = "$rw_devno" ]; then
|
|
|
|
apps_dirs+=( "$dir/applications" )
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "${#apps_dirs[@]}" -eq "0" ]; then
|
|
|
|
# nothing to send, exit early to not let `find` browse the current
|
|
|
|
# directory
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
find "${apps_dirs[@]}" -name '*.desktop' -print0 2>/dev/null | \
|
2016-01-19 06:02:30 +01:00
|
|
|
xargs -0 awk '
|
2015-11-03 00:48:26 +01:00
|
|
|
BEGINFILE { entry="" }
|
|
|
|
/^\[/ { if (tolower($0) != "\[desktop entry\]") nextfile }
|
|
|
|
/^Exec=/ { entry = entry FILENAME ":Exec=qubes-desktop-run " FILENAME "\n"; next }
|
|
|
|
/^NoDisplay *= *true$/ { entry=""; nextfile }
|
|
|
|
/=/ { entry = entry FILENAME ":" $0 "\n" }
|
|
|
|
ENDFILE { print entry }
|
|
|
|
' 2> /dev/null
|