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

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