#!/bin/bash
# info: update mail templates
# options: [RESTART] [SKIP]
#
# The function for obtaining updated pack of mail templates.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument definition
restart=$1
skip=$2

# Includes
source $HESTIA/func/main.sh
source $HESTIA/conf/hestia.conf

#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Update templates
cp -rf $HESTIA_INSTALL_DIR/templates/mail $HESTIA/data/templates/

# Rebuild mail domains if mail services are enabled
if [ ! -z "$skip" ]; then
	if [ ! -z $MAIL_SYSTEM ]; then
		for user in $($HESTIA/bin/v-list-sys-users plain); do
			$BIN/v-rebuild-mail-domains $user no
		done
	fi
fi
#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#

# Restarting web server
$BIN/v-restart-web $restart
check_result $? "restart" >/dev/null 2>&1

$BIN/v-restart-proxy $restart
check_result $? "restart" >/dev/null 2>&1

exit
