Skip to content

Instantly share code, notes, and snippets.

@bawbgale
Last active January 3, 2022 22:06
Show Gist options
  • Save bawbgale/1ef81cf5e05c5658d34fd397c724dd2a to your computer and use it in GitHub Desktop.
Save bawbgale/1ef81cf5e05c5658d34fd397c724dd2a to your computer and use it in GitHub Desktop.
Jamulus server + remote install
#!/bin/bash
echo ".----------------------------------------------------------."
echo "| Simons Jamulus Setup + vdellameas jamulus-server-remote |"
echo "+----------------------------------------------------------+"
echo "| This script installs/upgrades jamulus to the latest |"
echo "| release as well as allows you to setup a new jamulus |"
echo "| server. You can do either or both. |"
echo "'----------------------------------------------------------'"
read -p "Install/Upgrade Jamulus? (Y/y/N/n) :" install
if [[ "$install" == "Y" ]] || [[ "$install" == "y" ]]
then
#------------------------------------------------------------------------------
# First, get the latest .deb file from GitHub and install it
#------------------------------------------------------------------------------
url=$( curl -s https://api.github.com/repos/jamulussoftware/jamulus/releases/latest | fgrep browser_download_url | grep -o '[^"]*headless[^"]*' )
file=${url##*/}
wget -nv -N $url || { echo failed to download package ; exit 1; }
sudo apt update || { echo failed to update apt database ; exit 1; }
sudo apt install -y ./$file || { echo failed to install package ; exit 1; }
# disable the default service, as we will create or use our own
sudo systemctl stop jamulus-headless
sudo systemctl disable jamulus-headless
#------------------------------------------------------------------------------
# Now look for existing services that refer to the old llcon installations
#------------------------------------------------------------------------------
oldserv=$( systemctl -t service list-unit-files jamulus\* | fgrep .service | sed 's/\.service.*//' )
if [[ -n "$oldserv" ]]; then
# echo "You have the following old services set up currently: " $oldserv
for serv in $oldserv ; do
if systemctl --value -p ExecStart show $serv | grep -q llcon-jamulus; then
echo Old service $serv found - updating
enabled=$( systemctl is-enabled $serv )
active=$( systemctl is-active $serv )
sudo systemctl disable $serv
sudo systemctl stop $serv
file=$( systemctl --value -p FragmentPath show $serv )
sudo sed -i -e 's|/usr/local/bin/llcon-jamulus/Jamulus|/usr/bin/jamulus-headless|ig' $file
echo Updated $file for new server
sudo systemctl daemon-reload
# Now restore the state of the service
if [[ "$enabled" == 'enabled' ]]; then
sudo systemctl enable $serv
fi
if [[ "$active" == 'active' ]]; then
sudo systemctl start $serv
fi
fi
done
fi
sudo mkdir -p /var/log/jamulus
sudo chown jamulus:nogroup /var/log/jamulus
fi
read -p "Do you want to setup a Jamulus Server? (Y/y/N/n) : " setup
if [[ $setup == "Y" ]] || [[ $setup == "y" ]]
then
read -p "Enter name of your jamulus server : " servertitle
servicename="jamulus-headless"
# servicename=`echo "jamulus_$servername" | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//' | sed -e 's/ /_/g'`
read -p "Enter port number to use or default (Enter=default) : " portno
if [[ "$portno" != "" ]]
then
portno="--port $portno"
fi
read -p "Choose central list server to register to, for a public server, or 'p' for private.
1 - AnyGenre1 (formerly Default)
2 - AnyGenre2 (formerly All Genres)
3 - AnyGenre3 (new)
4 - Rock Genre
5 - Jazz Genre
6 - Classical/Folk Genre (formerly Folk/Classical/Choir)
7 - Choral/Barbershop (new)
8 - WorldJam
p - Private
c - This server will itself be a Central Server
Select: " cs
# check response and set correct line
case "$cs" in
1) central="--centralserver anygenre1.jamulus.io:22124" ;;
2) central="--centralserver anygenre2.jamulus.io:22224" ;;
3) central="--centralserver anygenre3.jamulus.io:22624" ;;
4) central="--centralserver rock.jamulus.io:22424" ;;
5) central="--centralserver jazz.jamulus.io:22324" ;;
6) central="--centralserver classical.jamulus.io:22524" ;;
7) central="--centralserver choral.jamulus.io:22724" ;;
8) central="--centralserver worldjam.vip" ;;
c) central="--centralserver localhost" ;;
*) central="" ;;
esac
if [[ "$cs" == "p" ]]
then
ufw allow 22124/udp
fi
read -p "Do you want recording enabled? (Y/y/N/n) : " recording
if [[ "$recording" == "Y" ]] || [[ "$recording" == "y" ]]
then
recording="--recording /home/jamulus/recording"
else
recording=""
fi
read -p "Do you want recording toggled on at start? (Y/y/N/n) : " toggle
if [[ "$toggle" == "N" ]] || [[ "$toggle" == "n" ]]
then
toggle="--norecord"
else
toggle=""
fi
read -p "How many max clients do you want to enable? (default 10) : " channels
if [[ "$channels" == "" ]]; then channels=10; fi
read -p "Location of your server (max chars 20) : " location
read -p "Enter country code for your server https://doc.qt.io/qt-5/qlocale.html#Country-enum (Common: 224 - UK, 225 - US, 151 - Netherlands, 82 - Germany, 205 - Sweden) : " ccode
/bin/cat <<EOF > ~/jamulus.service
[Unit]
Description=$servicetitle
After=network.target
[Service]
Type=simple
User=jamulus
Group=www-data
UMask=0002
NoNewPrivileges=true
ProtectSystem=true
ProtectHome=false
Nice=-20
IOSchedulingClass=realtime
IOSchedulingPriority=0
# This line below is what you want to edit according to your preferences
ExecStart=/usr/bin/jamulus-headless --server --nogui \
--log /var/log/jamulus/$servicename.log \
$recording \
$toggle \
--serverinfo "$servername;$location;$ccode" \
$central \
$portno \
--welcomemessage "Welcome to $servertitle" \
--numchannels $channels \
--multithreading
# end of section you might want to alter
Restart=on-failure
RestartSec=30
StandardOutput=journal
StandardError=inherit
SyslogIdentifier=jamulus
[Install]
WantedBy=multi-user.target
EOF
sleep 3s # Sleep for 3 seconds to allow filesystem to write file
echo "Starting server '$servername'"
OUT=/etc/systemd/system/$servicename.service
sudo cp ~/jamulus.service $OUT
sudo systemctl daemon-reload
sudo systemctl start $servicename
sudo systemctl enable $servicename
fi
read -p "JAMULUS RECORDING REMOTE INSTALLATION v0.6. Are you sure? (y/n)? " answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
echo "Stopping server '$servername'"
sudo systemctl stop jamulus-headless
sudo apt update
sudo apt install -y wget curl
#------------------------------------------------------------------------------
# Get the latest .zip file from jamulus-server-remote GitHub
#------------------------------------------------------------------------------
jsr_url=https://github.com/vdellamea/jamulus-server-remote/archive/main.zip
jsr_file=${jsr_url##*/}
wget -nv -N $jsr_url || { echo failed to download zip file ; exit 1; }
#------------------------------------------------------------------------------
# Install needed packages
#------------------------------------------------------------------------------
sudo apt install -y unzip apache2 php libapache2-mod-php ffmpeg acl|| { echo failed to install package ; exit 1; }
# Unzip jsr
unzip $jsr_file && cd jamulus-server-remote-main
# prepare web document root
sudo rm /var/www/html/index.html
sudo cp *.php /var/www/html/
sudo chown -R www-data /var/www/html/
sudo chgrp -R www-data /var/www/html/
# home dir for the jamulus user
sudo usermod -d /home/jamulus jamulus
sudo mkhomedir_helper jamulus
# recording directory
sudo mkdir /home/jamulus/recording
sudo chgrp www-data /home/jamulus/recording/
sudo chmod g+rwx /home/jamulus/recording/
sudo chmod g+s /home/jamulus/recording/
sudo setfacl -d -m g::rwx /home/jamulus/recording/
# mixed songs directory
sudo mkdir /home/jamulus/mix
sudo chgrp www-data /home/jamulus/mix/
sudo chmod g+rwx /home/jamulus/mix/
sudo chmod g+s /home/jamulus/mix/
sudo setfacl -d -m g::rwx /home/jamulus/mix/
# consolidated tracks directory
sudo mkdir /home/jamulus/consolidated
sudo chgrp www-data /home/jamulus/consolidated/
sudo chmod g+rwx /home/jamulus/consolidated/
sudo chmod g+s /home/jamulus/consolidated/
sudo setfacl -d -m g::rwx /home/jamulus/consolidated/
# add sudo capabilities to Apache for 2 commands
/bin/cat <<EOF > jamulus-sudoers.txt
Cmnd_Alias JAMREC_OPS = /bin/systemctl kill -s SIGUSR1 $servicename, /bin/systemctl kill -s SIGUSR2 $servicename
www-data ALL=(ALL) NOPASSWD:JAMREC_OPS
Defaults:www-data !requiretty
EOF
# open firewall for Web console
ufw allow http
sudo cp jamulus-sudoers.txt /etc/sudoers.d/jamulus
echo "Starting server '$servername'"
sudo systemctl daemon-reload
sudo systemctl start $servicename
sudo systemctl enable $servicename
else
echo -n "JAMULUS RECORDING REMOTE INSTALLATION canceled."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment