aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mpd-pulse
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2016-06-03 23:50:04 +0200
committerDavid Runge <dave@sleepmap.de>2016-06-03 23:50:04 +0200
commitf3ef116c1ded619adaa41d5bf94e414bbabd4a9b (patch)
tree81afadbf24d5fb4dfdd1aba1d4291104f0937ae0 /scripts/mpd-pulse
parentc44c182f3a75f60d4884359c5bd2782468ee72bc (diff)
downloaduenv-f3ef116c1ded619adaa41d5bf94e414bbabd4a9b.tar.gz
uenv-f3ef116c1ded619adaa41d5bf94e414bbabd4a9b.tar.bz2
uenv-f3ef116c1ded619adaa41d5bf94e414bbabd4a9b.tar.xz
uenv-f3ef116c1ded619adaa41d5bf94e414bbabd4a9b.zip
user/mpd{@,-new}.service: Unifying all template based approaches in mpd@.service. scripts/mpd-pulse: Adding script to start/stop a pax11publish connection to the given host, if it's not an extension of hostname or localhost.
Diffstat (limited to 'scripts/mpd-pulse')
-rwxr-xr-xscripts/mpd-pulse62
1 files changed, 62 insertions, 0 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