#!/bin/bash

# Copyright 2021 Zorin OS Technologies Ltd.
#
# This program is free software you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 3, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT ANY
# WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
# more details.

if [[ ! -d /usr/share/zorin-os-file-templates ]]; then
	exit 1
fi

template_files=/usr/share/zorin-os-file-templates/*
user_templates_directory=$(xdg-user-dir TEMPLATES)

if [[ "$user_templates_directory" != "$HOME" ]]; then
	if [[ -d "$user_templates_directory" ]]; then
		for file in $template_files
		do
			cp -u "$file" "$user_templates_directory"
		done

		if [[ -e ~/.config/autostart/zorin-os-file-templates.desktop ]]; then
			 rm ~/.config/autostart/zorin-os-file-templates.desktop
		fi
	fi
fi
