#!/bin/bash
source /root/envsetup/global-conf.sh

# MS package install
if ( dpkg -s python3-mediaserver >/dev/null 2>&1 ); then
	DEBIAN_FRONTEND=noninteractive apt-get install -y --reinstall python3-mediaserver
else
	DEBIAN_FRONTEND=noninteractive apt-get install -y python3-mediaserver
fi

# set sender address
sender="${EMAIL_SENDER}"
if [[ "${sender}" == "" || "${sender}" == "noreply@ubicast.eu" ]]; then
	if [[ "${MS_SERVER_NAME}" =~ .*\..* ]]; then
		sender="noreply@${MS_SERVER_NAME}"
	fi
fi
if [[ "${sender}" != "" && "${sender}" != "noreply@ubicast.eu" ]]; then
	echo "Using ${sender} as sender address for MS."
	sed -i "s?[# ]*DEFAULT_FROM_EMAIL.*?DEFAULT_FROM_EMAIL = '${sender}'?" /etc/mediaserver/msconf.py
fi

# MS instance
msinstaller.py msuser
