46 lines
1.1 KiB
Plaintext
46 lines
1.1 KiB
Plaintext
|
#! @bash@/bin/bash
|
||
|
# shellcheck disable=SC2239
|
||
|
# SPDX-FileCopyrightText: 2020 Maxim Baz <git@maximbaz.com>
|
||
|
# SPDX-FileCopyrightText: 2023 Matthew Monaco <matt@monaco.cx>
|
||
|
# SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
||
|
#
|
||
|
# SPDX-License-Identifier: ISC
|
||
|
|
||
|
set -euo pipefail
|
||
|
|
||
|
socket="${XDG_RUNTIME_DIR:-/run/user/$UID}/yubikey-touch-detector.socket"
|
||
|
|
||
|
while true; do
|
||
|
touch_reasons=()
|
||
|
|
||
|
if [ ! -e "$socket" ]; then
|
||
|
printf '{"text": "Waiting for socket"}\n'
|
||
|
while [ ! -e "$socket" ]; do sleep 1; done
|
||
|
fi
|
||
|
printf '{"text": ""}\n'
|
||
|
|
||
|
while read -r -n5 cmd; do
|
||
|
reason="${cmd:0:3}"
|
||
|
|
||
|
if [ "${cmd:4:1}" = "1" ]; then
|
||
|
touch_reasons+=("$reason")
|
||
|
else
|
||
|
for i in "${!touch_reasons[@]}"; do
|
||
|
if [ "${touch_reasons[i]}" = "$reason" ]; then
|
||
|
unset 'touch_reasons[i]'
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
fi
|
||
|
|
||
|
if [ "${#touch_reasons[@]}" -eq 0 ]; then
|
||
|
printf '{"text": ""}\n'
|
||
|
else
|
||
|
tooltip="Security key is waiting for a touch, reasons: ${touch_reasons[*]}"
|
||
|
printf '{"text": "", "tooltip": "%s"}\n' "$tooltip"
|
||
|
fi
|
||
|
done < <(@netcat@/bin/nc -U "$socket")
|
||
|
|
||
|
sleep 1
|
||
|
done
|