diff --git a/dist-scripts/debian/gmrender-resurrect-pre.service b/dist-scripts/debian/gmrender-resurrect-pre.service new file mode 100644 index 0000000..3ac9f9b --- /dev/null +++ b/dist-scripts/debian/gmrender-resurrect-pre.service @@ -0,0 +1,13 @@ +[Unit] +Description=gmrender-resurrect-pre service +Before=gmrender-resurrect.service + +[Service] +Type=oneshot +User=pi +Group=audio + +ExecStart=/bin/sh -c "touch /tmp/gmrender-resurrect.vars" + +[Install] +WantedBy=multi-user.target diff --git a/dist-scripts/debian/gmrender-resurrect.default b/dist-scripts/debian/gmrender-resurrect.default index a0b7a6c..253d4b6 100755 --- a/dist-scripts/debian/gmrender-resurrect.default +++ b/dist-scripts/debian/gmrender-resurrect.default @@ -13,7 +13,7 @@ DAEMON_USER="nobody:audio" # controller UI. Some string that helps you recognize the player, e.g. # "Livingroom Player" # Default is the short hostname of this device -UPNP_DEVICE_NAME=`hostname -s` +UPNP_DEVICE_NAME="$HOSTNAME" # Initial volume in decibel. 0.0 is 'full volume', -10 correspondents to # '75' on the exported volume scale (Note, this does not change the ALSA @@ -25,10 +25,21 @@ INITIAL_VOLUME_DB=-10 # 'aplay -L'), then gmediarenderer will use that ALSA device to play # audio. Otherwise, whatever default is configured for gstreamer for the # '$DAEMON_USER' is used. -ALSA_DEVICE="sysdefault" +RET=`dpkg -l pulseaudio` +if [ $? -eq 0 ] ; then + PULSEAUDIO_DEVICE=`aplay -l|awk '/^card 0/ {print $3}'` +else + ALSA_DEVICE="sysdefault" +fi + #ALSA_DEVICE="iec958" +LOG_PATH='/var/log/gmediarender.log' +[ ! -f "$LOG_PATH" ] && touch /var/log/gmediarender.log && chown pi $LOG_PATH -if [ -n "$ALSA_DEVICE" ] ; then +if [ -n "$PULSEAUDIO_DEVICE" ] ; then + GS_SINK_PARAM="--gstout-audiosink=autoaudiosink" + GS_DEVICE_PARAM="--gstout-audiodevice=$PULSEAUDIO_DEVICE" +elif [ -n "$ALSA_DEVICE" ] ; then GS_SINK_PARAM="--gstout-audiosink=alsasink" GS_DEVICE_PARAM="--gstout-audiodevice=$ALSA_DEVICE" fi @@ -36,6 +47,7 @@ fi # A simple stable UUID, based on this systems' first ethernet # device's MAC address, only using tools readily available to generate. UPNP_UUID=`ip link show | awk '/ether/ {print "salt:)-" $2}' | head -1 | md5sum | awk '{print $1}'` +LOG="--logfile=$LOG_PATH" # Alternatively use the MD5 summ of the short host name. # UPNP_UUID=`hostname -s | md5sum | | awk '{print $1}'` diff --git a/dist-scripts/debian/gmrender-resurrect.service b/dist-scripts/debian/gmrender-resurrect.service index 55ca190..f8fe047 100644 --- a/dist-scripts/debian/gmrender-resurrect.service +++ b/dist-scripts/debian/gmrender-resurrect.service @@ -3,11 +3,19 @@ Description=gmrender-resurrect service After=network.target sound.target [Service] -Environment="UPNP_DEVICE_NAME=Raspberry" -ExecStartPre=/bin/sh -c "/bin/systemctl set-environment UPNP_UUID=`ip link show | awk '/ether/ {print \"salt:)-\" $2}' | head -1 | md5sum | awk '{print $1}'`" +User=pi +Group=audio +Environment="GS_SINK_PARAM=autoaudiosink" +ExecStartPre=/bin/sh -c "/usr/bin/test -f '/tmp/gmrender-resurrect.vars' || /bin/rm /tmp/gmrender-resurrect.vars" +ExecStartPre=/bin/sh -c "echo UPNP_DEVICE_NAME=`/bin/hostname` > /tmp/gmrender-resurrect.vars" +ExecStartPre=/bin/sh -c "echo UPNP_UUID=`ip link show | awk '/ether/ {print \"salt:)-\" $2}' | head -1 | md5sum | awk '{print $1}'` >> /tmp/gmrender-resurrect.vars" +ExecStartPre=/bin/sh -c "pulseaudio --version ||echo GS_SINK_PARAM=alsasink >>/tmp/gmrender-resurrect.vars" +ExecStartPre=/bin/sh -c "echo GS_DEVICE_PARAM=`aplay -l|awk '/^card 0/ {print $3}'` >>/tmp/gmrender-resurrect.vars" + +EnvironmentFile=/tmp/gmrender-resurrect.vars ExecStart=/usr/local/bin/gmediarender -f "$UPNP_DEVICE_NAME" -u "$UPNP_UUID" \ - --gstout-audiosink=alsasink --gstout-audiodevice=sysdefault \ + --gstout-audiosink=${GS_SINK_PARAM} --gstout-audiodevice=${GS_DEVICE_PARAM} \ --logfile=/tmp/gmediarenderer.log --gstout-initial-volume-db=-10 Restart=always diff --git a/dist-scripts/debian/rules b/dist-scripts/debian/rules index 162e67b..eb98f6d 100755 --- a/dist-scripts/debian/rules +++ b/dist-scripts/debian/rules @@ -7,6 +7,7 @@ export DEB_BUILD_HARDENING=1 override_dh_auto_configure: ./autogen.sh dh_auto_configure -- + touch /tmp/gmrender-resurrect.vars override_dh_auto_clean: if [ -e ./Makefile ]; then make maintainer-clean; fi diff --git a/scripts/init.d/gmediarenderer b/scripts/init.d/gmediarenderer index 3dccd1d..d40de07 100755 --- a/scripts/init.d/gmediarenderer +++ b/scripts/init.d/gmediarenderer @@ -16,7 +16,7 @@ DAEMON_USER="pi:audio" # Device name as it will be advertised to and shown in the UPnP controller UI. # Some string that helps you recognize the player, e.g. "Livingroom Player" -UPNP_DEVICE_NAME="Raspberry" +UPNP_DEVICE_NAME=`hostname` # Initial volume in decibel. 0.0 is 'full volume', -10 correspondents to '75' on # the exported volume scale (Note, this does not change the ALSA volume, only @@ -27,13 +27,24 @@ INITIAL_VOLUME_DB=-10 # gmediarenderer will use that ALSA device to play audio. # Otherwise, whatever default is configured for gstreamer for the '$DAEMON_USER' is # used. -ALSA_DEVICE="sysdefault" #ALSA_DEVICE="iec958" +RET=`dpkg -l pulseaudio` +if [ $? -eq 0 ] ; then + PULSEAUDIO_DEVICE=`aplay -l|awk '/^card 0/ {print $3}'` +else + ALSA_DEVICE="sysdefault" +fi # Path to the gmediarender binary. BINARY_PATH=/usr/local/bin/gmediarender -if [ -n "$ALSA_DEVICE" ] ; then +LOG_PATH='/var/log/gmediarender.log' +[ ! -f "$LOG_PATH" ] && touch /var/log/gmediarender.log && chown pi $LOG_PATH + +if [ -n "$PULSEAUDIO_DEVICE" ] ; then + GS_SINK_PARAM="--gstout-audiosink=autoaudiosink" + GS_DEVICE_PARAM="--gstout-audiodevice=$PULSEAUDIO_DEVICE" +elif [ -n "$ALSA_DEVICE" ] ; then GS_SINK_PARAM="--gstout-audiosink=alsasink" GS_DEVICE_PARAM="--gstout-audiodevice=$ALSA_DEVICE" fi @@ -41,6 +52,7 @@ fi # A simple stable UUID, based on this systems' first ethernet devices MAC address, # only using tools readily available to generate. UPNP_UUID=`ip link show | awk '/ether/ {print "salt:)-" $2}' | head -1 | md5sum | awk '{print $1}'` +LOG="--logfile=$LOG_PATH" USER=root HOME=/root @@ -48,7 +60,7 @@ export USER HOME case "$1" in start) echo "Starting GMediaRender" - start-stop-daemon -x $BINARY_PATH -c "$DAEMON_USER" -S -- -f "$UPNP_DEVICE_NAME" -d -u "$UPNP_UUID" $GS_SINK_PARAM $GS_DEVICE_PARAM --gstout-initial-volume-db=$INITIAL_VOLUME_DB + start-stop-daemon -x $BINARY_PATH -c "$DAEMON_USER" -S -- -f "$UPNP_DEVICE_NAME" -d -u "$UPNP_UUID" $GS_SINK_PARAM $GS_DEVICE_PARAM --gstout-initial-volume-db=$INITIAL_VOLUME_DB $LOG ;; stop) diff --git a/scripts/logrotate.d/gmediarender b/scripts/logrotate.d/gmediarender new file mode 100644 index 0000000..5b0cccb --- /dev/null +++ b/scripts/logrotate.d/gmediarender @@ -0,0 +1,7 @@ +/var/log/gmediarender.log { + rotate 2 + weekly + compress + missingok + notifempty +}