#!/bin/bash # ============================================================================ # DarkForge Linux — PipeWire service # ============================================================================ # PipeWire audio server + WirePlumber session manager. # NOTE: PipeWire is designed to run as a user service, not system-wide. # This script prepares the runtime directory for the auto-login user. # The actual PipeWire startup is handled in the user's shell profile # (~/.zprofile) which starts pipewire, pipewire-pulse, and wireplumber. # # The auto-login user is detected from /etc/inittab (--autologin ). # ============================================================================ # Source system configuration [ -f /etc/rc.conf ] && . /etc/rc.conf # Detect the auto-login user from inittab get_autologin_user() { local user user=$(grep -m1 -- '--autologin' /etc/inittab 2>/dev/null \ | sed 's/.*--autologin \([^ ]*\).*/\1/') echo "${user:-root}" } case "$1" in start) AUTOLOGIN_USER=$(get_autologin_user) AUTOLOGIN_UID=$(id -u "$AUTOLOGIN_USER" 2>/dev/null || echo 1000) echo " PipeWire: preparing runtime dir for ${AUTOLOGIN_USER} (uid ${AUTOLOGIN_UID})" # Ensure XDG_RUNTIME_DIR exists for the user session mkdir -p "/run/user/${AUTOLOGIN_UID}" chown "${AUTOLOGIN_USER}:${AUTOLOGIN_USER}" "/run/user/${AUTOLOGIN_UID}" chmod 700 "/run/user/${AUTOLOGIN_UID}" echo " PipeWire: ready (will start with user session on tty1)" ;; stop) echo " Stopping PipeWire..." killall pipewire wireplumber pipewire-pulse 2>/dev/null echo " PipeWire stopped" ;; restart) $0 stop sleep 1 $0 start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac