strummolo/deploy.sh

306 рядки
7.1 KiB
Bash
Executable File

#!/bin/bash
# This script install the following components and their dependencies:
# - pulseaudio
# - Go
# - Ruby
# - Python3 (at least 3.6)
# - liquidsoap
# - barnard
# - botamusique
# - tmuxinator (optional)
# - NGINX (optional)
#
# This solution relies on a pre-existing Mumble instance.
#
# This script works ONLY on latest Debian systems - buster, atm - and it will exit if the system differs
#
# After the installation we'll have this infrastructure:
# * a streaming daemon by liquidsoap
# * a commandline mumble client that streams to liquidsoap
# * a mumble bot to play music
# * all these softwares run into a tmux session (optionally spawned by tmuxinator)
# * NGINX is an optional software to expose the botamusique web interface
#
# Author: bisco <bisco@autistici.org>
# The script is released under GNU General Public License v3 or later.
# Variables
CONFDIR="conf"
LIQCONF="${CONFDIR}/strummolo.liq"
TMUXCONF="${CONFDIR}/tmux.conf"
BOTAMCONF="${CONFDIR}/strummolo.ini"
NGINXCONF="${CONFDIR}/nginx_vhost.conf"
TXTORCONF="${CONFDIR}/tmuxinator.yml"
MUMNICK="strummolo"
BOTNICK="jukebox"
MUMCHAN="mystrumblingchan"
USERNAME="strummolo"
# TODO
# - make this script idempotent
# - daemonize the mumble client (maybe replaced by a bot, if it works into the infrastructure)
# - uwsgify botamusique for better performances
# Code - do not edit below unless you know what you're doing
### Exit on errors
set -e
### check_error function
### Check if things went all done when exit
check_error()
{
if [ ! $? = 0 ]; then
echo "====> ERROR!"
exit
fi
}
### trap built-in command
### Run "check_error" function on exit process status
trap check_error EXIT
### check_root function
### Check if the script has been ran by root (or sudo)
check_root()
{
if [ "$(id -u)" == "0" ];
then
echo "[OK] Check root permissions"
else
echo "[FAIL] Check root permissions"
echo "[INFO] Run this script as root or sudo"
exit 1
fi
}
### check_os function
### Check if the OS is a Debian Buster (10.x) otherwise the script exits
check_os()
{
if [ -e /etc/debian_version ];
then
if [[ $(cat /etc/debian_version) == "10"* ]];
then
echo "[OK] Check OS version"
else
echo "[FAIL] Check OS version"
echo "[INFO] Debian Buster not found"
exit 1
fi
else
echo "[FAIL] Check OS version"
echo "[INFO] Debian system not found"
exit 1
fi
}
### check_network function
### Check if network properly works otherwise the script exits
check_network()
{
ping -c 3 -q 8.8.8.8
if [ $? == 0 ];
then
echo "[OK] Check Network"
else
echo "[FAIL] Check Network"
exit 1
fi
}
### update_repo function
### Update the package repositories
update_repo()
{
apt-get -qq update
if [ $? == 0 ];
then
echo "[OK] Updating repository"
else
echo "[FAIL] Updating repository"
exit 1
fi
}
### liq_repo function
### Install liquidsoap's repository
liq_repo()
{
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 20D63CCDDD0F62C2
if [ $? == 0 ];
then
echo "[OK] Adding Liquidsoap's APT key"
else
echo "[FAIL] Adding Liquidsoap's APT key"
exit 1
fi
echo deb http://deb.debian.org/debian/ buster contrib non-free > /etc/apt/sources.list.d/strummolo.list
echo deb http://deb.liquidsoap.info/debian stable main > /etc/apt/sources.list.d/liquidsoap.list
if [ $? == 0 ];
then
echo "[OK] Adding Liquidsoap's APT Repo"
else
echo "[FAIL] Adding Liquidsoap's APT Repo"
exit 1
fi
}
### install_pre function
install_pre()
{
apt-get -qq install -y \
curl \
gnupg
}
### install_deps function
### Install needed packages
install_deps()
{
apt-get -qq install -y \
build-essential \
pulseaudio \
liquidsoap-master \
golang \
tmux \
python3-dev \
libjpeg-dev \
zlib1g-dev \
libtiff5 \
opus-tools \
ffmpeg \
git \
libopenal-dev \
python3-venv
if [ $? == 0 ];
then
echo "[OK] Dependencies installation"
else
echo "[FAIL] Dependencies installation"
echo "[INFO] Please read the error log to solve the problem"
exit 1
fi
}
### create_user function
### Creates the custom user for our bundle software
create_user()
{
set +e
id -u $USERNAME >/dev/null 2>&1
if [ $? == 0 ];
then
echo "[FAIL] User creation"
echo "[INFO] User $USERNAME exists. Please remove the user and its home directory"
else
useradd -m -s /bin/bash $USERNAME
echo "[OK] User creation"
fi
set -e
}
### install_barnard function
### Install Barnard, a mumble text-based client written in Go
install_pkgs()
{
su - ${USERNAME} -c "go get -u layeh.com/barnard"
if [ $? == 0 ];
then
echo "[OK] Barnard (Mumble text client)"
else
echo "[FAIL] Barnard (Mumble text client)"
echo "[INFO] Please read the error log to solve the problem"
exit 1
fi
su - ${USERNAME} -c "mkdir -p musicbot"
su - ${USERNAME} -c "curl -Lo botamusique.tar.gz http://packages.azlux.fr/botamusique/sources.tar.gz"
su - ${USERNAME} -c "tar -xzf botamusique.tar.gz -C musicbot"
su - ${USERNAME} -c "python3 -m venv musicbot"
su - ${USERNAME} -c "/home/${USERNAME}/musicbot/bin/pip install --upgrade pip"
su - ${USERNAME} -c "/home/${USERNAME}/musicbot/bin/pip install wheel"
su - ${USERNAME} -c "/home/${USERNAME}/musicbot/bin/pip install -r musicbot/botamusique/requirements.txt"
if [ $? == 0 ];
then
echo "[OK] Botamusique (Mumble bot)"
else
echo "[FAIL] Botamusique (Mumble bot)"
echo "[INFO] Please read the error log to solve the problem"
exit 1
fi
}
### configure_bundle function
### Copy/create software configuration files
configure_bundle()
{
cp $TMUXCONF /home/${USERNAME}/.tmux.conf
chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.tmux.conf
su - ${USERNAME} -c "mkdir -p /home/${USERNAME}/liq"
cp $LIQCONF /home/${USERNAME}/liq/
chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/liq
cp $BOTAMCONF /home/${USERNAME}/musicbot/botamusique/
chown ${USERNAME}:${USERNAME} /home/${USERNAME}/musicbot/botamusique/strummolo.ini
if [ $? == 0 ];
then
echo "[OK] Configuration files copied"
else
echo "[FAIL] Configuration files copied"
echo "[INFO] Please read the error log to solve the problem"
exit 1
fi
}
### usage function
### self-explainatory
usage()
{
echo "Usage: $0 [option]";
echo "";
echo "Options available:"
echo "-s|--system = check the system for the bundle";
echo "-i|--install = install the bundle software";
echo "-h|--help = show this message and exit";
echo "";
exit 1;
}
case $1 in
-s | --system)
check_root;
check_os;
check_network;;
-i | --install)
check_root;
check_os;
check_network;
update_repo;
install_pre;
liq_repo;
update_repo;
install_deps;
create_user;
install_pkgs;
configure_bundle;;
-h | --help | *)
usage;;
esac