# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=6

inherit vcs-snapshot

DESCRIPTION="Provides several system configuration files"
HOMEPAGE="https://gitlab.com/genthree/rc-files"
SRC_URI="https://gitlab.com/genthree/${PN}/repository/archive.tar.bz2?ref=v${PV} -> ${P}.tar.bz2"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
IUSE="X acpi +bash +eix +git +issue +logrotate +portage +readline +ssh +syslog-ng +vim"

# require at least one flag
REQUIRED_USE="|| ( ${IUSE//\+/} )"

DEPEND=""
RDEPEND=""

src_install() {
	dodir /etc
	dodir /etc/skel

	if use X ; then
		insinto /etc
		doins -r Xresources

		insinto /etc/skel
		doins skel/.Xresources
		doins skel/.xinitrc
		fperms 0600 /etc/skel/.Xresources
		fperms 0600 /etc/skel/.xinitrc
	fi

	if use acpi ; then
		insinto /etc
		doins -r acpi
		fperms 0755 /etc/acpi/genthree.sh
	fi

	if use bash ; then
		insinto /etc
		doins -r bash
		doins -r profile.d

		insinto /etc/skel
		doins skel/.bash_profile
		doins skel/.bashrc
		fperms 0600 /etc/skel/.bash_profile
		fperms 0600 /etc/skel/.bashrc
	fi

	if use eix ; then
		insinto /etc
		doins -r eixrc
	fi

	if use git ; then
		insinto /etc/skel
		doins skel/.gitconfig
		fperms 0600 /etc/skel/.gitconfig
	fi

	if use issue ; then
		insinto /etc
		doins issue issue.logo
	fi

	if use logrotate ; then
		insinto /etc
		doins logrotate.conf
	fi

	if use portage ; then
		insinto /etc
		doins -r portage
	fi

	if use readline ; then
		insinto /etc
		doins inputrc
	fi

	if use ssh ; then
		insinto /etc
		doins -r ssh
		fperms 0600 /etc/ssh/sshd_config
	fi

	if use syslog-ng ; then
		insinto /etc
		doins -r syslog-ng
	fi

	if use vim ; then
		insinto /etc
		doins -r vim
	fi
}

pkg_postinst() {
	if use acpi && [[ -e /etc/acpi/default.sh ]] && [[ -e /etc/acpi/events/default ]]; then
		ewarn "The default acpi handler script /etc/acpi/default.sh"
		ewarn "might interfere with the genthree handler script."
		ewarn ""
		ewarn "Consider deleting /etc/acpi/events/default"
		ewarn "to stop it from being invoked."
	fi
}