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.6KB

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