"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-4434/debian/jitsi-meet-web-config.postinst" (25 Sep 2020, 11127 Bytes) of package /linux/misc/jitsi-meet-4434.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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