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

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