"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7316/debian/jitsi-meet-turnserver.postinst" (5 Jun 2023, 5517 Bytes) of package /linux/misc/jitsi-meet-7316.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-turnserver
    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         # loading debconf
   23         . /usr/share/debconf/confmodule
   24 
   25         # try to get host from jitsi-videobridge
   26         db_get jitsi-videobridge/jvb-hostname
   27         if [ -z "$RET" ] ; then
   28             # server hostname
   29             db_set jitsi-videobridge/jvb-hostname "localhost"
   30             db_input critical jitsi-videobridge/jvb-hostname || true
   31             db_go
   32         fi
   33         JVB_HOSTNAME=$(echo "$RET" | xargs echo -n)
   34 
   35         TURN_CONFIG="/etc/turnserver.conf"
   36         JITSI_MEET_CONFIG="/etc/jitsi/meet/$JVB_HOSTNAME-config.js"
   37 
   38         # if there was a turn config backup it so we can configure
   39         # we cannot recognize at the moment is this a user config or default config when installing coturn
   40         if [[ -f $TURN_CONFIG ]] && ! grep -q "jitsi-meet coturn config" "$TURN_CONFIG" ; then
   41             mv $TURN_CONFIG $TURN_CONFIG.bak
   42         fi
   43 
   44         # detect dpkg-reconfigure, just delete old links
   45         db_get jitsi-meet-turnserver/jvb-hostname
   46         JVB_HOSTNAME_OLD=$(echo "$RET" | xargs echo -n)
   47         if [ -n "$RET" ] && [ ! "$JVB_HOSTNAME_OLD" = "$JVB_HOSTNAME" ] ; then
   48             if [[ -f $TURN_CONFIG ]] && grep -q "jitsi-meet coturn config" "$TURN_CONFIG" ; then
   49                 rm -f $TURN_CONFIG
   50             fi
   51         fi
   52 
   53         if [[ -f $TURN_CONFIG ]] ; then
   54             echo "------------------------------------------------"
   55             echo ""
   56             echo "turnserver is already configured on this machine."
   57             echo ""
   58             echo "------------------------------------------------"
   59 
   60             if grep -q "jitsi-meet coturn config" "$TURN_CONFIG" && ! grep -q "jitsi-meet coturn relay disable config" "$TURN_CONFIG" ; then
   61                 echo "Updating coturn config"
   62                 echo "# jitsi-meet coturn relay disable config. Do not modify this line
   63 no-multicast-peers
   64 no-cli
   65 no-loopback-peers
   66 no-tcp-relay
   67 denied-peer-ip=0.0.0.0-0.255.255.255
   68 denied-peer-ip=10.0.0.0-10.255.255.255
   69 denied-peer-ip=100.64.0.0-100.127.255.255
   70 denied-peer-ip=127.0.0.0-127.255.255.255
   71 denied-peer-ip=169.254.0.0-169.254.255.255
   72 denied-peer-ip=127.0.0.0-127.255.255.255
   73 denied-peer-ip=172.16.0.0-172.31.255.255
   74 denied-peer-ip=192.0.0.0-192.0.0.255
   75 denied-peer-ip=192.0.2.0-192.0.2.255
   76 denied-peer-ip=192.88.99.0-192.88.99.255
   77 denied-peer-ip=192.168.0.0-192.168.255.255
   78 denied-peer-ip=198.18.0.0-198.19.255.255
   79 denied-peer-ip=198.51.100.0-198.51.100.255
   80 denied-peer-ip=203.0.113.0-203.0.113.255
   81 denied-peer-ip=240.0.0.0-255.255.255.255" >> $TURN_CONFIG
   82 
   83                 invoke-rc.d coturn restart || true
   84             fi
   85 
   86             db_stop
   87             exit 0
   88         fi
   89 
   90         # stores the hostname so we will reuse it later, like in purge
   91         db_set jitsi-meet-turnserver/jvb-hostname "$JVB_HOSTNAME"
   92 
   93         # try to get turnserver password
   94         db_get jitsi-meet-prosody/turn-secret
   95         if [ -z "$RET" ] ; then
   96             db_input critical jitsi-meet-prosody/turn-secret || true
   97             db_go
   98         fi
   99         TURN_SECRET="$RET"
  100 
  101         # no turn config exists, lt's copy template and fill it in
  102         cp /usr/share/jitsi-meet-turnserver/turnserver.conf $TURN_CONFIG
  103         sed -i "s/jitsi-meet.example.com/$JVB_HOSTNAME/g" $TURN_CONFIG
  104         sed -i "s/__turnSecret__/$TURN_SECRET/g" $TURN_CONFIG
  105 
  106         # SSL settings
  107         db_get jitsi-meet/cert-choice
  108         CERT_CHOICE="$RET"
  109 
  110         UPLOADED_CERT_CHOICE="I want to use my own certificate"
  111         LE_CERT_CHOICE="Let's Encrypt certificates"
  112         if [ "$CERT_CHOICE" = "$UPLOADED_CERT_CHOICE" ]; then
  113             db_get jitsi-meet/cert-path-key
  114             CERT_KEY="$RET"
  115             db_get jitsi-meet/cert-path-crt
  116             CERT_CRT="$RET"
  117 
  118             # replace self-signed certificate paths with user provided ones
  119             CERT_KEY_ESC=$(echo $CERT_KEY | sed 's/\./\\\./g')
  120             CERT_KEY_ESC=$(echo $CERT_KEY_ESC | sed 's/\//\\\//g')
  121             sed -i "s/pkey=\/etc\/jitsi\/meet\/.*key/pkey=$CERT_KEY_ESC/g" $TURN_CONFIG
  122             CERT_CRT_ESC=$(echo $CERT_CRT | sed 's/\./\\\./g')
  123             CERT_CRT_ESC=$(echo $CERT_CRT_ESC | sed 's/\//\\\//g')
  124             sed -i "s/cert=\/etc\/jitsi\/meet\/.*crt/cert=$CERT_CRT_ESC/g" $TURN_CONFIG
  125         elif [ "$CERT_CHOICE" = "$LE_CERT_CHOICE" ]; then
  126             /usr/share/jitsi-meet/scripts/coturn-le-update.sh ${JVB_HOSTNAME}
  127         fi
  128 
  129         sed -i "s/#TURNSERVER_ENABLED/TURNSERVER_ENABLED/g" /etc/default/coturn
  130         invoke-rc.d coturn restart || true
  131 
  132         # and we're done with debconf
  133         db_stop
  134     ;;
  135 
  136     abort-upgrade|abort-remove|abort-deconfigure)
  137     ;;
  138 
  139     *)
  140         echo "postinst called with unknown argument \`$1'" >&2
  141         exit 1
  142     ;;
  143 esac
  144 
  145 # dh_installdeb will replace this with shell code automatically
  146 # generated by other debhelper scripts.
  147 
  148 #DEBHELPER#
  149 
  150 exit 0