לאחר ששידרגתי את systemd ו plasma גיליתי שצורת משתנה הסביבה DBUS_SESSION_BUS_ADDRESS השתנתה, וחלק מהתסריטים שלי כבר לא יכולים לשלוח התראות לסביבה הגרפית.
בעבר המשתנה היה פשוט :
אבל עכשיו הוא קיבל פורמט אחר :
הפתרון הנוכחי שלי הוא לנסות לגלות את משתנה הסביבה מ plasma :
לא מצאתי איפה הפורמט הזה מוגדר ברמת המערכת ומדוע הוא השתנה מהמבנה , אז אני פשוט לוקח אותו ממשתני הסביבה של הממשק הגרפי אליו אנו מחוברים.
השימוש בתוך אחד מהתסריטים שלי נראה כך :
בעבר המשתנה היה פשוט :
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
אבל עכשיו הוא קיבל פורמט אחר :
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-RANDOM,guid=UUID
הפתרון הנוכחי שלי הוא לנסות לגלות את משתנה הסביבה מ plasma :
eval $(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u username plasma_session)/environ )
לא מצאתי איפה הפורמט הזה מוגדר ברמת המערכת ומדוע הוא השתנה מהמבנה , אז אני פשוט לוקח אותו ממשתני הסביבה של הממשק הגרפי אליו אנו מחוברים.
השימוש בתוך אחד מהתסריטים שלי נראה כך :
#Send on screen notification when doorbell notification had arrived
#Copyright (c) 2017 Boris Shtrasman
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
function notify_all_users()
{
users=($(who | sed -nr "s/([a-z]*)[ \t]*.*\((:[^)]+)\).*/\1,\2/p" | sort|uniq))
summery=$1
text=$2
for i in "${users[@]}"
do
user=$(echo $i | cut -d',' -f1)
[ "root" == $user ] && continue
screen=$(echo $i|cut -d',' -f2)
id=$(id -u $user)
#begin with a pre systemd 245 value
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$id/bus
#get dbus for plasma
[[ ! -z "ps aux | grep plasma_session|grep -vvv grep" ]] && eval $(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u user plasma_session)/environ )
#get dbys for gnome sessions
[[ ! -z "ps aux | grep gnome_session|grep -vvv grep" ]] && eval $(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u user gnome_session)/environ )
#send an alert for each user that a door bell had been activated ,
screen -Dm sudo -u $user /bin/bash -c "DISPLAY=$screen DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS /usr/bin/notify-send -t 15000 -i /usr/share/home/doorbell.png -u critical \"$summery\" \"$text\""
done
}
אין תגובות:
הוסף רשומת תגובה