#!/bin/bash
# info: update white label logo's
# options: [DOWNLOAD]
#
# example: v-update-custom-templates
#
# Add or replace Hestia templates under $HESTIA/data/templates/
# with custom templates in $HESTIA/data/templates/custom
#
# Inspired on v-update-white-label-logo

#----------------------------------------------------------#
#                Variables & Functions                     #
#----------------------------------------------------------#

# Argument definition
# TODO: download hestia files, reset custom (unfinished)
download=${1-no}
reset=${2-no}

# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source "$HESTIA/func/main.sh"
# load config file
source_conf "$HESTIA/conf/hestia.conf"

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

# Unfinished: reset without download
if [ "$reset" = "yes" ]; then
	rm -rf "$HESTIA/data/templates/custom"
fi


# TODO: we should filter also files' directories are the appropriate ones
rsync -a -f'+ *\.(tpl|stpl|sh)' -f'- *' $HESTIA/data/templates/custom/ $HESTIA/data/templates/

# if [ -f "$HESTIA/web/images/custom/logo.svg" ]; then
# 	cp -f "$HESTIA/web/images/custom/logo.svg" "$HESTIA/web/images/logo.svg"
# elif [ ! -f "$HESTIA/web/images/custom/logo.svg" ] && [ "$download" = "yes" ]; then
# 	download_file "https://raw.githubusercontent.com/hestiacp/hestiacp/release/web/images/logo.svg" "$HESTIA/web/images/logo.svg"
# fi

$HESTIA/bin/v-rebuild-users yes

#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#

exit