summaryrefslogtreecommitdiff
path: root/dot/local/bin/dbus-autolaunch
blob: 6cc8653556e9acb39e968df015344f94e9bd3116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
DOUBLE_CHECK=y
SESSION_FILE=$HOME/.dbus/default_session

if [ "$*" ]; then
    eval "$("$0")"
    "$@"
    exit
fi

dbus_available()
{
  dbus-send \
    --session \
    --dest=org.freedesktop.DBus \
    --type=method_call \
    /org/freedesktop/DBus \
    org.freedesktop.DBus.ListNames >/dev/null 2>&1
}

dbus_available && exit

if [ -r "$SESSION_FILE" ]; then

  . "$SESSION_FILE"

  if dbus_available; then
    cat "$SESSION_FILE"
    exit
  fi

fi

mkdir -p "$HOME"/.dbus
dbus-launch --sh-syntax > "$SESSION_FILE".$$ || exit
mv "$SESSION_FILE".$$ "$SESSION_FILE" || exit

if [ "$DOUBLE_CHECK" ]; then

  . "$SESSION_FILE"
  dbus_available || exit

fi

cat "$SESSION_FILE"