#!/bin/sh
ME=$(whoami)
TIMEOUT=200
source /opt/bin/getuidgidno "${ME}"
# /opt/bin/pwo

[ -d "/tmp/pipeware-${ME}" ] || mkdir "/tmp/pipeware-${ME}"

PIDFILE="/run/user/$UIDNO/pipewire-master.pid"
LOG="/tmp/pipeware-${ME}/master.log"
[ -f "${LOG}" ] && rm "${LOG}"
start-stop-daemon --start --exec /usr/bin/pipewire --background --make-pidfile --pidfile "${PIDFILE}" --stdout "${LOG}" --stderr "${LOG}" --wait "${TIMEOUT}"

PIDFILE="/run/user/$UIDNO/pipewire-wireplumber.pid"
LOG="/tmp/pipeware-${ME}/wireplumber.log"
[ -f "${LOG}" ] && rm "${LOG}"
start-stop-daemon --start --exec /usr/bin/wireplumber --env GIO_USE_VFS=local --background --make-pidfile --pidfile "${PIDFILE}" --stdout "${LOG}" --stderr "${LOG}" --wait "${TIMEOUT}"

PIDFILE="/run/user/$UIDNO/pipewire-filter.pid"
LOG="/tmp/pipeware-${ME}/wirefilter.log"
[ -f "${LOG}" ] && rm "${LOG}"
start-stop-daemon --start --exec /usr/bin/pipewire --background --make-pidfile --pidfile "${PIDFILE}" --stdout "${LOG}" --stderr "${LOG}" --wait "${TIMEOUT}" -- -c filter-chain.conf

PIDFILE="/run/user/$UIDNO/pipewire-pulse.pid"
LOG="/tmp/pipeware-${ME}/pulse.log"
[ -f "${LOG}" ] && rm "${LOG}"
start-stop-daemon --start --exec /usr/bin/pipewire-pulse --background --make-pidfile --pidfile "${PIDFILE}" --stdout "${LOG}" --stderr "${LOG}" --wait "${TIMEOUT}"
