MusicLounge: Multi Room Audio Configuration

Multi Room Audio Configuration

# if you intend to create a multi-room audiophile configuration sharing the same music library on your LAN network
# Use the script below to configure your audio server very easily.

# create the script in scripts directory

  1. $ sudo nano ~/scripts/

# insert these lines (copy then right-click on ssh session)


# File:
# Author: Linux Audio Foundation
# Requirements: MusicLounge Audiophile Distro
# Link:
# get current arch
arch=$(dpkg --print-architecture)

# check if run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run by root" >&2
exit 1

CURR_HNAME=$(cat /etc/hostname)

echo "current hostname: ${CURR_HNAME}" >&2
echo "new hostname: ${NEW_HOSTNAME}" >&2

# empty new hostname
if [ -z "${NEW_HOSTNAME}" ]; then
echo "error: hostname (first parameter) is empty!" >&2
exit 1

# no change
if [ "${CURR_HNAME}" == "${NEW_HOSTNAME}" ]; then
echo "Same host name exit with no change." >&2
exit 1

# hostname cfg
sudo sed -i "s/$CURR_HNAME/$NEW_HOSTNAMELOW/g" /etc/hostname

# hosts
sudo sed -i "s/$CURR_HNAME/$NEW_HOSTNAMELOW/g" /etc/hosts

echo "hostname and hosts changed to: ${NEW_HOSTNAMELOW}" >&2

# mini dlna cfg
sudo sed -i "s/$CURR_HNAME/$NEW_HOSTNAME/I" /etc/minidlna.conf
echo "minidlna service changed to: ${NEW_HOSTNAME}" >&2

# upmpdcli (upnp)cfg
sudo sed -i "s/$CURR_HNAME/$NEW_HOSTNAME/I" /etc/upmpdcli.conf
echo "upnp service changed to: ${NEW_HOSTNAME}" >&2

# air play cfg
# nothing to do as general section contains name = "%H" which is current hostname
sudo sed -i "s/$CURR_HNAME/$NEW_HOSTNAME/I" /etc/shairport-sync.conf
echo "AirPlay service changed to: ${NEW_HOSTNAME}" >&2

# spotify connect armhf & arm64 cfg
if [ "amd64" != "$arch" ]; then
# armhf and arm64
sudo sed -i "s/$CURR_HNAME/$NEW_HOSTNAME/I" /etc/default/raspotify
echo "Spotify Connect (armhf/arm64) service changed to: ${NEW_HOSTNAME}" >&2

# docker spot container on amd64 cfg
if [ "amd64" == "$arch" ]; then
# read -p "Press any key to stop Spotify Connect service"
sudo docker ps -q --filter "name=spot" | grep -q . && docker stop spot && docker rm -fv spot
# read -p "Press any key to change the new of Spotify Connect to ${NEW_HOSTNAME}"
export SPOTNAME=$(echo "NAME=${NEW_HOSTNAME}")
sudo docker run -d --restart unless-stopped \
--name "spot" \
--env $SPOTNAME \
--volume /tmp \
--group-add audio \
--device /dev/snd \
--net host \
--cap-drop ALL \
--read-only \
dubodubonduponey/librespot \
--backend alsa \
--device plughw:1,0 \
--disable-audio-cache \
echo "Spotify Connect (Docker amd64) service changed to: ${NEW_HOSTNAME}" >&2

# ask before rebooting
while true; do
read -p "Hostname and services have been changed for ${NEW_HOSTNAME}, reboot for the change to take effect (y / n)? " yx
case $yx in
[Yy]* ) sudo reboot; break;;
* ) exit;;

# CTRL+O to save
# CTRL+X to exit

# change permision

  1. $ sudo chmod +x ~/scripts/

# we suggest a name which identify the room easily like a Music or Audio prefix + the room name (e.g MusicBedroom, MusicLivingroom, MusicKitchen,…)
# run the script with the audio server name in parameter, example:

  1. $ cd scripts/
  2. $ sudo ./ MusicKitchen

# type y to reboot the server
# that’s it!