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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. UPLOADED_CERT_CHOICE="I want to use my own certificate"
  62. # if first time config ask for certs, or if we are reconfiguring
  63. if [ -z "$JVB_HOSTNAME_OLD" ] || [ "$RECONFIGURING" = "true" ] ; then
  64. db_get jitsi-meet/cert-choice
  65. CERT_CHOICE="$RET"
  66. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  67. db_set jitsi-meet/cert-path-key "/etc/ssl/$JVB_HOSTNAME.key"
  68. db_input critical jitsi-meet/cert-path-key || true
  69. db_go
  70. db_get jitsi-meet/cert-path-key
  71. CERT_KEY="$RET"
  72. db_set jitsi-meet/cert-path-crt "/etc/ssl/$JVB_HOSTNAME.crt"
  73. db_input critical jitsi-meet/cert-path-crt || true
  74. db_go
  75. db_get jitsi-meet/cert-path-crt
  76. CERT_CRT="$RET"
  77. else
  78. # create self-signed certs
  79. CERT_KEY="/etc/jitsi/meet/$JVB_HOSTNAME.key"
  80. CERT_CRT="/etc/jitsi/meet/$JVB_HOSTNAME.crt"
  81. HOST="$( (hostname -s; echo localhost) | head -n 1)"
  82. DOMAIN="$( (hostname -d; echo localdomain) | head -n 1)"
  83. openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj \
  84. "/O=$DOMAIN/OU=$HOST/CN=$JVB_HOSTNAME/emailAddress=webmaster@$HOST.$DOMAIN" \
  85. -keyout $CERT_KEY \
  86. -out $CERT_CRT \
  87. -reqexts SAN \
  88. -extensions SAN \
  89. -config <(cat /etc/ssl/openssl.cnf \
  90. <(printf "[SAN]\nsubjectAltName=DNS:localhost,DNS:$JVB_HOSTNAME"))
  91. fi
  92. fi
  93. # jitsi meet
  94. JITSI_MEET_CONFIG="/etc/jitsi/meet/$JVB_HOSTNAME-config.js"
  95. if [ ! -f $JITSI_MEET_CONFIG ] ; then
  96. cp /usr/share/jitsi-meet-web-config/config.js $JITSI_MEET_CONFIG
  97. # replaces needed config for multidomain as it works only with nginx
  98. if [[ "$FORCE_NGINX" = "true" ]] ; then
  99. sed -i "s/conference.jitsi-meet.example.com/conference.<\!--# echo var=\"subdomain\" default=\"\" -->jitsi-meet.example.com/g" $JITSI_MEET_CONFIG
  100. fi
  101. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" $JITSI_MEET_CONFIG
  102. fi
  103. # getting rid of jetty serving web
  104. if [[ "$JVB_SERVE" = "true" ]] ; then
  105. JVB_CONFIG="/etc/jitsi/videobridge/sip-communicator.properties"
  106. # we will write to the file if missing create it
  107. if [ -f $JVB_CONFIG ] ; then
  108. echo ""
  109. echo "------------------------------------------------"
  110. echo ""
  111. echo "You are using jetty to serve jitsi-meet, we are now upgrading you to use nginx!"
  112. echo ""
  113. echo "If you are using Let’s Encrypt certificates please re-run the script."
  114. echo ""
  115. echo "------------------------------------------------"
  116. echo ""
  117. sed -i "s/org.jitsi.videobridge.rest.jetty/#org.jitsi.videobridge.rest.jetty/g" $JVB_CONFIG
  118. sed -i "s/org.jitsi.videobridge.TCP_HARVESTER_PORT/#org.jitsi.videobridge.TCP_HARVESTER_PORT/g" $JVB_CONFIG
  119. if [ -d /run/systemd/system ]; then
  120. systemctl restart jitsi-videobridge2.service >/dev/null || true
  121. fi
  122. # Removing this value will force nginx or apache to be locally configured
  123. JVB_HOSTNAME_OLD=""
  124. db_get jitsi-meet/cert-choice
  125. CERT_CHOICE="$RET"
  126. # Fix certs on upgrade from jetty
  127. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  128. db_get jitsi-meet/cert-path-key
  129. CERT_KEY="$RET"
  130. db_get jitsi-meet/cert-path-crt
  131. CERT_CRT="$RET"
  132. else
  133. # create self-signed certs
  134. CERT_KEY="/etc/jitsi/meet/$JVB_HOSTNAME.key"
  135. CERT_CRT="/etc/jitsi/meet/$JVB_HOSTNAME.crt"
  136. fi
  137. fi
  138. db_set jitsi-meet/jvb-serve "false"
  139. fi
  140. if [[ "$FORCE_NGINX" = "true" && ( -z "$JVB_HOSTNAME_OLD" || "$RECONFIGURING" = "true" ) ]] ; then
  141. # this is a reconfigure, lets just delete old links
  142. if [ "$RECONFIGURING" = "true" ] ; then
  143. rm -f /etc/nginx/sites-enabled/$JVB_HOSTNAME_OLD.conf
  144. rm -f /etc/jitsi/meet/$JVB_HOSTNAME_OLD-config.js
  145. fi
  146. # nginx conf
  147. if [ ! -f /etc/nginx/sites-available/$JVB_HOSTNAME.conf ] ; then
  148. cp /usr/share/jitsi-meet-web-config/jitsi-meet.example /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  149. if [ ! -f /etc/nginx/sites-enabled/$JVB_HOSTNAME.conf ] ; then
  150. ln -s /etc/nginx/sites-available/$JVB_HOSTNAME.conf /etc/nginx/sites-enabled/$JVB_HOSTNAME.conf
  151. fi
  152. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  153. fi
  154. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  155. # replace self-signed certificate paths with user provided ones
  156. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  157. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  158. sed -i "s/ssl_certificate_key\ \/etc\/jitsi\/meet\/.*key/ssl_certificate_key\ $CERT_KEY_ESC/g" \
  159. /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  160. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  161. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  162. sed -i "s/ssl_certificate\ \/etc\/jitsi\/meet\/.*crt/ssl_certificate\ $CERT_CRT_ESC/g" \
  163. /etc/nginx/sites-available/$JVB_HOSTNAME.conf
  164. fi
  165. invoke-rc.d nginx reload || true
  166. elif [[ "$FORCE_APACHE" = "true" && ( -z "$JVB_HOSTNAME_OLD" || "$RECONFIGURING" = "true" ) ]] ; then
  167. # this is a reconfigure, lets just delete old links
  168. if [ "$RECONFIGURING" = "true" ] ; then
  169. a2dissite $JVB_HOSTNAME_OLD.conf
  170. rm -f /etc/jitsi/meet/$JVB_HOSTNAME_OLD-config.js
  171. fi
  172. # apache2 config
  173. if [ ! -f /etc/apache2/sites-available/$JVB_HOSTNAME.conf ] ; then
  174. # when creating new config, make sure all needed modules are enabled
  175. a2enmod rewrite ssl headers proxy_http include
  176. cp /usr/share/jitsi-meet-web-config/jitsi-meet.example-apache /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  177. a2ensite $JVB_HOSTNAME.conf
  178. sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  179. fi
  180. if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ] ; then
  181. # replace self-signed certificate paths with user provided ones
  182. CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  183. CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  184. sed -i "s/SSLCertificateKeyFile\ \/etc\/jitsi\/meet\/.*key/SSLCertificateKeyFile\ $CERT_KEY_ESC/g" \
  185. /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  186. CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  187. CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  188. sed -i "s/SSLCertificateFile\ \/etc\/jitsi\/meet\/.*crt/SSLCertificateFile\ $CERT_CRT_ESC/g" \
  189. /etc/apache2/sites-available/$JVB_HOSTNAME.conf
  190. fi
  191. invoke-rc.d apache2 reload || true
  192. fi
  193. echo "----------------"
  194. echo ""
  195. echo "You can now switch to a Let’s Encrypt certificate. To do so, execute:"
  196. echo "/usr/share/jitsi-meet/scripts/install-letsencrypt-cert.sh"
  197. echo ""
  198. echo "----------------"
  199. # and we're done with debconf
  200. db_stop
  201. ;;
  202. abort-upgrade|abort-remove|abort-deconfigure)
  203. ;;
  204. *)
  205. echo "postinst called with unknown argument \`$1'" >&2
  206. exit 1
  207. ;;
  208. esac
  209. # dh_installdeb will replace this with shell code automatically
  210. # generated by other debhelper scripts.
  211. #DEBHELPER#
  212. exit 0