2014-09-04 09:00:12 +00:00
|
|
|
#!/bin/bash
|
2014-08-10 19:29:48 +00:00
|
|
|
# postinst script for jitsi-meet-prosody
|
|
|
|
#
|
|
|
|
# see: dh_installdeb(1)
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# summary of how this script can be called:
|
|
|
|
# * <postinst> `configure' <most-recently-configured-version>
|
|
|
|
# * <old-postinst> `abort-upgrade' <new version>
|
|
|
|
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
|
|
|
|
# <new-version>
|
|
|
|
# * <postinst> `abort-remove'
|
|
|
|
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
|
|
|
|
# <failed-install-package> <version> `removing'
|
|
|
|
# <conflicting-package> <version>
|
|
|
|
# for details, see http://www.debian.org/doc/debian-policy/ or
|
|
|
|
# the debian-policy package
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
configure)
|
|
|
|
|
2014-11-17 10:16:34 +00:00
|
|
|
# loading debconf
|
|
|
|
. /usr/share/debconf/confmodule
|
|
|
|
|
2016-11-21 21:16:37 +00:00
|
|
|
# try to get host from jitsi-videobridge
|
|
|
|
db_get jitsi-videobridge/jvb-hostname
|
|
|
|
if [ -z "$RET" ] ; then
|
|
|
|
# server hostname
|
|
|
|
db_set jitsi-videobridge/jvb-hostname "localhost"
|
|
|
|
db_input critical jitsi-videobridge/jvb-hostname || true
|
|
|
|
db_go
|
|
|
|
fi
|
|
|
|
JVB_HOSTNAME="$RET"
|
|
|
|
|
|
|
|
db_get jitsi-videobridge/jvbsecret
|
|
|
|
if [ -z "$RET" ] ; then
|
|
|
|
db_input critical jitsi-videobridge/jvbsecret || true
|
|
|
|
db_go
|
|
|
|
fi
|
|
|
|
JVB_SECRET="$RET"
|
|
|
|
|
|
|
|
db_get jicofo/jicofo-authuser
|
|
|
|
if [ -z "$RET" ] ; then
|
|
|
|
db_input critical jicofo/jicofo-authuser || true
|
|
|
|
db_go
|
|
|
|
fi
|
|
|
|
JICOFO_AUTH_USER="$RET"
|
|
|
|
|
|
|
|
db_get jicofo/jicofo-authpassword
|
|
|
|
if [ -z "$RET" ] ; then
|
|
|
|
db_input critical jicofo/jicofo-authpassword || true
|
|
|
|
db_go
|
|
|
|
fi
|
|
|
|
JICOFO_AUTH_PASSWORD="$RET"
|
|
|
|
|
|
|
|
db_get jicofo/jicofosecret
|
|
|
|
if [ -z "$RET" ] ; then
|
|
|
|
db_input critical jicofo/jicofosecret || true
|
|
|
|
db_go
|
|
|
|
fi
|
|
|
|
JICOFO_SECRET="$RET"
|
|
|
|
|
|
|
|
JICOFO_AUTH_DOMAIN="auth.$JVB_HOSTNAME"
|
|
|
|
|
2015-03-16 15:54:36 +00:00
|
|
|
# detect dpkg-reconfigure, just delete old links
|
2015-03-26 11:19:50 +00:00
|
|
|
db_get jitsi-meet-prosody/jvb-hostname
|
2015-03-16 15:54:36 +00:00
|
|
|
JVB_HOSTNAME_OLD=$RET
|
|
|
|
if [ -n "$RET" ] && [ ! "$JVB_HOSTNAME_OLD" = "$JVB_HOSTNAME" ] ; then
|
|
|
|
rm -f /etc/prosody/conf.d/$JVB_HOSTNAME_OLD.cfg.lua
|
|
|
|
rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.key
|
|
|
|
rm -f /etc/prosody/certs/$JVB_HOSTNAME_OLD.crt
|
|
|
|
fi
|
|
|
|
|
2014-11-17 10:16:34 +00:00
|
|
|
# stores the hostname so we will reuse it later, like in purge
|
2016-11-21 21:16:37 +00:00
|
|
|
db_set jitsi-meet-prosody/jvb-hostname "$JVB_HOSTNAME"
|
2014-11-17 10:16:34 +00:00
|
|
|
|
|
|
|
# and we're done with debconf
|
|
|
|
db_stop
|
|
|
|
|
2014-08-29 09:53:24 +00:00
|
|
|
PROSODY_CONFIG_PRESENT="true"
|
2014-12-05 13:04:15 +00:00
|
|
|
PROSODY_CREATE_JICOFO_USER="false"
|
2014-10-22 14:23:41 +00:00
|
|
|
PROSODY_HOST_CONFIG="/etc/prosody/conf.avail/$JVB_HOSTNAME.cfg.lua"
|
2014-12-05 13:04:15 +00:00
|
|
|
PROSODY_CONFIG_OLD="/etc/prosody/prosody.cfg.lua"
|
2014-09-04 09:00:12 +00:00
|
|
|
# if there is no prosody config extract our template
|
2014-10-22 14:23:41 +00:00
|
|
|
# check for config in conf.avail or check whether it wasn't already configured in main config
|
2014-12-05 13:04:15 +00:00
|
|
|
if [ ! -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JVB_HOSTNAME\"" $PROSODY_CONFIG_OLD; then
|
2014-08-29 09:53:24 +00:00
|
|
|
PROSODY_CONFIG_PRESENT="false"
|
2014-12-16 15:00:46 +00:00
|
|
|
mkdir -p /etc/prosody/conf.avail/
|
2014-10-22 14:23:41 +00:00
|
|
|
cp /usr/share/doc/jitsi-meet-prosody/prosody.cfg.lua-jvb.example $PROSODY_HOST_CONFIG
|
|
|
|
sed -i "s/jitmeet.example.com/$JVB_HOSTNAME/g" $PROSODY_HOST_CONFIG
|
|
|
|
sed -i "s/jitmeetSecret/$JVB_SECRET/g" $PROSODY_HOST_CONFIG
|
2014-12-02 19:11:54 +00:00
|
|
|
sed -i "s/focusSecret/$JICOFO_SECRET/g" $PROSODY_HOST_CONFIG
|
|
|
|
sed -i "s/focusUser/$JICOFO_AUTH_USER/g" $PROSODY_HOST_CONFIG
|
2014-10-22 14:23:41 +00:00
|
|
|
if [ ! -f /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua ]; then
|
|
|
|
ln -s $PROSODY_HOST_CONFIG /etc/prosody/conf.d/$JVB_HOSTNAME.cfg.lua
|
2014-08-29 09:53:24 +00:00
|
|
|
fi
|
2014-12-05 13:04:15 +00:00
|
|
|
PROSODY_CREATE_JICOFO_USER="true"
|
2014-12-17 07:39:12 +00:00
|
|
|
# on some distributions main prosody config doesn't include configs
|
|
|
|
# from conf.d folder enable it as this where we put our config by default
|
|
|
|
if ! grep -q "Include \"conf\.d\/\*\.cfg.lua\"" $PROSODY_CONFIG_OLD; then
|
|
|
|
echo -e "\nInclude \"conf.d/*.cfg.lua\"" >> $PROSODY_CONFIG_OLD
|
|
|
|
fi
|
2014-12-02 19:11:54 +00:00
|
|
|
fi
|
2014-12-05 13:04:15 +00:00
|
|
|
# UPGRADE to server side focus check if focus is configured
|
2016-11-21 21:16:37 +00:00
|
|
|
if [ -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JICOFO_AUTH_DOMAIN\"" $PROSODY_HOST_CONFIG; then
|
|
|
|
echo -e "\nVirtualHost \"$JICOFO_AUTH_DOMAIN\"" >> $PROSODY_HOST_CONFIG
|
2014-12-02 19:11:54 +00:00
|
|
|
echo -e " authentication = \"internal_plain\"\n" >> $PROSODY_HOST_CONFIG
|
2016-11-21 21:16:37 +00:00
|
|
|
sed -i "s/Component \"conference.$JVB_HOSTNAME\" \"muc\"/Component \"conference.$JVB_HOSTNAME\" \"muc\"\nadmins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\" }\n/g" $PROSODY_HOST_CONFIG
|
2014-12-02 19:11:54 +00:00
|
|
|
echo -e "Component \"focus.$JVB_HOSTNAME\"" >> $PROSODY_HOST_CONFIG
|
|
|
|
echo -e " component_secret=\"$JICOFO_SECRET\"\n" >> $PROSODY_HOST_CONFIG
|
2014-12-05 13:04:15 +00:00
|
|
|
PROSODY_CREATE_JICOFO_USER="true"
|
|
|
|
# UPGRADE to server side focus on old config(/etc/prosody/prosody.cfg.lua)
|
2016-11-21 21:16:37 +00:00
|
|
|
elif [ ! -f $PROSODY_HOST_CONFIG ] && ! grep -q "VirtualHost \"$JICOFO_AUTH_DOMAIN\"" $PROSODY_CONFIG_OLD; then
|
|
|
|
echo -e "\nVirtualHost \"$JICOFO_AUTH_DOMAIN\"" >> $PROSODY_CONFIG_OLD
|
2014-12-05 13:04:15 +00:00
|
|
|
echo -e " authentication = \"internal_plain\"\n" >> $PROSODY_CONFIG_OLD
|
|
|
|
if ! grep -q "admins = { }" $PROSODY_CONFIG_OLD; then
|
2016-11-21 21:16:37 +00:00
|
|
|
echo -e "admins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\" }\n" >> $PROSODY_CONFIG_OLD
|
2014-12-05 13:04:15 +00:00
|
|
|
else
|
2016-11-21 21:16:37 +00:00
|
|
|
sed -i "s/admins = { }/admins = { \"$JICOFO_AUTH_USER@$JICOFO_AUTH_DOMAIN\" }\n/g" $PROSODY_CONFIG_OLD
|
2014-12-05 13:04:15 +00:00
|
|
|
fi
|
|
|
|
echo -e "Component \"focus.$JVB_HOSTNAME\"" >> $PROSODY_CONFIG_OLD
|
|
|
|
echo -e " component_secret=\"$JICOFO_SECRET\"\n" >> $PROSODY_CONFIG_OLD
|
|
|
|
PROSODY_CREATE_JICOFO_USER="true"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PROSODY_CREATE_JICOFO_USER" = "true" ]; then
|
2014-12-02 19:11:54 +00:00
|
|
|
# create 'focus@auth.domain' prosody user
|
|
|
|
prosodyctl register $JICOFO_AUTH_USER $JICOFO_AUTH_DOMAIN $JICOFO_AUTH_PASSWORD
|
2014-12-04 11:40:13 +00:00
|
|
|
# trigger a restart
|
|
|
|
PROSODY_CONFIG_PRESENT="false"
|
2014-08-29 09:53:24 +00:00
|
|
|
fi
|
|
|
|
|
2014-08-10 19:29:48 +00:00
|
|
|
if [ ! -f /var/lib/prosody/$JVB_HOSTNAME.crt ]; then
|
|
|
|
HOST="$( (hostname -s; echo localhost) | head -n 1)"
|
|
|
|
DOMAIN="$( (hostname -d; echo localdomain) | head -n 1)"
|
|
|
|
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj \
|
|
|
|
"/O=$DOMAIN/OU=$HOST/CN=$JVB_HOSTNAME/emailAddress=webmaster@$HOST.$DOMAIN" \
|
2014-08-14 07:21:51 +00:00
|
|
|
-keyout /var/lib/prosody/$JVB_HOSTNAME.key \
|
|
|
|
-out /var/lib/prosody/$JVB_HOSTNAME.crt
|
2014-08-10 19:29:48 +00:00
|
|
|
fi
|
|
|
|
ln -sf /var/lib/prosody/$JVB_HOSTNAME.key /etc/prosody/certs/$JVB_HOSTNAME.key
|
|
|
|
ln -sf /var/lib/prosody/$JVB_HOSTNAME.crt /etc/prosody/certs/$JVB_HOSTNAME.crt
|
2014-09-17 13:52:00 +00:00
|
|
|
|
2014-10-22 14:23:41 +00:00
|
|
|
if [ "$PROSODY_CONFIG_PRESENT" = "false" ]; then
|
2014-09-17 13:52:00 +00:00
|
|
|
invoke-rc.d prosody restart
|
|
|
|
fi
|
2014-08-10 19:29:48 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
abort-upgrade|abort-remove|abort-deconfigure)
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "postinst called with unknown argument \`$1'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# dh_installdeb will replace this with shell code automatically
|
|
|
|
# generated by other debhelper scripts.
|
|
|
|
|
|
|
|
#DEBHELPER#
|
|
|
|
|
|
|
|
exit 0
|