forked from TonyTromp/tidal-connect-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_hifiberry.sh
executable file
·297 lines (259 loc) · 8.23 KB
/
install_hifiberry.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/bash
log() {
script=$(basename "$0")
echo "$(/bin/date) ${HOSTNAME} ${script}[$$]: [$1]: $2"
}
running_environment()
{
echo "Running environment: "
echo " FRIENDLY_NAME: ${FRIENDLY_NAME}"
echo " MODEL_NAME: ${MODEL_NAME}"
echo " BEOCREATE_SYMLINK_FOLDER: ${BEOCREATE_SYMLINK_FOLDER}"
echo " DOCKER_DNS: ${DOCKER_DNS}"
echo " DOCKER_IMAGE: ${DOCKER_IMAGE}"
echo " BUILD_OR_PULL: ${BUILD_OR_PULL}"
echo " MQA_PASSTHROUGH: ${MQA_PASSTHROUGH}"
echo " MQA_CODEC: ${MQA_CODEC}"
echo " PWD: ${PWD}"
echo ""
}
usage()
{
echo "$0 installs TIDAL Connect on your Raspberry Pi."
echo ""
echo "Usage: "
echo ""
echo " [FRIENDLY_NAME=<FRIENDLY_NAME>] \\"
echo " [MODEL_NAME=<MODEL_NAME>] \\"
echo " [BEOCREATE_SYMLINK_FOLDER=<BEOCREATE_SYMLINK_FOLDER>] \\"
echo " [DOCKER_DNS=<DOCKER_DNS>] \\"
echo " [DOCKER_IMAGE=<DOCKER_IMAGE>] \\"
echo " [BUILD_OR_PULL=<build|pull>] \\"
echo " [MQA_PASSTHROUGH=<true|false>] \\"
echo " [MQA_CODEC=<true|false>] \\"
echo " $0 \\"
echo " [-f <FRIENDLY_NAME>] \\"
echo " [-m <MODEL_NAME>] \\"
echo " [-b <BEOCREATE_SYMLINK_FOLDER>] \\"
echo " [-d <DOCKER_DNS>] \\"
echo " [-i <Docker Image>] \\"
echo " [-p <build|pull>] \\"
echo " [-t <true|false>] \\"
echo " [-c <true|false>"
echo ""
echo "Defaults:"
echo " FRIENDLY_NAME: ${FRIENDLY_NAME_DEFAULT}"
echo " MODEL_NAME: ${MODEL_NAME_DEFAULT}"
echo " BEOCREATE_SYMLINK_FOLDER: ${BEOCREATE_SYMLINK_FOLDER_DEFAULT}"
echo " DOCKER_DNS: ${DOCKER_DNS_DEFAULT}"
echo " DOCKER_IMAGE: ${DOCKER_IMAGE_DEFAULT}"
echo " BUILD_OR_PULL: ${BUILD_OR_PULL_DEFAULT}"
echo " MQA_PASSTHROUGH: ${MQA_PASSTHROUGH_DEFAULT}"
echo " MQA_CODEC: ${MQA_CODEC_DEFAULT}"
echo ""
echo "Example: "
echo " BUILD_OR_PULL=build \\"
echo " DOCKER_IMAGE=tidal-connect:latest \\"
echo " MQA_PASSTHROUGH=true \\"
echo " $0"
echo ""
running_environment
echo "Please note that command line arguments "
echo "take precedence over environment variables,"
echo "which take precedence over defaults."
echo ""
}
select_playback_device()
{
ARRAY_DEVICES=()
DEVICES=$(docker run --device /dev/snd \
--entrypoint "" \
edgecrush3r/tidal-connect \
/app/ifi-tidal-release/bin/ifi-pa-devs-get 2>/dev/null | grep device#)
echo ""
echo "Found output devices..."
echo ""
#make newlines the only separator
IFS=$'\n'
re_parse="^device#([0-9])+=(.*)$"
for line in $DEVICES
do
if [[ $line =~ $re_parse ]]
then
device_num="${BASH_REMATCH[1]}"
device_name="${BASH_REMATCH[2]}"
echo "${device_num}=${device_name}"
ARRAY_DEVICES+=( ${device_name} )
fi
done
while :; do
read -ep 'Choose your output Device (0-9): ' number
[[ $number =~ ^[[:digit:]]+$ ]] || continue
(( ( (number=(10#$number)) <= 9999 ) && number >= 0 )) || continue
# Here I'm sure that number is a valid number in the range 0..9999
# So let's break the infinite loop!
break
done
PLAYBACK_DEVICE="${ARRAY_DEVICES[$number]}"
}
# define defaults
FRIENDLY_NAME_DEFAULT=${HOSTNAME}
MODEL_NAME_DEFAULT=${HOSTNAME}
BEOCREATE_SYMLINK_FOLDER_DEFAULT="/opt/beocreate/beo-extensions/tidal"
DOCKER_DNS_DEFAULT="8.8.8.8"
DOCKER_IMAGE_DEFAULT="edgecrush3r/tidal-connect:latest"
BUILD_OR_PULL_DEFAULT="pull"
MQA_PASSTHROUGH_DEFAULT="false"
MQA_CODEC_DEFAULT="false"
PLAYBACK_DEVICE="default"
# override defaults with environment variables, if they have been set
FRIENDLY_NAME=${FRIENDLY_NAME:-${FRIENDLY_NAME_DEFAULT}}
MODEL_NAME=${MODEL_NAME:-${MODEL_NAME_DEFAULT}}
BEOCREATE_SYMLINK_FOLDER=${BEOCREATE_SYMLINK_FOLDER:-${BEOCREATE_SYMLINK_FOLDER_DEFAULT}}
DOCKER_DNS=${DOCKER_DNS:-${DOCKER_DNS_DEFAULT}}
DOCKER_IMAGE=${DOCKER_IMAGE:-${DOCKER_IMAGE_DEFAULT}}
BUILD_OR_PULL=${BUILD_OR_PULL:-${BUILD_OR_PULL_DEFAULT}}
MQA_PASSTHROUGH=${MQA_PASSTHROUGH:-${MQA_PASSTHROUGH_DEFAULT}}
MQA_CODEC=${MQA_CODEC:-${MQA_CODEC_DEFAULT}}
HELP=${HELP:-0}
VERBOSE=${VERBOSE:-0}
# override with command line parameters, if defined
while getopts "hvf:m:b:d:i:p:t:c:" option
do
case ${option} in
f)
FRIENDLY_NAME=${OPTARG}
;;
m)
MODEL_NAME=${OPTARG}
;;
b)
BEOCREATE_SYMLINK_FOLDER=${OPTARG}
;;
d)
DOCKER_DNS=${OPTARG}
;;
i)
DOCKER_IMAGE=${OPTARG}
;;
p)
BUILD_OR_PULL=${OPTARG}
;;
t)
MQA_PASSTHROUGH=${OPTARG}
;;
c)
MQA_CODEC=${OPTARG}
;;
v)
VERBOSE=1
;;
h)
HELP=1
usage
exit 0
;;
esac
done
running_environment
log INFO "Pre-flight checks."
log INFO "Checking to see if Docker is running."
docker info &> /dev/null
if [ $? -ne 0 ]
then
log ERROR "Docker daemon isn't running."
exit 1
else
log INFO "Confirmed that Docker daemon is running."
fi
log INFO "Checking to see if Docker image ${DOCKER_IMAGE} exists."
docker inspect --type=image ${DOCKER_IMAGE} &> /dev/null
if [ $? -eq 0 ]
then
log INFO "Docker image ${DOCKER_IMAGE} exist on the local machine."
DOCKER_IMAGE_EXISTS=1
else
log INFO "Docker image ${DOCKER_IMAGE} does not exist on local machine."
DOCKER_IMAGE_EXISTS=0
fi
# Pull latest image or build Docker image if it doesn't already exist.
if [ ${DOCKER_IMAGE_EXISTS} -eq 0 ]
then
if [ "${BUILD_OR_PULL}" == "pull" ]
then
# Pulling latest image
log INFO "Pulling docker image ${DOCKER_IMAGE}."
docker pull ${DOCKER_IMAGE}
log INFO "Finished pulling docker image ${DOCKER_IMAGE}."
elif [ "${BUILD_OR_PULL}" == "build" ]
then
log INFO "Building docker image."
cd Docker && \
DOCKER_IMAGE=${DOCKER_IMAGE} ./build_docker.sh && \
cd ..
log INFO "Finished building docker image."
else
log ERROR "BUILD_OR_PULL must be set to \"build\" or \"pull\""
usage
exit 1
fi
docker inspect --type=image ${DOCKER_IMAGE} &> /dev/null
if [ $? -ne 0 ]
then
log ERROR "Docker image ${DOCKER_IMAGE} does not exist on the local machine even after we tried ${BUILD_OR_PULL}ing it."
log ERROR "Exiting."
exit 1
fi
fi
if [ "$(docker ps -q -f name=tidal_connect)" ]; then
log INFO "Stopping Tidal Container.."
./stop-tidal-service.sh
fi
log INFO "Select audio output device"
select_playback_device
echo ${PLAYBACK_DEVICE}
log INFO "Creating .env file."
ENV_FILE="${PWD}/Docker/.env"
CONFIG_FILE="${PWD}/Docker/CONFIG"
> ${ENV_FILE}
echo "FRIENDLY_NAME=${FRIENDLY_NAME}" >> ${ENV_FILE}
echo "MODEL_NAME=${MODEL_NAME}" >> ${ENV_FILE}
echo "MQA_PASSTHROUGH=${MQA_PASSTHROUGH}" >> ${ENV_FILE}
echo "MQA_CODEC=${MQA_CODEC}" >> ${ENV_FILE}
echo "PLAYBACK_DEVICE=${PLAYBACK_DEVICE}" >> ${ENV_FILE}
log INFO "Finished creating .env file."
if [ -L "${CONFIG_FILE}" ]; then
log INFO "${CONFIG_FILE} already exists. this file will be replaced with new configuration."
rm "${CONFIG_FILE}"
fi
log INFO "Create config symlink -> ${ENV_FILE}"
ln -s ${ENV_FILE} ${CONFIG_FILE}
# Generate docker-compose.yml
log INFO "Generating docker-compose.yml."
eval "echo \"$(cat templates/docker-compose.yml.tpl)\"" > Docker/docker-compose.yml
log INFO "Finished generating docker-compose.yml."
# Enable service
log INFO "Enabling TIDAL Connect Service."
eval "echo \"$(cat templates/tidal.service.tpl)\"" >/etc/systemd/system/tidal.service
systemctl enable tidal.service
log INFO "Finished enabling TIDAL Connect Service."
# Add TIDAL Connect Source to Beocreate
log INFO "Adding TIDAL Connect Source to Beocreate."
if [ -L "${BEOCREATE_SYMLINK_FOLDER}" ]; then
# Already installed... remove symlink and re-install
log INFO "TIDAL Connect extension found, removing previous install."
rm ${BEOCREATE_SYMLINK_FOLDER}
fi
log INFO "Adding TIDAL Connect Source to Beocreate UI."
ln -s ${PWD}/beocreate/beo-extensions/tidal ${BEOCREATE_SYMLINK_FOLDER}
log INFO "Finished adding TIDAL Connect Source to Beocreate."
log INFO "Installation Completed."
if [ "$(docker ps -q -f name=docker_tidal-connect)" ]; then
log INFO "Stopping TIDAL Connect Service."
./stop-tidal-service.sh
fi
log INFO "Starting TIDAL Connect Service."
./start-tidal-service.sh
log INFO "Restarting Beocreate 2 Service."
./restart_beocreate2
log INFO "Finished, exiting."