Selaa lähdekoodia

Merge remote-tracking branch 'origin/pr/199'

* origin/pr/199:
  qubes.GetAppmenus: handle home directory properly in case of sudo
  Silence shellcheck
  GetAppmenus: ensure right app directories
Marek Marczykowski-Górecki 4 vuotta sitten
vanhempi
commit
cc68f165bc
1 muutettua tiedostoa jossa 17 lisäystä ja 1 poistoa
  1. 17 1
      qubes-rpc/qubes.GetAppmenus

+ 17 - 1
qubes-rpc/qubes.GetAppmenus

@@ -6,8 +6,24 @@
 #  - directories stored on /rw in case of "rw-only" persistence
 #  - nothing, otherwise
 
+# 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
+        # shellcheck disable=SC1090
+        . "$i" >/dev/null
+    fi
+done
+
 if [ -z "$XDG_DATA_HOME" ]; then
-    XDG_DATA_HOME="$HOME/.local/share"
+    user="$(whoami)"
+    # In case we are running under sudo, use default-user.
+    if [ "$user" = "root" ]; then
+        user="$(qubesdb-read /default-user || echo user)"
+    fi
+    home="$(eval echo "~$user")"
+    XDG_DATA_HOME="$home/.local/share"
 fi
 if [ -z "$XDG_DATA_DIRS" ]; then
     XDG_DATA_DIRS="/usr/local/share/:/usr/share/"