From 91076b4873a8967af1859bb3b62b939b19cbe840 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 30 Oct 2024 18:11:18 +0100
Subject: [PATCH] Fix pulseaudio setting.

---
 many_releases/etc/raspi/greetd/config.toml        |  2 +-
 many_releases/home/raspi/.config/pulse/default.pa |  3 ---
 many_releases/home/raspi/startup.sh               | 13 +++++++++++++
 testing/scripts/setup_raspi.sh                    |  4 +++-
 4 files changed, 17 insertions(+), 5 deletions(-)
 delete mode 100644 many_releases/home/raspi/.config/pulse/default.pa
 create mode 100755 many_releases/home/raspi/startup.sh

diff --git a/many_releases/etc/raspi/greetd/config.toml b/many_releases/etc/raspi/greetd/config.toml
index 9830be6..afbef59 100644
--- a/many_releases/etc/raspi/greetd/config.toml
+++ b/many_releases/etc/raspi/greetd/config.toml
@@ -1,5 +1,5 @@
 [terminal]
 vt = 7 
 [default_session]
-command = "/usr/bin/sway"
+command = "/home/plom/startup.sh"
 user = "plom"
diff --git a/many_releases/home/raspi/.config/pulse/default.pa b/many_releases/home/raspi/.config/pulse/default.pa
deleted file mode 100644
index 0b25b91..0000000
--- a/many_releases/home/raspi/.config/pulse/default.pa
+++ /dev/null
@@ -1,3 +0,0 @@
-.include /etc/pulse/default.pa
-set-default-sink alsa_output.platform-fef05700.hdmi.hdmi-stereo
-set-sink-volume @DEFAULT_SINK@ 50%
diff --git a/many_releases/home/raspi/startup.sh b/many_releases/home/raspi/startup.sh
new file mode 100755
index 0000000..bcbba4d
--- /dev/null
+++ b/many_releases/home/raspi/startup.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/sh
+# Iinitalize anything we want in our sessions opened by greetd.
+
+# Workaround to pulseaudio daemon somehow not respecting setting these with
+# ~/.config/pulse/default.pa – note that the first pactl call also seems
+# necessary, probably for forcing some init routines without which the pacmd
+# calls that follow won't work; TODO: find cleaner solutions 
+pactl list sinks > /dev/null
+pacmd set-default-sink alsa_output.platform-fef05700.hdmi.hdmi-stereo
+pacmd set-sink-volume alsa_output.platform-fef05700.hdmi.hdmi-stereo 32768 
+
+# Wayland environment.
+/usr/bin/sway
diff --git a/testing/scripts/setup_raspi.sh b/testing/scripts/setup_raspi.sh
index a4ff538..0d21b1b 100755
--- a/testing/scripts/setup_raspi.sh
+++ b/testing/scripts/setup_raspi.sh
@@ -42,10 +42,12 @@ ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
 # so Sway won't complain about failing to access non-existant background image file
 sed -i '/^output \* bg/ s/^/#/' /etc/sway/config
 
-# Set up users and their environments.
+# Set up root environment.
 for root in "${PATH_MANY}" '..'; do
     copy_dirtree "${root}${PATH_REL_HOME}" '/root' all root
 done
+
+# Set up user and their environment.
 adduser --disabled-password --gecos "" "${USERNAME}" 
 usermod -a -G sudo "${USERNAME}" 
 for root in "${PATH_MANY}" '..'; do
-- 
2.30.2