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 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. echo "------> $JVB_SERVE"
  45. # stores the hostname so we will reuse it later, like in purge
  46. db_set jitsi-meet/jvb-hostname $JVB_HOSTNAME
  47. NGINX_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'nginx' 2>/dev/null | awk '{print $3}' || true)"
  48. NGINX_EXTRAS_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'nginx-extras' 2>/dev/null | awk '{print $3}' || true)"
  49. if [ "$NGINX_INSTALL_CHECK" = "installed" ] \
  50. || [ "$NGINX_INSTALL_CHECK" = "unpacked" ] \
  51. || [ "$NGINX_EXTRAS_INSTALL_CHECK" = "installed" ] \
  52. || [ "$NGINX_EXTRAS_INSTALL_CHECK" = "unpacked" ] ; then
  53. FORCE_NGINX="true"
  54. fi
  55. APACHE_INSTALL_CHECK="$(dpkg-query -f '${Status}' -W 'apache2' 2>/dev/null | awk '{print $3}' || true)"
  56. if [ "$APACHE_INSTALL_CHECK" = "installed" ] || [ "$APACHE_INSTALL_CHECK" = "unpacked" ] ; then
  57. FORCE_APACHE="true"
  58. fi
  59. # if first time config ask for certs, or if we are reconfiguring
  60. if [ -z "$JVB_HOSTNAME_OLD" ] || [ "$RECONFIGURING" = "true" ] ; then
  61. # SSL for nginx
  62. db_get jitsi-meet/cert-choice
  63. CERT_CHOICE="$RET"
  64. UPLOADED_CERT_CHOICE="I want to use my own certificate"
  65. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  66. db_set jitsi-meet/cert-path-key "/etc/ssl/$JVB_HOSTNAME.key"
  67. db_input critical jitsi-meet/cert-path-key || true
  68. db_go
  69. db_get jitsi-meet/cert-path-key
  70. CERT_KEY="$RET"
  71. db_set jitsi-meet/cert-path-crt "/etc/ssl/$JVB_HOSTNAME.crt"
  72. db_input critical jitsi-meet/cert-path-crt || true
  73. db_go
  74. db_get jitsi-meet/cert-path-crt
  75. CERT_CRT="$RET"
  76. else
  77. # create self-signed certs
  78. CERT_KEY="/etc/jitsi/meet/$JVB_HOSTNAME.key"
  79. CERT_CRT="/etc/jitsi/meet/$JVB_HOSTNAME.crt"
  80. HOST="$( (hostname -s; echo localhost) | head -n 1)"
  81. DOMAIN="$( (hostname -d; echo localdomain) | head -n 1)"
  82. openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj \
  83. "/O=$DOMAIN/OU=$HOST/CN=$JVB_HOSTNAME/emailAddress=webmaster@$HOST.$DOMAIN" \
  84. -keyout $CERT_KEY \
  85. -out $CERT_CRT
  86. fi
  87. fi
  88. # jitsi meet
  89. JITSI_MEET_CONFIG="/etc/jitsi/meet/$JVB_HOSTNAME-config.js"
  90. if [ ! -f $JITSI_MEET_CONFIG ] ; then
  91. cp /usr/share/jitsi-meet-web-config/config.js $JITSI_MEET_CONFIG
  92. # replaces needed config for multidomain as it works only with nginx
  93. sed -i "s/conference.jitsi-meet.example.com/conference.<\!--# echo var=\"subdomain\" default=\"\" -->jitsi-meet.example.com/g" $JITSI_MEET_CONFIG
  94. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" $JITSI_MEET_CONFIG
  95. fi
  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!!!"
  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. # this is a reconfigure, lets just delete old links
  111. if [ "$RECONFIGURING" = "true" ] ; then
  112. rm -f /etc/nginx/sites-enabled/$JVB_HOSTNAME_OLD.conf
  113. rm -f /etc/jitsi/meet/$JVB_HOSTNAME_OLD-config.js
  114. fi
  115. # nginx conf
  116. if [ ! -f /etc/nginx/sites-available/$JVB_HOSTNAME.conf ] ; then
  117. cp /usr/share/jitsi-meet-web-config/jitsi-meet.example /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  118. if [ ! -f /etc/nginx/sites-enabled/$JVB_HOSTNAME.conf ] ; then
  119. ln -s /etc/nginx/sites-available/$JVB_HOSTNAME.conf /etc/nginx/sites-enabled/$JVB_HOSTNAME.conf
  120. fi
  121. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  122. fi
  123. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  124. # replace self-signed certificate paths with user provided ones
  125. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  126. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  127. sed -i "s/ssl_certificate_key\ \/etc\/jitsi\/meet\/.*key/ssl_certificate_key\ $CERT_KEY_ESC/g" \
  128. /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  129. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  130. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  131. sed -i "s/ssl_certificate\ \/etc\/jitsi\/meet\/.*crt/ssl_certificate\ $CERT_CRT_ESC/g" \
  132. /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  133. fi
  134. invoke-rc.d nginx reload || true
  135. elif [[ "$FORCE_APACHE" = "true" && ( -z "$JVB_HOSTNAME_OLD" || "$RECONFIGURING" = "true" ) ]] ; then
  136. # this is a reconfigure, lets just delete old links
  137. if [ "$RECONFIGURING" = "true" ] ; then
  138. a2dissite $JVB_HOSTNAME_OLD.conf
  139. rm -f /etc/jitsi/meet/$JVB_HOSTNAME_OLD-config.js
  140. fi
  141. # apache2 config
  142. if [ ! -f /etc/apache2/sites-available/$JVB_HOSTNAME.conf ] ; then
  143. # when creating new config, make sure all needed modules are enabled
  144. a2enmod rewrite ssl headers proxy_http include
  145. cp /usr/share/jitsi-meet-web-config/jitsi-meet.example-apache /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  146. a2ensite $JVB_HOSTNAME.conf
  147. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  148. fi
  149. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  150. # replace self-signed certificate paths with user provided ones
  151. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  152. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  153. sed -i "s/SSLCertificateKeyFile\ \/etc\/jitsi\/meet\/.*key/SSLCertificateKeyFile\ $CERT_KEY_ESC/g" \
  154. /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  155. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  156. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  157. sed -i "s/SSLCertificateFile\ \/etc\/jitsi\/meet\/.*crt/SSLCertificateFile\ $CERT_CRT_ESC/g" \
  158. /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  159. fi
  160. invoke-rc.d apache2 reload || true
  161. fi
  162. echo "----------------"
  163. echo ""
  164. echo "You can now switch to a Let’s Encrypt certificate. To do so, execute:"
  165. echo "/usr/share/jitsi-meet/scripts/install-letsencrypt-cert.sh"
  166. echo ""
  167. echo "----------------"
  168. # and we're done with debconf
  169. db_stop
  170. ;;
  171. abort-upgrade|abort-remove|abort-deconfigure)
  172. ;;
  173. *)
  174. echo "postinst called with unknown argument \`$1'" >&2
  175. exit 1
  176. ;;
  177. esac
  178. # dh_installdeb will replace this with shell code automatically
  179. # generated by other debhelper scripts.
  180. #DEBHELPER#
  181. exit 0