-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
set_zone_group
executable file
·68 lines (60 loc) · 1.67 KB
/
set_zone_group
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
#
# shellcheck disable=SC1090,SC2220
ROON=/usr/local/Roon
ROONAPI=${ROON}/api
ROONETC=${ROON}/etc
ROONCONF=${ROONETC}/pyroonconf
SCRIPT="zone_group.py"
[ -f ${ROONAPI}/${SCRIPT} ] || {
echo "Roon Command Line scripts not installed. Missing $ROONAPI/$SCRIPT"
exit 1
}
cd ${ROONAPI} || exit 1
# Verify this is a valid zone grouping command
[ "$1" ] || {
echo "No zone grouping command specified on command line. Exiting."
exit 1
}
[ "$1" == "group" ] || [ "$1" == "ungroup" ] || {
echo "Zone grouping command must be 'group' or 'ungroup'. Exiting."
exit 1
}
ZONE_COMMAND="$1"
# Verify this is a valid zone group name
[ "$2" ] || {
echo "No zone grouping specified on command line. Exiting."
exit 1
}
ROON_ZONE_GROUP="Group_$2"
found_group=
for gn in $(grep ^Group_ "${ROONETC}"/roon_api.ini | awk -F '=' ' { print $1 } ')
do
gn="$(echo -e "${gn}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
[ "$ROON_ZONE_GROUP" == "$gn" ] && found_group=1
done
[ "$found_group" ] || {
echo "No matching zone grouping found. Exiting."
exit 1
}
# Use a Python virtual environment
[ -f ${ROON}/venv/bin/activate ] && source ${ROON}/venv/bin/activate
[[ ":$PATH:" == *":/usr/local/Roon/venv/bin:"* ]] || {
export PATH=/usr/local/Roon/venv/bin:${PATH}
}
if [ -f ${ROONCONF} ]
then
. ${ROONCONF}
else
DEFZONE=$(grep ^DefaultZone ${ROONETC}/roon_api.ini | awk -F '=' ' { print $2 } ')
${ROON}/bin/set_zone "${DEFZONE}"
. ${ROONCONF}
fi
have_python3=$(type -p python3)
if [ "${have_python3}" ]
then
python3 $SCRIPT -c "$ZONE_COMMAND" -z "$ROON_ZONE_GROUP"
else
python $SCRIPT -c "$ZONE_COMMAND" -z "$ROON_ZONE_GROUP"
fi
exit 0