gentoo-pipewire-launcher (2707B)
1 #!/bin/sh 2 3 # PipeWire launcher script for XDG compliant desktops on OpenRC. 4 # 5 # systemd users are very _STRONGLY_ advised to use the much 6 # more reliable and predictable user units instead. 7 8 # WARNING: This script assumes being run inside XDG compliant session, 9 # which means D-Bus session instance is expected to be correctly set up 10 # prior to this script starting. If that is not true, things may break! 11 12 DATE_FORMAT='+%Y-%m-%dT%H:%M:%S%Z' 13 14 CONF="${XDG_CONFIG_HOME:-${HOME}/.config}/gentoo-pipewire-launcher.conf" 15 if [ -f "${CONF}" ] 16 then 17 . "${CONF}" 18 fi 19 20 : "${GENTOO_PIPEWIRE_LOG:=/dev/null}" 21 : "${GENTOO_PIPEWIRE_PULSE_LOG:=/dev/null}" 22 : "${GENTOO_WIREPLUMBER_LOG:=/dev/null}" 23 24 for L in \ 25 "${GENTOO_PIPEWIRE_LOG}" \ 26 "${GENTOO_PIPEWIRE_PULSE_LOG}" \ 27 "${GENTOO_WIREPLUMBER_LOG}" 28 do 29 if [ ! -e "${L}" ] 30 then 31 touch "${L}" 32 fi 33 done 34 35 restart () { 36 echo "Terminating PipeWire processes ..." 37 pkill -u "${USER}" -x pipewire\|wireplumber 1>/dev/null 2>&1 38 39 # pidwait was renamed to pwait w/ procps-4 (bug #914030) 40 if command -v pidwait > /dev/null ; then 41 pidwait -u "${USER}" -x pipewire\|wireplumber 42 elif command -v pwait > /dev/null ; then 43 pwait -u "${USER}" -x pipewire\|wireplumber 44 fi 45 46 echo "PipeWire terminated." 47 } 48 49 if [ "${#}" -gt 0 ] 50 then 51 if [ "${1}" = 'restart' ] 52 then 53 restart 54 else 55 echo "Unrecognised argument." >&2 56 echo "Usage: gentoo-pipewire-launcher [restart]" >&2 57 exit 1 58 fi 59 fi 60 61 if pgrep -u "${USER}" -x pipewire\|wireplumber 1>/dev/null 2>&1 62 then 63 echo "PipeWire already running, exiting." >&2 64 echo "(Use 'gentoo-pipewire-launcher restart' to restart PipeWire and WirePlumber.)" >&2 65 exit 1 66 fi 67 68 # The core daemon which by itself does probably nothing. 69 echo "[$(/bin/date ${DATE_FORMAT})] Starting PipeWire." 1>>"${GENTOO_PIPEWIRE_LOG}" 70 /usr/bin/pipewire 1>>"${GENTOO_PIPEWIRE_LOG}" 2>&1 & 71 72 # The so called pipewire-pulse daemon used for PulseAudio compatibility. 73 # Commenting this out will stop the PA proxying daemon from starting, 74 # however ALSA (with pipewire-alsa), JACK (with jack-sdk) and PW API using 75 # clients will still have access to audio and may end up clashing with 76 # non-PW apps over HW control (most notably, /usr/bin/pulseaudio daemon). 77 echo "[$(/bin/date ${DATE_FORMAT})] Starting PipeWire-Pulse." 1>>"${GENTOO_PIPEWIRE_PULSE_LOG}" 78 /usr/bin/pipewire -c pipewire-pulse.conf 1>>"${GENTOO_PIPEWIRE_PULSE_LOG}" 2>&1 & 79 80 # Hack for bug #822498 81 sleep 1 82 83 # Finally a session manager is required for PipeWire to do anything. 84 echo "[$(/bin/date ${DATE_FORMAT})] Starting WirePlumber." 1>>"${GENTOO_WIREPLUMBER_LOG}" 85 exec /usr/bin/wireplumber 1>>"${GENTOO_WIREPLUMBER_LOG}" 2>&1