freedombone-app-jitsi 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Jitsi meet + videobridge
  10. #
  11. # Instructions: https://github.com/jitsi/jitsi-meet/blob/master/doc/manual-install.md
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2016-2018 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. VARIANTS=""
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=0
  33. VIDEOBRIDGE_PORT=5347
  34. JITSI_ONION_PORT=8102
  35. JITSI_PORT=5280
  36. # domains
  37. JITSI_DOMAIN_NAME=
  38. JITSI_CODE=
  39. JITSI_ONION_HOSTNAME=
  40. jitsi_variables=(ONION_ONLY
  41. JITSI_DOMAIN_NAME
  42. JITSI_ONION_HOSTNAME
  43. JITSI_CODE
  44. DEFAULT_DOMAIN_NAME
  45. MY_USERNAME)
  46. function logging_on_jitsi {
  47. echo -n ''
  48. }
  49. function logging_off_jitsi {
  50. echo -n ''
  51. }
  52. function jitsi_disable_google_spyware {
  53. # Presumably they included Google Analytics for benign reasons, but it's
  54. # an obvious security problem. This should disable it.
  55. sed -i "s|Google Analytics|Google Spyware deactivated|g" /usr/share/jitsi-meet/analytics.js
  56. sed -i "s|www.google-analytics.com|${JITSI_DOMAIN_NAME}|g" /usr/share/jitsi-meet/analytics.js
  57. if ! grep -q '//ga(' /usr/share/jitsi-meet/analytics.js; then
  58. sed -i 's|ga(|//ga(|g' /usr/share/jitsi-meet/analytics.js
  59. fi
  60. if ! grep -q '//action +' /usr/share/jitsi-meet/analytics.js; then
  61. sed -i 's|action +|//action +|g' /usr/share/jitsi-meet/analytics.js
  62. fi
  63. sed -i "s|Google Analytics|Google Spyware deactivated|g" /usr/share/jitsi-meet/libs/analytics.js
  64. sed -i "s|www.google-analytics.com|${JITSI_DOMAIN_NAME}|g" /usr/share/jitsi-meet/libs/analytics.js
  65. if ! grep -q '//ga(' /usr/share/jitsi-meet/libs/analytics.js; then
  66. sed -i 's|ga(|//ga(|g' /usr/share/jitsi-meet/libs/analytics.js
  67. fi
  68. if ! grep -q '//action +' /usr/share/jitsi-meet/libs/analytics.js; then
  69. sed -i 's|action +|//action +|g' /usr/share/jitsi-meet/libs/analytics.js
  70. fi
  71. }
  72. function can_install_videobridge {
  73. check_architecture=$(uname -a)
  74. if [[ "$check_architecture" == *"amd64"* || "$check_architecture" == *"i386"* ]]; then
  75. echo "1"
  76. else
  77. echo "0"
  78. fi
  79. }
  80. function remove_jitsi_subdomains {
  81. function_check remove_onion_service
  82. remove_onion_service jitsi ${JITSI_ONION_PORT}
  83. }
  84. function remove_user_jitsi {
  85. remove_username="$1"
  86. }
  87. function add_user_jitsi {
  88. new_username="$1"
  89. new_user_password="$2"
  90. }
  91. function install_interactive_jitsi {
  92. if [ ! "${ONION_ONLY}" ]; then
  93. ONION_ONLY='no'
  94. fi
  95. if [[ ${ONION_ONLY} != "no" ]]; then
  96. JITSI_DOMAIN_NAME='jitsi.local'
  97. write_config_param "JITSI_DOMAIN_NAME" "$JITSI_DOMAIN_NAME"
  98. else
  99. function_check interactive_site_details
  100. interactive_site_details "jitsi" "JITSI_DOMAIN_NAME" "JITSI_CODE"
  101. fi
  102. APP_INSTALLED=1
  103. }
  104. function configure_interactive_jitsi {
  105. echo -n ''
  106. }
  107. function reconfigure_jitsi {
  108. echo -n ''
  109. }
  110. function upgrade_jitsi {
  111. jitsi_disable_google_spyware
  112. }
  113. function backup_local_jitsi {
  114. echo -n ''
  115. }
  116. function restore_local_jitsi {
  117. echo -n ''
  118. }
  119. function backup_remote_jitsi {
  120. echo -n ''
  121. }
  122. function restore_remote_jitsi {
  123. echo -n ''
  124. }
  125. function remove_jitsi {
  126. read_config_param JITSI_DOMAIN_NAME
  127. if [ ${#JITSI_DOMAIN_NAME} -eq 0 ]; then
  128. return
  129. fi
  130. if [ -f /etc/nginx/sites-available/${JITSI_DOMAIN_NAME} ]; then
  131. nginx_dissite ${JITSI_DOMAIN_NAME}
  132. if [ -d /var/www/${JITSI_DOMAIN_NAME} ]; then
  133. rm -rf /var/www/${JITSI_DOMAIN_NAME}
  134. fi
  135. rm /etc/nginx/sites-available/${JITSI_DOMAIN_NAME}
  136. function_check remove_certs
  137. remove_certs ${JITSI_DOMAIN_NAME}
  138. systemctl reload nginx
  139. fi
  140. remove_jitsi_subdomains
  141. systemctl stop prosody
  142. if [ -f /etc/prosody/conf.d/${JITSI_DOMAIN_NAME}.cfg.lua ]; then
  143. rm /etc/prosody/conf.d/${JITSI_DOMAIN_NAME}.cfg.lua
  144. fi
  145. if [ -f /etc/prosody/conf.avail/${JITSI_DOMAIN_NAME}.cfg.lua ]; then
  146. rm /etc/prosody/conf.avail/${JITSI_DOMAIN_NAME}.cfg.lua
  147. fi
  148. prosodyctl unregister focus auth.${JITSI_DOMAIN_NAME}
  149. systemctl start prosody
  150. remove_nodejs jitsi
  151. # remove videobridge
  152. firewall_remove ${VIDEOBRIDGE_PORT}
  153. firewall_remove "10000:20000"
  154. apt-get -yq remove --purge jitsi-videobridge jicofo jitsi-meet jitsi-meet-prosody
  155. if [ -d /etc/jitsi ]; then
  156. rm -rf /etc/jitsi
  157. fi
  158. if [ -d /usr/share/jitsi-videobridge ]; then
  159. rm -rf /usr/share/jitsi-videobridge
  160. fi
  161. if [ -d /usr/share/jitsi-meet ]; then
  162. rm -rf /usr/share/jitsi-meet
  163. fi
  164. if [ -d /etc/jitsi ]; then
  165. rm -rf /etc/jitsi
  166. fi
  167. sed -i "/jitsi/d" /etc/apt/sources.list
  168. rm /etc/apt/sources.list.d/jitsi*
  169. apt-get update
  170. remove_app jitsi
  171. remove_completion_param install_jitsi
  172. sed -i '/jitsi/d' "${COMPLETION_FILE}"
  173. function_check remove_ddns_domain
  174. remove_ddns_domain $JITSI_DOMAIN_NAME
  175. }
  176. function install_jitsi {
  177. if [[ "$(can_install_videobridge)" == "0" ]]; then
  178. echo $'jitsi meet/videobridge can only be installed on i386 or amd64 architectures'
  179. exit 83562
  180. fi
  181. if [ ! ${JITSI_DOMAIN_NAME} ]; then
  182. echo $'No domain name was given for jitsi'
  183. exit 47682
  184. fi
  185. if [ ! -d /etc/prosody ]; then
  186. echo $'xmpp must be installed before installing jitsi'
  187. exit 62394
  188. fi
  189. if [[ "${JITSI_DOMAIN_NAME}" == "${DEFAULT_DOMAIN_NAME}" ]]; then
  190. echo $'The jitsi domain name should not be the same as the main domain name'
  191. exit 78372
  192. fi
  193. # add jitsi repo
  194. jitsi_deb_repo=unstable #binary
  195. apt-get -yq install wget debconf-utils default-jre
  196. install_nodejs jitsi
  197. if ! npm install -g browserify@13.1.1; then
  198. remove_nodejs jitsi
  199. exit 638352
  200. fi
  201. if ! grep -q "jitsi" /etc/apt/sources.list; then
  202. echo "deb http://download.jitsi.org/nightly/deb ${jitsi_deb_repo}/" >> /etc/apt/sources.list
  203. fi
  204. wget -qO - https://download.jitsi.org/nightly/deb/${jitsi_deb_repo}/archive.key | apt-key add -
  205. apt-get update
  206. JITSI_ONION_HOSTNAME=$(add_onion_service jitsi 80 ${JITSI_ONION_PORT})
  207. # videobridge
  208. if [[ $ONION_ONLY == 'no' ]]; then
  209. debconf-set-selections <<< "jitsi-videobridge jitsi-videobridge/jvb-hostname string ${JITSI_DOMAIN_NAME}"
  210. else
  211. debconf-set-selections <<< "jitsi-videobridge jitsi-videobridge/jvb-hostname string ${JITSI_ONION_HOSTNAME}"
  212. fi
  213. apt-get -yq install jitsi-videobridge
  214. if [ ! -d /etc/jitsi ]; then
  215. echo $'Videobridge package failed to install'
  216. exit 63983
  217. fi
  218. firewall_add videobridge ${VIDEOBRIDGE_PORT}
  219. firewall_add_range jitsi 10000 20000 udp
  220. # meet
  221. debconf-set-selections <<< "jitsi-meet jitsi-meet/cert-choice multiselect 1"
  222. apt-get -yq install jitsi-meet jitsi-meet-prosody
  223. jitsi_nginx_site=/etc/nginx/sites-available/${JITSI_DOMAIN_NAME}
  224. if [ -f ${jitsi_nginx_site}.conf ]; then
  225. rm ${jitsi_nginx_site}.conf
  226. fi
  227. echo 'server_names_hash_bucket_size 64;' > $jitsi_nginx_site
  228. if [[ $ONION_ONLY == "no" ]]; then
  229. { echo '';
  230. echo 'server {';
  231. echo ' listen 80;';
  232. echo " server_name ${JITSI_DOMAIN_NAME};";
  233. echo " return 301 https://\$host\$request_uri;";
  234. echo '}';
  235. echo 'server {';
  236. echo ' listen 443 ssl;';
  237. echo ' #listen [::]:443 ssl;';
  238. echo " server_name ${JITSI_DOMAIN_NAME};";
  239. echo ''; } >> $jitsi_nginx_site
  240. function_check nginx_ssl
  241. nginx_ssl ${JITSI_DOMAIN_NAME}
  242. function_check nginx_security_options
  243. nginx_security_options ${JITSI_DOMAIN_NAME}
  244. { echo ' add_header Strict-Transport-Security max-age=15768000;';
  245. echo '';
  246. echo ' root /usr/share/jitsi-meet;';
  247. echo ' index index.html index.htm;';
  248. echo '';
  249. echo ' location /config.js {';
  250. echo " alias /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js;";
  251. echo ' }';
  252. echo '';
  253. echo ' location ~ ^/([a-zA-Z0-9=\?]+)$ {';
  254. echo ' rewrite ^/(.*)$ / break;';
  255. echo ' }';
  256. echo '';
  257. echo ' location / {';
  258. echo ' ssi on;';
  259. echo ' }';
  260. echo '';
  261. echo ' # Backward compatibility';
  262. echo ' location ~ /external_api.* {';
  263. echo ' root /usr/share/jitsi-meet/libs;';
  264. echo ' }';
  265. echo '';
  266. echo ' # Logs';
  267. echo ' access_log /dev/null;';
  268. echo ' error_log /dev/null;';
  269. echo '';
  270. echo ' # BOSH';
  271. echo ' location /http-bind {';
  272. echo ' proxy_pass http://localhost:5280/http-bind;';
  273. echo " proxy_set_header X-Forwarded-For \$remote_addr;";
  274. echo " proxy_set_header Host \$http_host;";
  275. echo ' }';
  276. echo '}'; } >> $jitsi_nginx_site
  277. fi
  278. { echo '';
  279. echo 'server {';
  280. echo " listen 127.0.0.1:$JITSI_ONION_PORT default_server;"; } >> $jitsi_nginx_site
  281. if [[ $ONION_ONLY == 'no' ]]; then
  282. echo " server_name ${JITSI_DOMAIN_NAME};" >> $jitsi_nginx_site
  283. else
  284. echo " server_name ${JITSI_ONION_HOSTNAME};" >> $jitsi_nginx_site
  285. fi
  286. { echo '';
  287. echo ' root /usr/share/jitsi-meet;';
  288. echo ' index index.html index.htm;';
  289. echo '';
  290. echo ' location /config.js {';
  291. echo " alias /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js;";
  292. echo ' }';
  293. echo '';
  294. echo ' location ~ ^/([a-zA-Z0-9=\?]+)$ {';
  295. echo ' rewrite ^/(.*)$ / break;';
  296. echo ' }';
  297. echo '';
  298. echo ' location / {';
  299. echo ' ssi off;';
  300. echo ' }';
  301. echo '';
  302. echo ' # Backward compatibility';
  303. echo ' location ~ /external_api.* {';
  304. echo ' root /usr/share/jitsi-meet/libs;';
  305. echo ' }';
  306. echo '';
  307. echo ' # Logs';
  308. echo ' access_log /dev/null;';
  309. echo ' error_log /dev/null;';
  310. echo '';
  311. echo ' # BOSH';
  312. echo ' location /http-bind {';
  313. echo ' proxy_pass http://localhost:5280/http-bind;';
  314. echo " proxy_set_header X-Forwarded-For \$remote_addr;";
  315. echo " proxy_set_header Host \$http_host;";
  316. echo ' }';
  317. echo '}'; } >> $jitsi_nginx_site
  318. sed -i "s|/var/www/${JITSI_DOMAIN_NAME}/htdocs|/usr/share/jitsi-meet|g" $jitsi_nginx_site
  319. if [ ! -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.pem ]; then
  320. if [ -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.crt ]; then
  321. rm /etc/ssl/certs/${JITSI_DOMAIN_NAME}.crt
  322. fi
  323. if [ -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.dhparam ]; then
  324. rm /etc/ssl/certs/${JITSI_DOMAIN_NAME}.dhparam
  325. fi
  326. function_check create_site_certificate
  327. create_site_certificate ${JITSI_DOMAIN_NAME} 'yes'
  328. if [[ "$ONION_ONLY" == "no" ]]; then
  329. if [ ! -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.pem ]; then
  330. exit 678363
  331. fi
  332. fi
  333. fi
  334. if [ -d /etc/letsencrypt ]; then
  335. usermod -a -G www-data jitsi
  336. usermod -a -G ssl-cert jitsi
  337. fi
  338. if [ -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.pem ]; then
  339. sed -i "s|.crt|.pem|g" /etc/prosody/conf.d/${JITSI_DOMAIN_NAME}.cfg.lua
  340. fi
  341. sed -i "s|key =.*|key = \"/etc/ssl/private/${JITSI_DOMAIN_NAME}.key\"|g" /etc/prosody/conf.avail/${JITSI_DOMAIN_NAME}.cfg.lua
  342. sed -i "s|certificate =.*|certificate = \"/etc/ssl/certs/${JITSI_DOMAIN_NAME}.pem\"|g" /etc/prosody/conf.avail/${JITSI_DOMAIN_NAME}.cfg.lua
  343. sed -i "s|enableWelcomePage:.*|enableWelcomePage: false,|g" /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js
  344. sed -i "s|disableStats:.*|disableStats: true,|g" /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js
  345. sed -i "s|minHDHeight:.*|minHDHeight: 800,|g" /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js
  346. sed -i "s|clientNode:.*|clientNode: 'https://${JITSI_DOMAIN_NAME}',|g" /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js
  347. sed -i "s|navigator.mozGetUserMedia|navigator.mediaDevices.getUserMedia|g" /usr/share/jitsi-meet/libs/lib-jitsi-meet.min.js
  348. # generated certs which aren't used
  349. if [ -f /usr/lib/ssl/certs/${JITSI_DOMAIN_NAME}.pem ]; then
  350. rm /usr/lib/ssl/certs/${JITSI_DOMAIN_NAME}.pem
  351. fi
  352. if [ -f /usr/lib/ssl/private/${JITSI_DOMAIN_NAME}.key ]; then
  353. rm /usr/lib/ssl/private/${JITSI_DOMAIN_NAME}.key
  354. fi
  355. if [ -f /usr/lib/ssl/certs/${JITSI_DOMAIN_NAME}.dhparam ]; then
  356. rm /usr/lib/ssl/certs/${JITSI_DOMAIN_NAME}.dhparam
  357. fi
  358. function_check nginx_ensite
  359. nginx_ensite ${JITSI_DOMAIN_NAME}
  360. set_completion_param "jitsi domain" "$JITSI_DOMAIN_NAME"
  361. jitsi_disable_google_spyware
  362. systemctl restart nginx
  363. systemctl restart prosody
  364. function_check add_ddns_domain
  365. add_ddns_domain $JITSI_DOMAIN_NAME
  366. APP_INSTALLED=1
  367. }