You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jitsi-meet-web-config.postinst 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/bin/bash
  2. # postinst script for jitsi-meet-web-config
  3. #
  4. # see: dh_installdeb(1)
  5. set -e
  6. # summary of how this script can be called:
  7. # * <postinst> `configure' <most-recently-configured-version>
  8. # * <old-postinst> `abort-upgrade' <new version>
  9. # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  10. # <new-version>
  11. # * <postinst> `abort-remove'
  12. # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  13. # <failed-install-package> <version> `removing'
  14. # <conflicting-package> <version>
  15. # for details, see http://www.debian.org/doc/debian-policy/ or
  16. # the debian-policy package
  17. case "$1" in
  18. configure)
  19. # loading debconf
  20. . /usr/share/debconf/confmodule
  21. # try to get host from jitsi-videobridge
  22. db_get jitsi-videobridge/jvb-hostname
  23. if [ -z "$RET" ] ; then
  24. # server hostname
  25. db_set jitsi-videobridge/jvb-hostname "localhost"
  26. db_input critical jitsi-videobridge/jvb-hostname || true
  27. db_go
  28. fi
  29. JVB_HOSTNAME="$RET"
  30. # detect dpkg-reconfigure
  31. RECONFIGURING="false"
  32. db_get jitsi-meet/jvb-hostname
  33. JVB_HOSTNAME_OLD=$RET
  34. if [ -n "$RET" ] && [ ! "$JVB_HOSTNAME_OLD" = "$JVB_HOSTNAME" ] ; then
  35. RECONFIGURING="true"
  36. rm -f /etc/jitsi/meet/$JVB_HOSTNAME_OLD-config.js
  37. fi
  38. JVB_SERVE="false"
  39. # this detect only old installations
  40. db_get jitsi-meet/jvb-serve || true
  41. if [ -n "$RET" ] && [ "$RET" = "true" ] ; then
  42. JVB_SERVE="true"
  43. fi
  44. # stores the hostname so we will reuse it later, like in purge
  45. db_set jitsi-meet/jvb-hostname $JVB_HOSTNAME
  46. NGINX_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'nginx' 2>/dev/null | awk '{print $3}' || true)"
  47. NGINX_EXTRAS_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'nginx-extras' 2>/dev/null | awk '{print $3}' || true)"
  48. if [ "$NGINX_INSTALL_CHECK" = "installed" ] \
  49. || [ "$NGINX_INSTALL_CHECK" = "unpacked" ] \
  50. || [ "$NGINX_EXTRAS_INSTALL_CHECK" = "installed" ] \
  51. || [ "$NGINX_EXTRAS_INSTALL_CHECK" = "unpacked" ] ; then
  52. FORCE_NGINX="true"
  53. fi
  54. APACHE_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'apache2' 2>/dev/null | awk '{print $3}' || true)"
  55. if [ "$APACHE_INSTALL_CHECK" = "installed" ] || [ "$APACHE_INSTALL_CHECK" = "unpacked" ] ; then
  56. FORCE_APACHE="true"
  57. fi
  58. # if first time config ask for certs, or if we are reconfiguring
  59. if [ -z "$JVB_HOSTNAME_OLD" ] || [ "$RECONFIGURING" = "true" ] ; then
  60. # SSL for nginx
  61. db_get jitsi-meet/cert-choice
  62. CERT_CHOICE="$RET"
  63. UPLOADED_CERT_CHOICE="I want to use my own certificate"
  64. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  65. db_set jitsi-meet/cert-path-key "/etc/ssl/$JVB_HOSTNAME.key"
  66. db_input critical jitsi-meet/cert-path-key || true
  67. db_go
  68. db_get jitsi-meet/cert-path-key
  69. CERT_KEY="$RET"
  70. db_set jitsi-meet/cert-path-crt "/etc/ssl/$JVB_HOSTNAME.crt"
  71. db_input critical jitsi-meet/cert-path-crt || true
  72. db_go
  73. db_get jitsi-meet/cert-path-crt
  74. CERT_CRT="$RET"
  75. else
  76. # create self-signed certs
  77. CERT_KEY="/etc/jitsi/meet/$JVB_HOSTNAME.key"
  78. CERT_CRT="/etc/jitsi/meet/$JVB_HOSTNAME.crt"
  79. HOST="$( (hostname -s; echo localhost) | head -n 1)"
  80. DOMAIN="$( (hostname -d; echo localdomain) | head -n 1)"
  81. openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj \
  82. "/O=$DOMAIN/OU=$HOST/CN=$JVB_HOSTNAME/emailAddress=webmaster@$HOST.$DOMAIN" \
  83. -keyout $CERT_KEY \
  84. -out $CERT_CRT
  85. fi
  86. fi
  87. # jitsi meet
  88. JITSI_MEET_CONFIG="/etc/jitsi/meet/$JVB_HOSTNAME-config.js"
  89. if [ ! -f $JITSI_MEET_CONFIG ] ; then
  90. cp /usr/share/jitsi-meet-web-config/config.js $JITSI_MEET_CONFIG
  91. # replaces needed config for multidomain as it works only with nginx
  92. sed -i "s/conference.jitsi-meet.example.com/conference.<\!--# echo var=\"subdomain\" default=\"\" -->jitsi-meet.example.com/g" $JITSI_MEET_CONFIG
  93. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" $JITSI_MEET_CONFIG
  94. fi
  95. JVB_CONFIG="/etc/jitsi/videobridge/sip-communicator.properties"
  96. # this is new install let's configure jvb to serve meet
  97. # no-nginx, no-apache installed on machine, this is new install or reconfiguring old one which have jvb_serve set
  98. if [[ "$JVB_SERVE" = "true" ]] ; then
  99. echo ""
  100. echo "------------------------------------------------"
  101. echo "You are using jetty to serve jitsi-meet, it is recommended to uninstall(purge) and use default installation that comes with nginx!"
  102. echo ""
  103. echo "When using the following command, any custom config will be LOST, please backup /etc/jitsi !!!"
  104. echo ""
  105. echo "You can purge your installation using the following command:"
  106. echo "apt-get purge jitsi-meet jitsi-meet-web-config jitsi-meet-prosody jitsi-meet-web jicofo jitsi-videobridge"
  107. echo "------------------------------------------------"
  108. echo ""
  109. elif [[ "$FORCE_NGINX" = "true" && ( -z "$JVB_HOSTNAME_OLD" || "$RECONFIGURING" = "true" ) ]] ; then
  110. # disables tcp harvester to make sure jvb will not take port 443
  111. if [[ -f $JVB_CONFIG ]] && ! grep -q "org.jitsi.videobridge.DISABLE_TCP_HARVESTER" "$JVB_CONFIG" ;then
  112. echo "org.jitsi.videobridge.DISABLE_TCP_HARVESTER=true" >> $JVB_CONFIG
  113. invoke-rc.d jvb restart || true
  114. fi
  115. # this is a reconfigure, lets just delete old links
  116. if [ "$RECONFIGURING" = "true" ] ; then
  117. rm -f /etc/nginx/sites-enabled/$JVB_HOSTNAME_OLD.conf
  118. rm -f /etc/jitsi/meet/$JVB_HOSTNAME_OLD-config.js
  119. fi
  120. # nginx conf
  121. if [ ! -f /etc/nginx/sites-available/$JVB_HOSTNAME.conf ] ; then
  122. cp /usr/share/jitsi-meet-web-config/jitsi-meet.example /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  123. if [ ! -f /etc/nginx/sites-enabled/$JVB_HOSTNAME.conf ] ; then
  124. ln -s /etc/nginx/sites-available/$JVB_HOSTNAME.conf /etc/nginx/sites-enabled/$JVB_HOSTNAME.conf
  125. fi
  126. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  127. fi
  128. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  129. # replace self-signed certificate paths with user provided ones
  130. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  131. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  132. sed -i "s/ssl_certificate_key\ \/etc\/jitsi\/meet\/.*key/ssl_certificate_key\ $CERT_KEY_ESC/g" \
  133. /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  134. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  135. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  136. sed -i "s/ssl_certificate\ \/etc\/jitsi\/meet\/.*crt/ssl_certificate\ $CERT_CRT_ESC/g" \
  137. /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  138. fi
  139. invoke-rc.d nginx reload || true
  140. elif [[ "$FORCE_APACHE" = "true" && ( -z "$JVB_HOSTNAME_OLD" || "$RECONFIGURING" = "true" ) ]] ; then
  141. # disables tcp harvester to make sure jvb will not take port 443
  142. if [[ -f $JVB_CONFIG ]] && ! grep -q "org.jitsi.videobridge.DISABLE_TCP_HARVESTER" "$JVB_CONFIG" ;then
  143. echo "org.jitsi.videobridge.DISABLE_TCP_HARVESTER=true" >> $JVB_CONFIG
  144. invoke-rc.d jvb restart || true
  145. fi
  146. # this is a reconfigure, lets just delete old links
  147. if [ "$RECONFIGURING" = "true" ] ; then
  148. a2dissite $JVB_HOSTNAME_OLD.conf
  149. rm -f /etc/jitsi/meet/$JVB_HOSTNAME_OLD-config.js
  150. fi
  151. # apache2 config
  152. if [ ! -f /etc/apache2/sites-available/$JVB_HOSTNAME.conf ] ; then
  153. # when creating new config, make sure all needed modules are enabled
  154. a2enmod rewrite ssl headers proxy_http include
  155. cp /usr/share/jitsi-meet-web-config/jitsi-meet.example-apache /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  156. a2ensite $JVB_HOSTNAME.conf
  157. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  158. fi
  159. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  160. # replace self-signed certificate paths with user provided ones
  161. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  162. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  163. sed -i "s/SSLCertificateKeyFile\ \/etc\/jitsi\/meet\/.*key/SSLCertificateKeyFile\ $CERT_KEY_ESC/g" \
  164. /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  165. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  166. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  167. sed -i "s/SSLCertificateFile\ \/etc\/jitsi\/meet\/.*crt/SSLCertificateFile\ $CERT_CRT_ESC/g" \
  168. /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  169. fi
  170. invoke-rc.d apache2 reload || true
  171. fi
  172. echo "----------------"
  173. echo ""
  174. echo "You can now switch to a Let’s Encrypt certificate. To do so, execute:"
  175. echo "/usr/share/jitsi-meet/scripts/install-letsencrypt-cert.sh"
  176. echo ""
  177. echo "----------------"
  178. # and we're done with debconf
  179. db_stop
  180. ;;
  181. abort-upgrade|abort-remove|abort-deconfigure)
  182. ;;
  183. *)
  184. echo "postinst called with unknown argument \`$1'" >&2
  185. exit 1
  186. ;;
  187. esac
  188. # dh_installdeb will replace this with shell code automatically
  189. # generated by other debhelper scripts.
  190. #DEBHELPER#
  191. exit 0