freedombone-app-jitsi 14KB

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