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

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

if [[ "${MONITOR_SHELL_PWD}" != "" ]]; then
	echo -e "${MONITOR_SHELL_PWD}\n${MONITOR_SHELL_PWD}" | passwd -q msmonitor
	echo -e "\033[1;33mThe msmonitor account password has been set.\033[0m"
fi

# configure nginx
if [[ "${MONITOR_SERVER_NAME}" != "" ]]; then
	/root/envsetup/set_app_domain.py mon $MONITOR_SERVER_NAME
fi
nginx -t
service nginx restart
