#!/bin/sh
# EasySDR: make the user who asked (through pkexec, with an administrator's password) the station
# owner, then restart the service so it admits them. The owner is taken from PKEXEC_UID, never from
# an argument, so nobody can name someone else.
set -eu
[ -n "${PKEXEC_UID:-}" ] || { echo "run this through pkexec" >&2; exit 1; }
user=$(getent passwd "$PKEXEC_UID" | cut -d: -f1)
[ -n "$user" ] && [ "$user" != root ] || { echo "no such user" >&2; exit 1; }
mkdir -p /etc/easysdr
printf '%s\n' "$user" > /etc/easysdr/owner
chmod 0644 /etc/easysdr/owner
systemctl restart easysdr.service
