# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="restic-wrapper for easy backups"
S="${WORKDIR}"

LICENSE="EUPL-1.2"
SLOT="0"
KEYWORDS=""

IUSE="+cron +logrotate"

RDEPEND="
	app-backup/restic
	cron? ( virtual/cron )
	logrotate? ( app-admin/logrotate )
"

src_install() {
	dobin "${FILESDIR}"/resticw
	dobin "${FILESDIR}"/resticbackup
	dobin "${FILESDIR}"/resticrestore

	insinto /usr/share/resticbackup
	doins "${FILESDIR}"/config
	doins "${FILESDIR}"/includes
	doins "${FILESDIR}"/excludes

	insinto /etc/resticbackup
	newins - includes <<-EOF
		# paths to include
	EOF
	newins - excludes <<-EOF
		# paths to exclude
	EOF

	if use cron; then
		exeinto /etc/cron.weekly
		newexe "${FILESDIR}"/cronjob resticbackup
	fi

	if use logrotate ; then
		insinto /etc/logrotate.d
		newins "${FILESDIR}"/logrotate resticbackup
	fi
}

pkg_postinst() {
	if use cron ; then
		elog
		elog "Backups will run weekly, see ${EROOT}/etc/cron.weekly/resticbackup"
		elog
	fi

	elog
	elog "A config template is shipped under ${EROOT}/usr/share/resticbackup/config."
	elog "Copy to ${EROOT}/etc/resticbackup/config and edit to make changes."
	elog ""
	elog "See https://restic.readthedocs.io/en/stable/075_scripting.html#environment-variables"
	elog
}