From f47ed8cc36539ec8cecdb249e79447880842d1c6 Mon Sep 17 00:00:00 2001 From: bisco Date: Sun, 17 May 2020 11:42:09 +0200 Subject: [PATCH] initial release --- conf/strummolo.ini | 70 +++++++++++ conf/strummolo.liq | 10 ++ conf/tmux.conf | 74 +++++++++++ deploy.sh | 306 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 460 insertions(+) create mode 100644 conf/strummolo.ini create mode 100644 conf/strummolo.liq create mode 100644 conf/tmux.conf create mode 100755 deploy.sh diff --git a/conf/strummolo.ini b/conf/strummolo.ini new file mode 100644 index 0000000..0300b08 --- /dev/null +++ b/conf/strummolo.ini @@ -0,0 +1,70 @@ +### stripped botamusique configuration file +[server] +host = mumble.esiliati.org +port = 64738 +#password = +channel = Napoli/MSAck/streaming +#tokens = token1,token2 +#certificate = + +[bot] +username = jukebox +volume = 0.1 +playback_mode = one-shot +autoplay_length = 5 +clear_when_stop_in_oneshot = False +target_version = stable +admin = picard;nt;vzzz;shadow.penguin +music_folder = music/ +database_path = database.db +tmp_folder = /tmp/ +tmp_folder_max_size = 200 +ignored_folders = tmp +ignored_files = Thumbs.db +download_attempts = 3 +auto_check_update = True +pip3_path = bin/pip +logfile = bam-cli.log +announce_current_music = True +allow_other_channel_message = False +allow_private_message = True +save_music_library = True +refresh_cache_on_startup = True +save_playlist = True +max_track_playlist = 20 +max_track_duration = 60 +ducking = True +ducking_volume = 0.05 +ducking_threshold = 3000 +when_nobody_in_channel = nothing + + +[webinterface] +enabled = True +listening_addr = 127.0.0.1 +listening_port = 8181 +is_web_proxified = False +web_logfile = bam-web.log + +require_auth = True +user = strummolo +password = tiriteppolo + +[debug] +ffmpeg = False +mumbleConnection = False + +[radio] +#ponyville = http://192.99.131.205:8000/stream.mp3 "Here a command of !radio comment" +#luna = http://radio.ponyvillelive.com:8002/stream "calm and orchestra music" +#radiobrony = http://62.210.138.34:8000/live "Borny music of a friend" +#celestiaradio = http://celestia.aiverse.org:8000/mp3_256 +#jazz = http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3 "Jazz Yeah !" + + +[commands] +command_symbol = !:! +split_username_at_space = False + +[strings] +# this section is left blank diff --git a/conf/strummolo.liq b/conf/strummolo.liq new file mode 100644 index 0000000..1e3c014 --- /dev/null +++ b/conf/strummolo.liq @@ -0,0 +1,10 @@ +# Liquidsoap configuration +output.icecast( + %mp3(bitrate=128, samplerate=44100, stereo=true), + mount="/yourmountpoint.mp3", + host="your.streaming.server.url", + port=80, + user="username", + password="password", + name="yourstreamingname", +input.pulseaudio(device="mumble.monitor")); \ No newline at end of file diff --git a/conf/tmux.conf b/conf/tmux.conf new file mode 100644 index 0000000..eb2f492 --- /dev/null +++ b/conf/tmux.conf @@ -0,0 +1,74 @@ +# use ISO-8859-1 +#set -g iso8859-1 +#set-window-option -g iso8859-1 on +#set -g utf8 +#set-window-option -g utf8 on + +# make tmux display things in 256 colors +setw -g xterm-keys on +set -g default-terminal "screen-256color" + +# set scrollback history to 10000 (10k) +set -g history-limit 10000 + +# fixes shift-pageup/shift-pagedown +#set -ga terminal-overrides 'xterm*:smcup@:rmcup@' + +# shorten command delay +set -sg escape-time 1 + +# set window and pane index to 1 (0 by default) +set-option -g base-index 1 +setw -g pane-base-index 1 + +# reload ~/.tmux.conf using PREFIX r +bind r source-file ~/.tmux.conf \; display "Reloaded!" + +# make the current window the first window +bind T swap-window -t 1 + +set -g mouse on + +# bind WheelUp and WheelDown for scroll +bind-key -T root WheelUpPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M" +#bind-key -t vi-copy WheelUpPane halfpage-up +#bind-key -t vi-copy WheelDownPane halfpage-down + +# bind PageUp for copy-mode +bind-key S-Pageup copy-mode -u + +# bind S to toggle synchronize-panes +bind-key S set-window-option synchronize-panes \; display "synchronize-panes is now #{?pane_synchronized,on,off}" + + +# ---------------------- +# set some pretty colors +# ---------------------- +# set pane colors - hilight the active pane +set-option -g pane-border-style fg=colour235 #base02 +set-option -g pane-active-border-style fg=colour240 #base01 + + +# colorize messages in the command line +set-option -g message-style bg=black,fg=brightred #base02 + + +# ---------------------- +# Status Bar +# ----------------------- +set-option -g status on # turn the status bar on +#set -g status-utf-8 on # set utf-8 for the status bar +set -g status-interval 5 # set update frequencey (default 15 seconds) + +### solarized ### +set-option -g status-style bg=colour235,fg=colour130 #base02 // 235 +set-window-option -g window-status-style fg=colour33,bg=default #base0 // 224 +set-window-option -g window-status-current-style fg=colour196,bg=default #orange // 166 + +# visual notification of activity in other windows +setw -g monitor-activity on +set -g visual-activity on + +set -g status-right-length 150 +set -g status-right "#H | Load:#(uptime | awk -F "average:" '{print $2}') | %d-%b-%Y - %H:%M " + diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..0fc366b --- /dev/null +++ b/deploy.sh @@ -0,0 +1,306 @@ +#!/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 +# 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 \ No newline at end of file