Last active 1726527644

Revision 966fb0adc7c0f26a8e5886815f1c9ea3055d54bc

mpdsrvp Raw
1#!/bin/sh
2# mpdsrvp
3#
4# Serve a MPD instance on a different port already in a partition
5# This "adds" partition support for mpd clients that don't support it.
6#
7# ~jmjl
8: "${mpd_srv_addr:="127.0.0.1"}"
9: "${mpd_srv_port:="6600"}"
10
11mpm() {
12 printf '%s\n' "$1" | timeout 0.15 nc "$mpd_srv_addr" "$mpd_srv_port"
13}
14
15
16[ -z "$ca95505c_baa3_4c12_95b3_552426a8aea5_mpdsrvp" ] && {
17
18[ "$#" -lt "1" ] && { printf 'mpdsrvp [add/del/list/(move <part> <out>)] <partition> <port>(,bind=<bind>)\n'; exit 1; }
19
20case "$1" in
21 "add") mpm "newpartition $2";;
22 "del") mpm "delpartition $2";;
23 "list") mpm "listpartitions";;
24 "move") mpm "partition $2
25moveoutput $3";;
26 *) export ca95505c_baa3_4c12_95b3_552426a8aea5_mpdsrvp="$1"
27 socat TCP-L:"$2",reuseaddr,fork,nodelay SYSTEM:"$0";;
28esac
29
30exit;
31}
32
33{ printf 'partition %s\n' "$ca95505c_baa3_4c12_95b3_552426a8aea5_mpdsrvp"; cat; } |\
34 nc "$mpd_srv_addr" "$mpd_srv_port" |\
35 sed --unbuffered '2d'
36