Strummolo installs a gizmo for a mumble-based streaming radio
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #!/bin/bash
  2. # This script install the following components and their dependencies:
  3. # - pulseaudio
  4. # - Go
  5. # - Ruby
  6. # - Python3 (at least 3.6)
  7. # - liquidsoap
  8. # - barnard
  9. # - botamusique
  10. # - tmuxinator (optional)
  11. # - NGINX (optional)
  12. #
  13. # This solution relies on a pre-existing Mumble instance.
  14. #
  15. # This script works ONLY on latest Debian systems - buster, atm - and it will exit if the system differs
  16. #
  17. # After the installation we'll have this infrastructure:
  18. # * a streaming daemon by liquidsoap
  19. # * a commandline mumble client that streams to liquidsoap
  20. # * a mumble bot to play music
  21. # * all these softwares run into a tmux session (optionally spawned by tmuxinator)
  22. # * NGINX is an optional software to expose the botamusique web interface
  23. #
  24. # Author: bisco <bisco@autistici.org>
  25. # The script is released under GNU General Public License v3 or later.
  26. # Variables
  27. CONFDIR="conf"
  28. LIQCONF="${CONFDIR}/strummolo.liq"
  29. TMUXCONF="${CONFDIR}/tmux.conf"
  30. BOTAMCONF="${CONFDIR}/strummolo.ini"
  31. NGINXCONF="${CONFDIR}/nginx_vhost.conf"
  32. TXTORCONF="${CONFDIR}/tmuxinator.yml"
  33. MUMNICK="strummolo"
  34. BOTNICK="jukebox"
  35. MUMCHAN="mystrumblingchan"
  36. USERNAME="strummolo"
  37. # TODO
  38. # - make this script idempotent
  39. # - daemonize the mumble client (maybe replaced by a bot, if it works into the infrastructure)
  40. # - uwsgify botamusique for better performances
  41. # Code - do not edit below unless you know what you're doing
  42. ### Exit on errors
  43. set -e
  44. ### check_error function
  45. ### Check if things went all done when exit
  46. check_error()
  47. {
  48. if [ ! $? = 0 ]; then
  49. echo "====> ERROR!"
  50. exit
  51. fi
  52. }
  53. ### trap built-in command
  54. ### Run "check_error" function on exit process status
  55. trap check_error EXIT
  56. ### check_root function
  57. ### Check if the script has been ran by root (or sudo)
  58. check_root()
  59. {
  60. if [ "$(id -u)" == "0" ];
  61. then
  62. echo "[OK] Check root permissions"
  63. else
  64. echo "[FAIL] Check root permissions"
  65. echo "[INFO] Run this script as root or sudo"
  66. exit 1
  67. fi
  68. }
  69. ### check_os function
  70. ### Check if the OS is a Debian Buster (10.x) otherwise the script exits
  71. check_os()
  72. {
  73. if [ -e /etc/debian_version ];
  74. then
  75. if [[ $(cat /etc/debian_version) == "10"* ]];
  76. then
  77. echo "[OK] Check OS version"
  78. else
  79. echo "[FAIL] Check OS version"
  80. echo "[INFO] Debian Buster not found"
  81. exit 1
  82. fi
  83. else
  84. echo "[FAIL] Check OS version"
  85. echo "[INFO] Debian system not found"
  86. exit 1
  87. fi
  88. }
  89. ### check_network function
  90. ### Check if network properly works otherwise the script exits
  91. check_network()
  92. {
  93. ping -c 3 -q 8.8.8.8
  94. if [ $? == 0 ];
  95. then
  96. echo "[OK] Check Network"
  97. else
  98. echo "[FAIL] Check Network"
  99. exit 1
  100. fi
  101. }
  102. ### update_repo function
  103. ### Update the package repositories
  104. update_repo()
  105. {
  106. apt-get -qq update
  107. if [ $? == 0 ];
  108. then
  109. echo "[OK] Updating repository"
  110. else
  111. echo "[FAIL] Updating repository"
  112. exit 1
  113. fi
  114. }
  115. ### liq_repo function
  116. ### Install liquidsoap's repository
  117. liq_repo()
  118. {
  119. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 20D63CCDDD0F62C2
  120. if [ $? == 0 ];
  121. then
  122. echo "[OK] Adding Liquidsoap's APT key"
  123. else
  124. echo "[FAIL] Adding Liquidsoap's APT key"
  125. exit 1
  126. fi
  127. echo deb http://deb.debian.org/debian/ buster contrib non-free > /etc/apt/sources.list.d/strummolo.list
  128. echo deb http://deb.liquidsoap.info/debian stable main > /etc/apt/sources.list.d/liquidsoap.list
  129. if [ $? == 0 ];
  130. then
  131. echo "[OK] Adding Liquidsoap's APT Repo"
  132. else
  133. echo "[FAIL] Adding Liquidsoap's APT Repo"
  134. exit 1
  135. fi
  136. }
  137. ### install_pre function
  138. install_pre()
  139. {
  140. apt-get -qq install -y \
  141. curl \
  142. gnupg
  143. }
  144. ### install_deps function
  145. ### Install needed packages
  146. install_deps()
  147. {
  148. apt-get -qq install -y \
  149. build-essential \
  150. pulseaudio \
  151. liquidsoap-master \
  152. golang \
  153. tmux \
  154. python3-dev \
  155. libjpeg-dev \
  156. zlib1g-dev \
  157. libtiff5 \
  158. opus-tools \
  159. ffmpeg \
  160. git \
  161. libopenal-dev \
  162. python3-venv
  163. if [ $? == 0 ];
  164. then
  165. echo "[OK] Dependencies installation"
  166. else
  167. echo "[FAIL] Dependencies installation"
  168. echo "[INFO] Please read the error log to solve the problem"
  169. exit 1
  170. fi
  171. }
  172. ### create_user function
  173. ### Creates the custom user for our bundle software
  174. create_user()
  175. {
  176. set +e
  177. id -u $USERNAME >/dev/null 2>&1
  178. if [ $? == 0 ];
  179. then
  180. echo "[FAIL] User creation"
  181. echo "[INFO] User $USERNAME exists. Please remove the user and its home directory"
  182. else
  183. useradd -m -s /bin/bash $USERNAME
  184. echo "[OK] User creation"
  185. fi
  186. set -e
  187. }
  188. ### install_barnard function
  189. ### Install Barnard, a mumble text-based client written in Go
  190. install_pkgs()
  191. {
  192. su - ${USERNAME} -c "go get -u layeh.com/barnard"
  193. if [ $? == 0 ];
  194. then
  195. echo "[OK] Barnard (Mumble text client)"
  196. else
  197. echo "[FAIL] Barnard (Mumble text client)"
  198. echo "[INFO] Please read the error log to solve the problem"
  199. exit 1
  200. fi
  201. su - ${USERNAME} -c "mkdir -p musicbot"
  202. su - ${USERNAME} -c "curl -Lo botamusique.tar.gz http://packages.azlux.fr/botamusique/sources.tar.gz"
  203. su - ${USERNAME} -c "tar -xzf botamusique.tar.gz -C musicbot"
  204. su - ${USERNAME} -c "python3 -m venv musicbot"
  205. su - ${USERNAME} -c "/home/${USERNAME}/musicbot/bin/pip install --upgrade pip"
  206. su - ${USERNAME} -c "/home/${USERNAME}/musicbot/bin/pip install wheel"
  207. su - ${USERNAME} -c "/home/${USERNAME}/musicbot/bin/pip install -r musicbot/botamusique/requirements.txt"
  208. if [ $? == 0 ];
  209. then
  210. echo "[OK] Botamusique (Mumble bot)"
  211. else
  212. echo "[FAIL] Botamusique (Mumble bot)"
  213. echo "[INFO] Please read the error log to solve the problem"
  214. exit 1
  215. fi
  216. }
  217. ### configure_bundle function
  218. ### Copy/create software configuration files
  219. configure_bundle()
  220. {
  221. cp $TMUXCONF /home/${USERNAME}/.tmux.conf
  222. chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.tmux.conf
  223. su - ${USERNAME} -c "mkdir -p /home/${USERNAME}/liq"
  224. cp $LIQCONF /home/${USERNAME}/liq/
  225. chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/liq
  226. cp $BOTAMCONF /home/${USERNAME}/musicbot/botamusique/
  227. chown ${USERNAME}:${USERNAME} /home/${USERNAME}/musicbot/botamusique/strummolo.ini
  228. if [ $? == 0 ];
  229. then
  230. echo "[OK] Configuration files copied"
  231. else
  232. echo "[FAIL] Configuration files copied"
  233. echo "[INFO] Please read the error log to solve the problem"
  234. exit 1
  235. fi
  236. }
  237. ### usage function
  238. ### self-explainatory
  239. usage()
  240. {
  241. echo "Usage: $0 [option]";
  242. echo "";
  243. echo "Options available:"
  244. echo "-s|--system = check the system for the bundle";
  245. echo "-i|--install = install the bundle software";
  246. echo "-h|--help = show this message and exit";
  247. echo "";
  248. exit 1;
  249. }
  250. case $1 in
  251. -s | --system)
  252. check_root;
  253. check_os;
  254. check_network;;
  255. -i | --install)
  256. check_root;
  257. check_os;
  258. check_network;
  259. update_repo;
  260. install_pre;
  261. liq_repo;
  262. update_repo;
  263. install_deps;
  264. create_user;
  265. install_pkgs;
  266. configure_bundle;;
  267. -h | --help | *)
  268. usage;;
  269. esac