fix shitty bugs, fuck shell script they piss me off

This commit is contained in:
William Bell
2026-01-02 16:44:27 +00:00
parent eb2e6ee917
commit 5f4727aae3
4 changed files with 48 additions and 12 deletions

12
delete_stupid_loopback.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# List all loaded modules
pactl list short modules | while read -r id name rest; do
# If module is a loopback, unload it
if [[ "$name" == "module-loopback" ]]; then
echo "Unloading loopback module $id"
pactl unload-module "$id"
fi
done
echo "All loopback modules removed."

28
play.sh
View File

@@ -1,16 +1,23 @@
#!/usr/bin/env bash
set -e
FILE="$1"
[[ -f "$FILE" ]] || { echo "Usage: $0 <file>"; exit 1; }
STATE="$HOME/.soundboard"
mkdir -p "$STATE"
# Check if the soundboard is started
if [[ ! -f "$STATE/remap.id" ]]; then
echo "Soundboard not started"
exit 1
fi
FILE="$1"
if [[ -z "$FILE" || ! -f "$FILE" ]]; then
echo "Usage: $0 <audio-file>"
exit 1
fi
DEFAULT_SINK=$(pactl get-default-sink)
# Start paplay processes in foreground
# Store PIDs so we can clean up
paplay --device=soundboard_sink "$FILE" &
PID_MIC=$!
@@ -20,11 +27,14 @@ PID_OUT=$!
# Trap signals to stop both outputs if script is killed
trap "kill $PID_MIC $PID_OUT 2>/dev/null" EXIT INT TERM
# Register this process in PID file for stop_all.sh
echo $$ >> "$STATE/playing.pids"
# Register paplay PIDs for stop_all.sh
mkdir -p "$STATE"
echo "$PID_MIC" >> "$STATE/playing.pids"
echo "$PID_OUT" >> "$STATE/playing.pids"
# Wait for both streams to finish
wait $PID_MIC $PID_OUT
# Remove from PID file when done
sed -i "\|^$$\$|d" "$STATE/playing.pids"
# Remove these PIDs from PID file when done
sed -i "\|^$PID_MIC\$|d" "$STATE/playing.pids"
sed -i "\|^$PID_OUT\$|d" "$STATE/playing.pids"

View File

@@ -4,10 +4,14 @@ STATE="$HOME/.soundboard"
[[ -f "$STATE/playing.pids" ]] || exit 0
while read -r PGID; do
kill -TERM -- "-$PGID" 2>/dev/null || true
while read -r PID; do
# Check if process exists before sending SIGINT
if [[ -n "$PID" ]] && kill -0 "$PID" 2>/dev/null; then
kill -INT "$PID" 2>/dev/null || true
fi
done < "$STATE/playing.pids"
# Clear the PID file after attempting to stop everything
rm -f "$STATE/playing.pids"
echo "All soundboard playback stopped."
echo "All soundboard playback stopped."

View File

@@ -2,6 +2,16 @@
STATE="$HOME/.soundboard"
# 1. Stop all currently playing soundboard audio
./stop_all.sh
# 2. Restore default mic BEFORE unloading modules
DEFAULT_MIC=$(pactl info | grep "Default Source" | awk '{print $3}')
if [[ -n "$DEFAULT_MIC" ]]; then
pactl set-default-source "$DEFAULT_MIC"
fi
# 3. Unload all soundboard modules safely
for f in "$STATE"/*.id; do
pactl unload-module "$(cat "$f")" 2>/dev/null || true
rm -f "$f"