#!/bin/sh
# Puts the user who started it through pkexec into group "input", so Dictate
# can read the hotkey from /dev/input on Wayland. Started by Dictate on its
# first run (after asking), never by itself. Takes no arguments: the user is
# the one polkit authenticated (PKEXEC_UID), nobody else can be added.
set -e
if [ -z "$PKEXEC_UID" ] || [ "$PKEXEC_UID" = 0 ]; then
    echo "dictate-input-group: run it as a normal user through pkexec" >&2
    exit 1
fi
user=$(getent passwd "$PKEXEC_UID" | cut -d: -f1)
[ -n "$user" ] || exit 1
getent group input >/dev/null || groupadd --system input
usermod -a -G input "$user"
echo "added $user to group input; log out and back in"
