Skip to content

Commit c1fa0b2

Browse files
committed
Run roonapi commands in postinstall as user if provided
1 parent 601a398 commit c1fa0b2

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

etc/postinstall

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ echo "to authorize discovery"
254254
echo ""
255255

256256
# Get and set the Roon Core IP address
257-
${ROON}/bin/get_core_ip 2>&1 | tee /tmp/discover$$
257+
if [ "${USER}" ]
258+
then
259+
sudo -u ${USER} ${ROON}/bin/get_core_ip 2>&1 | tee /tmp/discover$$
260+
else
261+
${ROON}/bin/get_core_ip 2>&1 | tee /tmp/discover$$
262+
fi
258263
CORE_IP=`cat /tmp/discover$$ | grep RoonCoreIP | awk -F '=' ' { print $2 } '`
259264
CORE_IP="$(echo -e "${CORE_IP}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
260265
CORE_PORT=`cat /tmp/discover$$ | grep RoonCorePort | awk -F '=' ' { print $2 } '`
@@ -273,12 +278,22 @@ groupOne=
273278
groupTwo=
274279
groupRee=
275280
groupFor=
276-
zones=`${ROON}/bin/get_zones`
281+
if [ "${USER}" ]
282+
then
283+
zones=`sudo -u ${USER} ${ROON}/bin/get_zones`
284+
else
285+
zones=`${ROON}/bin/get_zones`
286+
fi
277287
numZones=`echo "${zones}" | awk -F ',' ' { print NF } '`
278288
numWith=0
279289
[ ${numZones} -gt 0 ] && {
280290
defaultZone=`echo "${zones}" | awk -F ',' ' { print $1 } '`
281-
withDefaultZone=`${ROON}/bin/get_zone_info -l -z "${defaultZone}"`
291+
if [ "${USER}" ]
292+
then
293+
withDefaultZone=`sudo -u ${USER} ${ROON}/bin/get_zone_info -l -z "${defaultZone}"`
294+
else
295+
withDefaultZone=`${ROON}/bin/get_zone_info -l -z "${defaultZone}"`
296+
fi
282297
numWith=`echo "${withDefaultZone}" | awk -F ',' ' { print NF } '`
283298
}
284299
[ ${numZones} -gt 2 ] && {
@@ -315,7 +330,12 @@ numWith=0
315330

316331
zoneTwo=${Array3[0]}
317332
[ "${zoneTwo}" ] || zoneTwo=${arrayone[1]}
318-
withZoneTwo=`${ROON}/bin/get_zone_info -l -z "${zoneTwo}"`
333+
if [ "${USER}" ]
334+
then
335+
withZoneTwo=`sudo -u ${USER} ${ROON}/bin/get_zone_info -l -z "${zoneTwo}"`
336+
else
337+
withZoneTwo=`${ROON}/bin/get_zone_info -l -z "${zoneTwo}"`
338+
fi
319339
numWithTwo=`echo "${withZoneTwo}" | awk -F ',' ' { print NF } '`
320340
[ ${numWithTwo} -gt 0 ] && {
321341
groupTwo=`echo "${zoneTwo},${withZoneTwo}" | sed -e "s/${defaultZone},//" -e "s/,/, /g" -e "s/:/,/"`
@@ -326,7 +346,12 @@ numWith=0
326346
}
327347
[ ${numZones} -gt 3 ] && {
328348
secondZone=`echo "${zones}" | awk -F ',' ' { print $2 } ' | sed -e "s/^ //"`
329-
withSecondZone=`${ROON}/bin/get_zone_info -l -z "${secondZone}"`
349+
if [ "${USER}" ]
350+
then
351+
withSecondZone=`sudo -u ${USER} ${ROON}/bin/get_zone_info -l -z "${secondZone}"`
352+
else
353+
withSecondZone=`${ROON}/bin/get_zone_info -l -z "${secondZone}"`
354+
fi
330355
withSecondZone=`echo ${withSecondZone} | sed -e "s/${defaultZone},//"`
331356
numWith=`echo "${withSecondZone}" | awk -F ',' ' { print NF } '`
332357
if [ ${numWith} -gt 1 ]
@@ -342,7 +367,12 @@ numWith=0
342367
}
343368
[ ${numZones} -gt 4 ] && {
344369
lastZone=`echo "${zones}" | awk -F ',' ' { print $(NF) } ' | sed -e "s/^ //"`
345-
withLastZone=`${ROON}/bin/get_zone_info -l -z "${lastZone}"`
370+
if [ "${USER}" ]
371+
then
372+
withLastZone=`sudo -u ${USER} ${ROON}/bin/get_zone_info -l -z "${lastZone}"`
373+
else
374+
withLastZone=`${ROON}/bin/get_zone_info -l -z "${lastZone}"`
375+
fi
346376
withLastZone=`echo ${withLastZone} | sed -e "s/${defaultZone},//"`
347377
withLastZone=`echo ${withLastZone} | sed -e "s/${secondZone},//"`
348378
numWith=`echo "${withLastZone}" | awk -F ',' ' { print NF } '`

0 commit comments

Comments
 (0)