"Fossies" - the Fresh Open Source Software Archive

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