Sunday, December 31, 2023

spotifyd: add user and rc.d script

_nginx is the oldest commented user from 2012 according to my blame/grep.
I'd like to recycle the ID into _spotifyd and isolate this internet facing
daemon into /var/spotifyd/, away from /home/kn/.

Looks like this is the first case of an unprivileged user in ports playing.
sndio(7) needs a cookie file; neither PortAudio (audio/portaudio-svn), nor
Rust's portaudio-rs crate or spotifyd seem to use that, so I've added a
trivial rc_pre() one-shot hook leveraging aucat(1).

Existing users as per README won't have to do anything after upgrading
to spotifyd-0.3.5p3; ~/.spotifyd/spotifyd.conf continues to take
precedence and is NOT merged with /etc/spotifyd.conf used by rc.d/spotifyd.

Works like a charm for me.

Feedback? OK?

Index: infrastructure/db/user.list
===================================================================
RCS file: /cvs/ports/infrastructure/db/user.list,v
diff -u -p -r1.435 user.list
--- infrastructure/db/user.list 17 Dec 2023 21:25:50 -0000 1.435
+++ infrastructure/db/user.list 29 Dec 2023 23:59:22 -0000
@@ -101,7 +101,7 @@ id user group port
590 _smsd _smsd comms/smstools
591 _bacula _bacula sysutils/bacula
592 _imapproxy _imapproxy mail/imapproxy
-#593 _nginx _nginx www/nginx
+593 _spotifyd _spotifyd audio/spotifyd
#594 _ejabberd _ejabberd net/ejabberd
595 _poppassd _poppassd sysutils/openpoppassd
#596 _heartbeat _heartbeat sysutils/heartbeat
Index: audio/spotifyd/Makefile
===================================================================
RCS file: /cvs/ports/audio/spotifyd/Makefile,v
diff -u -p -r1.4 Makefile
--- audio/spotifyd/Makefile 31 Dec 2023 18:45:17 -0000 1.4
+++ audio/spotifyd/Makefile 31 Dec 2023 19:59:27 -0000
@@ -4,7 +4,7 @@ NOT_FOR_ARCHS = powerpc64 riscv6
COMMENT = Spotify client running as UNIX daemon
DIST_TUPLE = github Spotifyd spotifyd v0.3.5 .
CATEGORIES = audio net
-REVISION = 2
+REVISION = 3

MAINTAINER = Klemens Nanni <kn@openbsd.org>

@@ -31,10 +31,15 @@ MODCARGO_FEATURES = dbus_keyring \
portaudio_backend

DOC_DIR = ${PREFIX}/doc/${PKGSTEM}
+EXAMPLES_DIR = ${PREFIX}/share/examples/${PKGSTEM}
+HOME_DIR = ${LOCALSTATEDIR}/${PKGSTEM}
+SUBST_VARS = HOME_DIR

post-install:
${INSTALL_DATA_DIR} ${DOC_DIR}
${INSTALL_DATA} ${WRKSRC}/docs/src/config/File.md ${DOC_DIR}/
+ ${INSTALL_DATA_DIR} ${EXAMPLES_DIR}
+ ${SUBST_DATA} {${FILESDIR},${EXAMPLES_DIR}}/${PKGSTEM}.conf

.include "crates.inc"
.include <bsd.port.mk>
Index: audio/spotifyd/files/spotifyd.conf
===================================================================
RCS file: audio/spotifyd/files/spotifyd.conf
diff -N audio/spotifyd/files/spotifyd.conf
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ audio/spotifyd/files/spotifyd.conf 31 Dec 2023 19:58:21 -0000
@@ -0,0 +1,8 @@
+[global]
+username = "user@example.com"
+password = "secret"
+
+# TODO needs D-Bus policy to allow '_spotifyd' owning the MPRIS service
+use_mpris = false
+
+#cache_path = "${HOME_DIR}/cache"
Index: audio/spotifyd/pkg/PLIST
===================================================================
RCS file: /cvs/ports/audio/spotifyd/pkg/PLIST,v
diff -u -p -r1.2 PLIST
--- audio/spotifyd/pkg/PLIST 29 Dec 2023 22:09:21 -0000 1.2
+++ audio/spotifyd/pkg/PLIST 31 Dec 2023 20:01:49 -0000
@@ -1,5 +1,19 @@
+@newgroup _spotifyd:593
+@newuser _spotifyd:593:_spotifyd::Spotify Daemon:${HOME_DIR}:/sbin/nologin
+@rcscript ${RCDIR}/spotifyd
+@owner _spotifyd
+@group _spotifyd
+@sample ${HOME_DIR}/
+@extraunexec rm -rf ${HOME_DIR}
+@owner
+@group
@bin bin/spotifyd
doc/
doc/spotifyd/
doc/spotifyd/File.md
share/doc/pkg-readmes/${PKGSTEM}
+share/examples/spotifyd/
+share/examples/spotifyd/spotifyd.conf
+@mode 0640
+@group _spotifyd
+@sample ${SYSCONFDIR}/spotifyd.conf
Index: audio/spotifyd/pkg/README
===================================================================
RCS file: /cvs/ports/audio/spotifyd/pkg/README,v
diff -u -p -r1.1.1.1 README
--- audio/spotifyd/pkg/README 27 Dec 2023 19:47:33 -0000 1.1.1.1
+++ audio/spotifyd/pkg/README 31 Dec 2023 19:43:08 -0000
@@ -1,8 +1,9 @@
With credentials in an XDG configuration file spotifyd is ready to run, e.g.
as daemon in ~/.xsession or on-demand via clients such as "spotify-qt":

- [global]
+ [spotifyd]
username = "user@example.com"
password = "secret"

-See https://docs.spotifyd.rs/ for more information.
+Alternatively, the rc.d(8) script runs as dedicated user, but lacks D-Bus
+configuration, hence features like the MPRIS interface do not work (yet).
Index: audio/spotifyd/pkg/spotifyd.rc
===================================================================
RCS file: audio/spotifyd/pkg/spotifyd.rc
diff -N audio/spotifyd/pkg/spotifyd.rc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ audio/spotifyd/pkg/spotifyd.rc 31 Dec 2023 20:30:36 -0000
@@ -0,0 +1,16 @@
+#!/bin/ksh
+
+daemon="/usr/local/bin/spotifyd"
+daemon_user="_spotifyd"
+
+. /etc/rc.d/rc.subr
+
+rc_reload=NO
+
+rc_pre() {
+ # Create sndio(7) cookie on first run, PortAudio does not do it,
+ # otherwise spotifyd starts, but crashes when playing audio.
+ [[ -f ~/.sndio/cookie ]] || aucat -i /dev/null
+}
+
+rc_cmd $1

No comments:

Post a Comment