#! /bin/bash

WaitDbusComplete()
{
    while [ true ]
    do
        DaemomPid=`ps | grep "dbus-daemon" | grep "\-\-fork" | awk -F' ' '{print $1}'`;
        Pid=`cat /app/DBus/DBUS_SESSION_BUS_PID | awk -F'\n' '{print $1}'`;
        ADDRESS=`cat /app/DBus/DBUS_SESSION_BUS_ADDRESS | awk -F'\n' '{print $1}'`;
        if [ "$Pid" == "$DaemomPid" ]; then
            export DBUS_SESSION_BUS_ADDRESS=$ADDRESS;
            export DBUS_SESSION_BUS_PID=$Pid;
            break;
        fi
    done
}

CreateDbus()
{
    export $(dbus-launch);
    echo $DBUS_SESSION_BUS_ADDRESS > "/app/DBus/DBUS_SESSION_BUS_ADDRESS";
    echo $DBUS_SESSION_BUS_PID     > "/app/DBus/DBUS_SESSION_BUS_PID";
    sync;sync;sync;
}

ExportVariable()
{
    export DBUS_SESSION_BUS_ADDRESS=$ADDRESS;
    export DBUS_SESSION_BUS_PID=$Pid;
}
