Ubuntu Pastebin

Paste from laney at Tue, 22 Aug 2017 12:09:07 +0000

Download as text
 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh

set -e

FGCONSOLE=$(fgconsole)

strip_quotes() {
        i="$1"
        i=${i%\"}
        i=${i#\"}
        echo "${i}"
}

get_property() {
        session="$1"
        property="$2"
        # the output is "type value" - we only support single outputs here, not
        # arrays or anything
        val=$(busctl --no-pager \
                     --no-legend \
                     --system \
                     get-property \
                        org.freedesktop.login1 \
                        "${session}" \
                        org.freedesktop.login1.Session \
                        "${property}" 2>/dev/null | cut -d" " -f 2 || true)
        strip_quotes "${val}"
}

if [ -x /usr/bin/busctl ]; then
        SESSIONS=$(busctl --no-pager \
                          --no-legend \
                          --system \
                          call \
                                org.freedesktop.login1 \
                                /org/freedesktop/login1 \
                                org.freedesktop.login1.Manager \
                                ListSessions 2>/dev/null || true)
        if [ -n "${SESSIONS}" ]; then
                # return type, number of sessions, rest (actual session information)
                echo "${SESSIONS}" | while read -r _ n r; do
                        for i in $(seq 1 "${n}"); do
                                read -r _ _ _ _ session rest <<EOT
                                        $(echo "${r}")
EOT
                                session=$(strip_quotes "${session}")
                                VT=$(get_property "${session}" VTNr)
                                if [ -n "${VT}" ] && [ "${VT}" -eq "${FGCONSOLE}" ]; then
                                        type=$(get_property "${session}" Type)
                                        if [ "${type}" = "tty" ]; then
                                                echo "would restart"
                                        fi

                                fi
                                r="${rest}"
                        done
                done
        fi
fi
Download as text