#!/bin/sh
# Copyright(C) 2010 Ying-Chun Liu(PaulLiu). All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
#
# Please run this script by using "source ./attach-dbus-session.sh"
# Search some process to get DBUS_SESSION_BUS_ADDRESS
targetProcess=( unity8 compiz )
# GET PID
for index in ${targetProcess[@]}; do
PID=$(pidof -s ${index})
if [ x"${PID}" != x"" ]; then
break
fi
done
if [ x"${PID}" == x"" ]; then
echo "No process found to get DBUS_SESSION_BUS_ADDRESS"
return 1
fi
QUERY="$(cat /proc/${PID}/environ | tr '\0' '\n' | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [ x"${QUERY}" != x"" ]; then
export DBUS_SESSION_BUS_ADDRESS="${QUERY}"
echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
else
echo "Cannot find DBUS_SESSION_BUS_ADDRESS in process pid=${PID}."
return 1
fi
return 0