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

echo -e "${RED}Customer parameters will be applied after rebooting. Note that you won't be able to login to the machine after this operation !${NC}"

# set customer IP (/etc/network/interfaces)
if ( ! test -z ${NETWORK_IP} ); then
	sed -i "s@192\.168\.40\.10.*@${NETWORK_IP}@" /etc/network/interfaces
fi
if ( ! test -z ${NETWORK_MASK} ); then
	sed -i "s@255\.255\.252\..*@${NETWORK_MASK}@" /etc/network/interfaces
fi
if ( ! test -z ${NETWORK_GATEWAY} ); then
	sed -i "s@192\.168\.40\..*@${NETWORK_GATEWAY}@" /etc/network/interfaces
fi

# backup-server specific
if ( test -f /usr/sbin/burp ); then
	# changer burp status IP
	sed -i "s@^BURP_CLIENT_MAIL_DEST=.*@BURP_CLIENT_MAIL_DEST=${BURP_CLIENT_MAIL_DEST}@" /root/burp-custom.sh
	sed -i "s@admin: .*@admin: ${BURP_CLIENT_MAIL_DEST}" /etc/aliases
	newaliases
fi

# set customer DNS
if ( ! test -z ${NETWORK_DNS1} ); then
	echo "nameserver ${NETWORK_DNS1}" > /etc/resolv.conf
	if ( ! test -z ${NETWORK_DNS2} ); then
		echo "nameserver ${NETWORK_DNS2}" >> /etc/resolv.conf
	fi
fi

# set customer NTP
sed -i "s@^server .*@@" /etc/ntp.conf
echo "" >> /etc/ntp.conf
if ( ! test -z ${NTP_SERVER} ); then
	echo "server ${NTP_SERVER}" >> /etc/ntp.conf
fi
service ntp restart

# set email sender
if ( ! test -z ${EMAIL_SENDER} ); then
	echo "#DEFAULT_FROM_EMAIL = '${EMAIL_SENDER}'" >> /etc/mediaserver/msconf.py
	echo "#DEFAULT_FROM_EMAIL = '${EMAIL_SENDER}'" >> /home/skyreach/htdocs/skyreach_site/settings_override.py
fi

# set locale
echo -e "${CYAN}You will now change the locales.${NC}"
locale-gen en_GB.UTF-8
dpkg-reconfigure locales
update-locale LANG=en_GB.UTF-8 LANGUAGE=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
#dpkg-reconfigure console-data
#dpkg-reconfigure keyboard-configuration

# set TZ
echo -e "${CYAN}You will now change the time zone.${NC}"
dpkg-reconfigure tzdata
