Pipewire configuration tool updated. In a bout of pure insanity I tested this on my production system and it worked without a hitch, so should be good to go.

This commit is contained in:
Storm Dragon
2025-10-17 22:19:30 -04:00
parent af4740d5ad
commit 2f3a114790

View File

@@ -1,21 +1,61 @@
#!/bin/bash #!/bin/bash
# This script configures pipewire to work both in the graphical environment and in the console with root apps. # This script configures pipewire to work both in the graphical environment and in the console with root apps.
# Supports both legacy WirePlumber (Lua) and modern WirePlumber (0.5+ config format)
# Detect WirePlumber version
detect_wireplumber_version() {
if command -v wireplumber >/dev/null 2>&1; then
local version
version=$(wireplumber --version 2>/dev/null | grep -oP 'wireplumber \K[0-9]+\.[0-9]+' | head -n1)
if [ -n "$version" ]; then
echo "$version"
return 0
fi
fi
# Default to legacy if detection fails
echo "0.4"
return 1
}
# Compare versions (returns 0 if version1 >= version2)
version_ge() {
[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$2" ]
}
if [[ $(whoami) != "root" ]]; then if [[ $(whoami) != "root" ]]; then
# Track overall success
CONFIG_SUCCESS=true
# Get the current user's XDG_HOME # Get the current user's XDG_HOME
xdgPath="${XDG_CONFIG_HOME:-$HOME/.config}" xdgPath="${XDG_CONFIG_HOME:-$HOME/.config}"
mkdir -p "$xdgPath/pipewire" mkdir -p "$xdgPath/pipewire" || CONFIG_SUCCESS=false
mkdir -p "$xdgPath/wireplumber/main.lua.d"
mkdir -p "$xdgPath/wireplumber/bluetooth.lua.d" # Detect WirePlumber version
WP_VERSION=$(detect_wireplumber_version)
echo "Detected WirePlumber version: $WP_VERSION"
# Determine configuration format
if version_ge "$WP_VERSION" "0.5"; then
echo "Using modern WirePlumber configuration format (0.5+)"
USE_MODERN_CONFIG=true
mkdir -p "$xdgPath/wireplumber/wireplumber.conf.d"
mkdir -p "$xdgPath/wireplumber/main.conf.d"
mkdir -p "$xdgPath/wireplumber/bluetooth.conf.d"
else
echo "Using legacy WirePlumber Lua configuration format"
USE_MODERN_CONFIG=false
mkdir -p "$xdgPath/wireplumber/main.lua.d"
mkdir -p "$xdgPath/wireplumber/bluetooth.lua.d"
fi
# Create drop-in configuration for PipeWire-Pulse console access # Create drop-in configuration for PipeWire-Pulse console access
mkdir -p "$xdgPath/pipewire/pipewire-pulse.conf.d" mkdir -p "$xdgPath/pipewire/pipewire-pulse.conf.d"
# Warn user if we are going to overwrite an existing fenrir console config # Warn user if we are going to overwrite an existing fenrir console config
if [ -f "$xdgPath/pipewire/pipewire-pulse.conf.d/50-fenrir-console.conf" ]; then if [ -f "$xdgPath/pipewire/pipewire-pulse.conf.d/50-fenrir-console.conf" ]; then
read -p "This will replace the current file located at $xdgPath/pipewire/pipewire-pulse.conf.d/50-fenrir-console.conf, press enter to continue or control+c to abort. " continue read -r -p "This will replace the current file located at $xdgPath/pipewire/pipewire-pulse.conf.d/50-fenrir-console.conf, press enter to continue or control+c to abort. "
fi fi
cat << "EOF" > "$xdgPath/pipewire/pipewire-pulse.conf.d/50-fenrir-console.conf" cat << "EOF" > "$xdgPath/pipewire/pipewire-pulse.conf.d/50-fenrir-console.conf" || CONFIG_SUCCESS=false
# Fenrir console audio support # Fenrir console audio support
# Adds secondary socket for console applications like Fenrir # Adds secondary socket for console applications like Fenrir
@@ -43,11 +83,56 @@ pulse.rules = [
EOF EOF
# Create WirePlumber configuration to prevent audio device suspension on console switch # Create WirePlumber configuration to prevent audio device suspension on console switch
# Warn user if we are going to overwrite an existing 50-fenrir-no-suspend.lua if [ "$USE_MODERN_CONFIG" = true ]; then
if [ -f "$xdgPath/wireplumber/main.lua.d/50-fenrir-no-suspend.lua" ]; then # Modern WirePlumber 0.5+ configuration format
read -p "This will replace the current file located at $xdgPath/wireplumber/main.lua.d/50-fenrir-no-suspend.lua, press enter to continue or control+c to abort. " continue CONFIG_FILE="$xdgPath/wireplumber/main.conf.d/50-fenrir-no-suspend.conf"
fi if [ -f "$CONFIG_FILE" ]; then
cat << "EOF" > "$xdgPath/wireplumber/main.lua.d/50-fenrir-no-suspend.lua" read -r -p "This will replace the current file located at $CONFIG_FILE, press enter to continue or control+c to abort. "
fi
cat << "EOF" > "$CONFIG_FILE" || CONFIG_SUCCESS=false
# Fenrir console audio support
# Prevents audio device suspension when switching to TTY console
monitor.alsa.rules = [
{
matches = [
{
device.name = "~alsa_card.*"
}
]
actions = {
update-props = {
api.alsa.use-acp = true
api.acp.auto-profile = false
api.acp.auto-port = false
session.suspend-timeout-seconds = 0
}
}
}
{
matches = [
{
node.name = "~alsa_input.*"
}
{
node.name = "~alsa_output.*"
}
]
actions = {
update-props = {
session.suspend-timeout-seconds = 0
}
}
}
]
EOF
else
# Legacy Lua configuration format
CONFIG_FILE="$xdgPath/wireplumber/main.lua.d/50-fenrir-no-suspend.lua"
if [ -f "$CONFIG_FILE" ]; then
read -r -p "This will replace the current file located at $CONFIG_FILE, press enter to continue or control+c to abort. "
fi
cat << "EOF" > "$CONFIG_FILE" || CONFIG_SUCCESS=false
-- Fenrir console audio support -- Fenrir console audio support
-- Prevents audio device suspension when switching to TTY console -- Prevents audio device suspension when switching to TTY console
@@ -67,7 +152,7 @@ alsa_monitor.rules = {
}, },
{ {
matches = { matches = {
{ {
{ "node.name", "matches", "alsa_input.*" }, { "node.name", "matches", "alsa_input.*" },
}, },
{ {
@@ -80,13 +165,48 @@ alsa_monitor.rules = {
}, },
} }
EOF EOF
fi
# Create WirePlumber bluetooth configuration to prevent disconnection on TTY switch # Create WirePlumber bluetooth configuration to prevent disconnection on TTY switch
# Warn user if we are going to overwrite an existing 30-fenrir-bluez.lua if [ "$USE_MODERN_CONFIG" = true ]; then
if [ -f "$xdgPath/wireplumber/bluetooth.lua.d/30-fenrir-bluez.lua" ]; then # Modern WirePlumber 0.5+ configuration format
read -p "This will replace the current file located at $xdgPath/wireplumber/bluetooth.lua.d/30-fenrir-bluez.lua, press enter to continue or control+c to abort. " continue CONFIG_FILE="$xdgPath/wireplumber/bluetooth.conf.d/50-fenrir-bluez.conf"
fi if [ -f "$CONFIG_FILE" ]; then
cat << "EOF" > "$xdgPath/wireplumber/bluetooth.lua.d/30-fenrir-bluez.lua" read -r -p "This will replace the current file located at $CONFIG_FILE, press enter to continue or control+c to abort. "
fi
cat << "EOF" > "$CONFIG_FILE" || CONFIG_SUCCESS=false
# Fenrir console audio support
# Prevents bluetooth disconnection when switching TTY
monitor.bluez.properties = {
# Disable logind integration to prevent bluetooth device suspension on TTY switch
bluez5.enable-sbc-xq = true
bluez5.enable-msbc = true
bluez5.enable-hw-volume = true
}
monitor.bluez.rules = [
{
matches = [
{
device.name = "~bluez_card.*"
}
]
actions = {
update-props = {
session.suspend-timeout-seconds = 0
}
}
}
]
EOF
else
# Legacy Lua configuration format
CONFIG_FILE="$xdgPath/wireplumber/bluetooth.lua.d/30-fenrir-bluez.lua"
if [ -f "$CONFIG_FILE" ]; then
read -r -p "This will replace the current file located at $CONFIG_FILE, press enter to continue or control+c to abort. "
fi
cat << "EOF" > "$CONFIG_FILE" || CONFIG_SUCCESS=false
-- Fenrir console audio support -- Fenrir console audio support
-- Disables logind module to prevent bluetooth disconnection when switching TTY -- Disables logind module to prevent bluetooth disconnection when switching TTY
@@ -101,20 +221,30 @@ function bluez_monitor.enable()
}) })
end end
EOF EOF
fi
echo ""
echo "Configuration files created successfully."
if [ "$USE_MODERN_CONFIG" = true ]; then
echo "Using modern WirePlumber 0.5+ configuration format (.conf files)"
else
echo "Using legacy WirePlumber configuration format (.lua files)"
fi
echo ""
echo "Please ensure that your user is added to the audio group." echo "Please ensure that your user is added to the audio group."
echo "If you have not yet done so, please run this script as root to write the client.conf file." echo "If you have not yet done so, please run this script as root to write the client.conf file."
else else
# This section does the root part: # This section does the root part:
CONFIG_SUCCESS=true
xdgPath="/root/.config" xdgPath="/root/.config"
mkdir -p "$xdgPath/pulse" mkdir -p "$xdgPath/pulse" || CONFIG_SUCCESS=false
# Warn user if we are going to overwrite an existing client.conf # Warn user if we are going to overwrite an existing client.conf
if [ -f "$xdgPath/pulse/client.conf" ]; then if [ -f "$xdgPath/pulse/client.conf" ]; then
read -p "This will replace the current file located at $xdgPath/pulse/client.conf, press enter to continue or control+c to abort. " continue read -r -p "This will replace the current file located at $xdgPath/pulse/client.conf, press enter to continue or control+c to abort. "
fi fi
cat << "EOF" > "$xdgPath/pulse/client.conf" cat << "EOF" > "$xdgPath/pulse/client.conf" || CONFIG_SUCCESS=false
# This file is part of PulseAudio. # This file is part of PulseAudio.
# #
# PulseAudio is free software; you can redistribute it and/or modify # PulseAudio is free software; you can redistribute it and/or modify
@@ -156,9 +286,10 @@ echo "If you have not yet done so, run this script as your normal user to write
fi fi
# If there were no errors tell user to restart, else warn them errors happened. # If there were no errors tell user to restart, else warn them errors happened.
if [ $? -eq 0 ]; then if [ "$CONFIG_SUCCESS" = true ]; then
echo "Configuration created successfully, please restart both Pipewire-pulseaudio and Wireplumber or your system, for changes to take affect." echo "Configuration created successfully, please restart both Pipewire-pulseaudio and Wireplumber or your system, for changes to take affect."
exit 0
else else
echo "Errors were encountered whilst writing the configuration, please correct them manually." echo "Errors were encountered whilst writing the configuration, please correct them manually."
exit 1
fi fi
exit 0