mpd: run mpd as a non-root user 15299/head
authorAlexander Egorenkov <egorenar-dev@posteo.net>
Mon, 29 Mar 2021 06:06:10 +0000 (08:06 +0200)
committerAlexander Egorenkov <egorenar-dev@posteo.net>
Mon, 29 Mar 2021 07:16:13 +0000 (09:16 +0200)
* Make /etc/mpd.conf worldreadable.

Signed-off-by: Alexander Egorenkov <egorenar-dev@posteo.net>
sound/mpd/Makefile
sound/mpd/files/mpd.init

index f8fd18cb5a624a41b399ecd9e417ccdd53469602..8a7af1368553fedde5904242a6c40789290e5fd4 100644 (file)
@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=mpd
 PKG_VERSION:=0.22.6
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 PKG_SOURCE_URL:=https://www.musicpd.org/download/mpd/0.22/
@@ -35,6 +35,7 @@ define Package/mpd/Default
   URL:=https://www.musicpd.org/
   DEPENDS:= +zlib +libcurl +libpthread +libmpdclient +boost $(ICONV_DEPENDS) \
             +AUDIO_SUPPORT:alsa-lib +libexpat +libflac +libid3tag +libfaad2 +libopus
+  USERID:=mpd:mpd
 endef
 
 define Package/mpd/Default/description
@@ -220,7 +221,7 @@ define Package/mpd/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/mpd $(1)/usr/bin/
        $(INSTALL_DIR) $(1)/etc
-       $(INSTALL_CONF) $(PKG_BUILD_DIR)/doc/mpdconf.example $(1)/etc/mpd.conf
+       $(INSTALL_DATA) $(PKG_BUILD_DIR)/doc/mpdconf.example $(1)/etc/mpd.conf
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/mpd.init $(1)/etc/init.d/mpd
 endef
index 9ec164db7e4a0a57c7505959f5f73ba381df07f2..f89049d6cc5570b42ab986e29e9f26a12b1baa4e 100644 (file)
@@ -9,6 +9,9 @@ PROG=/usr/bin/mpd
 CONFIGFILE=/etc/mpd.conf
 NICEPRIO=-10
 
+USER="mpd"
+GROUP="mpd"
+
 #TODO: Add uci config - nice, config
 
 start_service() {
@@ -16,7 +19,10 @@ start_service() {
 
        #create mpd directories from config
        pld=$(grep ^playlist_directory "$CONFIGFILE" | cut -d "\"" -f 2 | sed "s/~/\/root/g")
-       [ -d "$pld" ] || mkdir -m 0755 -p "$pld"
+       if [ ! -d "$pld" ]; then
+               mkdir -m 0755 -p "$pld"
+               chown $USER:$GROUP $pld
+       fi
 
        lport=$(grep ^port "$CONFIGFILE" | cut -d "\"" -f 2)
        [ -z "$lport" ] && lport=6600
@@ -24,6 +30,8 @@ start_service() {
        procd_open_instance
        procd_add_mdns "mpd" "tcp" "$lport"
        procd_set_param command "$PROG" --no-daemon "$CONFIGFILE"
+       procd_set_param user "$USER"
+       procd_set_param group "$GROUP"
        procd_set_param stderr 1
        # Give MPD some real-time priority
        procd_set_param nice "$NICEPRIO"