aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/mpd-pulse62
-rw-r--r--user/mpd-new.service15
-rw-r--r--user/mpd@.service4
3 files changed, 64 insertions, 17 deletions
diff --git a/scripts/mpd-pulse b/scripts/mpd-pulse
new file mode 100755
index 0000000..afb33e0
--- /dev/null
+++ b/scripts/mpd-pulse
@@ -0,0 +1,62 @@
+# !/usr/bin/env bash
+
+set -euo pipefail
+IFS=$'\n\t'
+
+host="$(hostname)"
+
+function connect ()
+{
+ if [[ $1 != "${host}"* ]] && [[ $1 != localhost* ]]; then
+ echo "Connecting with host \"$1\" using pax11publish."
+ pax11publish -S $1 -e
+ fi
+}
+
+function disconnect ()
+{
+ if [[ $1 != "${host}"* ]] && [[ $1 != localhost* ]]; then
+ echo "Disconnecting from host \"$1\" using pax11publish."
+ pax11publish -r
+ fi
+}
+
+function print_help ()
+{
+ echo "Use this script as follows:"
+ echo "Connect to host with mpd-pulse -c hostname"
+ echo "Disconnect from host with mpd-pulse -d hostname"
+ echo "If your given hostname is localhost or matches your local machine, no action will be taken."
+}
+
+if [ ${#@} -gt 0 ]; then
+ while getopts 'c:d:h' flag; do
+ case "${flag}" in
+ c)
+ if [ ! -z "${OPTARG}" ]; then
+ connect "${OPTARG}"
+ else
+ exit 1
+ fi
+ ;;
+ d)
+ if [ ! -z "${OPTARG}" ]; then
+ disconnect "${OPTARG}"
+ else
+ exit 1
+ fi
+ ;;
+ h)
+ print_help
+ ;;
+ *)
+ echo "Error. Unrecognized option: ${flag}."
+ exit 1
+ ;;
+ esac
+ done
+else
+ print_help
+fi
+
+exit 0
diff --git a/user/mpd-new.service b/user/mpd-new.service
deleted file mode 100644
index 730bc71..0000000
--- a/user/mpd-new.service
+++ /dev/null
@@ -1,15 +0,0 @@
-[Unit]
-Description=Music Player Daemon
-After=network.target sound.target
-Conflicts=mpd@.service
-
-[Service]
-ExecStartPre=/usr/bin/mkdir -p %t/mpd
-ExecStart=/usr/bin/mpd --no-daemon
-CPUSchedulingPolicy=rr
-CPUSchedulingPriority=70
-LimitRTPRIO=50
-LimitRTTIME=infinity
-
-[Install]
-WantedBy=default.target
diff --git a/user/mpd@.service b/user/mpd@.service
index 74fb0a3..643b871 100644
--- a/user/mpd@.service
+++ b/user/mpd@.service
@@ -6,8 +6,8 @@ Conflicts=mpd.service
[Service]
ExecStartPre=/usr/bin/mkdir -p %t/mpd
ExecStart=/usr/bin/mpd --no-daemon %h/.config/mpd/mpd-%i.conf
-ExecStartPost=/usr/bin/pax11publish -S %i -e
-ExecStopPost=/usr/bin/pax11publish -r
+ExecStartPost=/usr/lib/systemd/scripts/mpd-pulse -c %i
+ExecStopPost=/usr/lib/systemd/scripts/mpd-pulse -d %i
CPUSchedulingPolicy=rr
CPUSchedulingPriority=70
LimitRTPRIO=50