summaryrefslogtreecommitdiffstats
path: root/core/modules/hardware-stats/data/etc/X11/Xsetup.d/99-detect-screens
blob: a1c771e0b62fc81048499592d144010feb1fd87a (plain) (blame)
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
#!/bin/sh
# XXX: This file is actually sourced, so the shebang above doesn't do anything.
# Thus we explicitly call bash below to get our echo -e -n support

(
bash <<"HEREDOC"

    mkdir -p "/run/openslx"
    [ -f "/run/openslx/screen-report-done" ] && exit 0
    touch "/run/openslx/screen-report-done"

    . /opt/openslx/config
    [ -z "$SLX_REMOTE_LOG" ] && exit 0
    UUID=$( cat /etc/system-uuid )
    [ -z "$UUID" ] && exit 0
    XRANDR=$( mktemp )
    TMP=$( mktemp )
    TF=$( mktemp )
    xrandr --verbose > "$XRANDR"

    OUTPUTNAMES=$( < "$XRANDR"  grep -E "[[:digit:]]+mm x [[:digit:]]+mm" | awk '{print $1}' )

    declare -a POSTDATA
    for output in ${OUTPUTNAMES}; do
        < "$XRANDR"  grep -Pzo "\n${output}\N*connected\N*\n(\s+\N*\n)+" > "$TMP"
        echo -e -n "$( < "$TMP"  grep -Eao '[0-9a-f]{32}' | sed -r ':a;N;$!ba;s/[^0-9a-f]//gI;s/([0-9a-f]{2})/\\x\1/gI' )" > "$TF"
        MODEL_NAME=$( < "$TF"  parse-edid | grep -m 1 -E '^\s*ModelName' | sed -r 's/^[^"]*"(.*)"[^"]*$/\1/;s/^\s+//;s/\s+$//' )
        NATIVE_RES=$( < "$TMP"  grep -Fa ' +preferred' | awk '{print $1}' )
        POSTDATA+=( "-dscreen[${output}][name]=${MODEL_NAME}" "-dscreen[${output}][resolution]=${NATIVE_RES}" )
    done

    rm -f -- "$TF" "$XRANDR" "$TMP"
    # Note, the report is sent only on the first X startup, and we actually use the event server-side
    # to determine when we reach the graphical login screen for simple performance measurements, so
    # keep that in mind if you ever fiddle around here.
    curl -m 4 -sS --data "uuid=$UUID" --data "type=~screens" "${POSTDATA[@]}" "$SLX_REMOTE_LOG"

HEREDOC
) &

true