From 17c6be78d6122f102481a49764449929f4920bcb Mon Sep 17 00:00:00 2001 From: fiftydinar <65243233+fiftydinar@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:49:01 +0200 Subject: [PATCH] chore(default-flatpaks): Improve detection of username & UID for rootful `notify-send` --- .../default-flatpaks/v1/system-flatpak-setup | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/default-flatpaks/v1/system-flatpak-setup b/modules/default-flatpaks/v1/system-flatpak-setup index e96210e..e43c4b3 100755 --- a/modules/default-flatpaks/v1/system-flatpak-setup +++ b/modules/default-flatpaks/v1/system-flatpak-setup @@ -154,32 +154,32 @@ COMBINED_INSTALL_LIST=$(cat <(echo "$MAINTAINER_INSTALL_LIST") "$USER_INSTALL_LI COMBINED_REMOVE_LIST=$(cat <(echo "$MAINTAINER_REMOVE_LIST") "$USER_REMOVE_LIST_FILE" | grep -v -E '^#|^$' | awk '!seen[$0]++') function notify-send-pre-install { - user_name=$(loginctl list-sessions --output=json | jq -r '.[].user') - uid=$(loginctl list-sessions --output=json | jq -r '.[].uid') + user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user') + uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid') xdg_runtime_path="/run/user/$uid" display_var=$(printenv DISPLAY) sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Started install of system flatpaks" --app-name="Flatpak Installer" -u NORMAL } function notify-send-install { - user_name=$(loginctl list-sessions --output=json | jq -r '.[].user') - uid=$(loginctl list-sessions --output=json | jq -r '.[].uid') + user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user') + uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid') xdg_runtime_path="/run/user/$uid" display_var=$(printenv DISPLAY) sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Finished install of system flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL } function notify-send-pre-uninstall { - user_name=$(loginctl list-sessions --output=json | jq -r '.[].user') - uid=$(loginctl list-sessions --output=json | jq -r '.[].uid') - xdg_runtime_path="/run/user/$uid" - display_var=$(printenv DISPLAY) - sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Started uninstall of some system flatpaks" --app-name="Flatpak Installer" -u NORMAL + user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user') + uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid') + xdg_runtime_path="/run/user/$uid" + display_var=$(printenv DISPLAY) + sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Started uninstall of some system flatpaks" --app-name="Flatpak Installer" -u NORMAL } function notify-send-uninstall { - user_name=$(loginctl list-sessions --output=json | jq -r '.[].user') - uid=$(loginctl list-sessions --output=json | jq -r '.[].uid') + user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user') + uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid') xdg_runtime_path="/run/user/$uid" display_var=$(printenv DISPLAY) sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Finished uninstall of system flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL