#!/bin/bash
if [ -f /etc/sysconfig/interfaces ]; then
    . /etc/sysconfig/interfaces
else
        echo "Interfaces description not found, exiting.."
        exit 1
fi
 
 SOFTPAC=`cat /etc/sysconfig/softpac`

ROO="room-house.com"
#if [ $SOFTPAC -eq 7 ]; then
#ROO="validate.guru"
#fi


sed -i '/stunServerAddress=/d' /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini && echo stunServerAddress=$TURNSERVER >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini
sed -i '/turnURL=/d' /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini && echo turnURL=alex:alex\@$TURNSERVER:3478 >> /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini

	(nohup cat /etc/letsencrypt/archive/$ROO/cert1.pem /etc/letsencrypt/archive/$ROO/privkey1.pem > /etc/kurento/cert+key.pem && num=$(ps aux | grep kurento-media-server | grep -v grep | awk '{print $2}'); if [ ! -z $num ]; then kill -9 $num; fi && su -c 'GST_PLUGIN_SCANNER=/usr/lib/x86_64-linux-gnu/gstreamer1.5/gstreamer-1.5/gst-plugin-scanner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/nobody/newlib/lib/ /home/nobody/newlib/lib64/ld-linux-x86-64.so.2 /home/nobody/newlib/bin/kurento-media-server > /dev/null 2>&1 &' - nobody ) &>/dev/null
