#!/bin/sh
# Migration for existing installs: add every regular (human) user to the
# `pipewire` group. Membership is what grants libpipewire-module-rt its
# RT scheduling rights via /etc/security/limits.d/25-pw-rlimits.conf; without
# it the PipeWire data-loop runs SCHED_OTHER and audio underruns/skips.
#
# New users get this from the useradd-post.d hook; this service covers users
# created before that change landed. Idempotent and safe to run every boot.

getent group pipewire >/dev/null 2>&1 || exit 0

getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 { print $1 }' | while read -r user; do
	id -nG "$user" 2>/dev/null | tr ' ' '\n' | grep -qx pipewire && continue
	gpasswd -a "$user" pipewire >/dev/null 2>&1
done
