# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="4"

inherit eutils

if [[ ${PV} == "9999" ]] ; then
	inherit git-2
	EGIT_BRANCH="master"
	EGIT_REPO_URI="git://git.monkeysphere.info/${PN}
		http://http-git.tremily.us/${PN}.git"
	SRC_URI=""
else
	MY_P="${P/-/_}"
	SRC_URI="http://archive.monkeysphere.info/debian/pool/monkeysphere/m/monkeysphere/${MY_P}.orig.tar.gz"
fi

DESCRIPTION="use the OpenPGP web of trust to verify ssh connections"
HOMEPAGE="http://web.monkeysphere.info/"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="test"

#RESTRICT="test" # ssh connection failed

RDEPEND="app-crypt/gnupg
	dev-perl/Crypt-OpenSSL-Bignum
	dev-perl/Crypt-OpenSSL-RSA
	virtual/perl-Digest-SHA
	virtual/perl-MIME-Base64
	net-misc/openssh
	net-misc/socat
	|| (
		app-misc/lockfile-progs
		mail-filter/procmail
	)"
DEPEND="test? ( ${RDEPEND} )"

pkg_setup() {
	enewgroup "${PN}"
	enewuser "${PN}" -1 -1 -1 "${PN}"
}

src_install() {
	emake install DESTDIR="${D}"
	rm -rf "${ED}usr/share/doc/${PN}"

	keepdir /var/lib/${PN}
	fperms 770 /var/lib/${PN}
	fowners "${PN}:${PN}" "/var/lib/${PN}"

	dodoc Changelog README
	dodoc -r examples/
}

pkg_postinst() {
	elog "Monkeysphere ssh config stanza (for ~/.ssh/config or /etc/ssh_config)"
	elog "This checks for host keys in the OpenPGP WoT:"
	elog ""
	elog "Host *"
	elog "ProxyCommand monkeysphere ssh-proxycommand %h %p"
	elog ""
	elog "To be able to use some 'monkeysphere-host' commands, you need to be a"
	elog "member of the group 'monkeysphere' which has just been added to your"
	elog "system. You can add your user to the group by running the following"
	elog "command as root:"
	elog
	elog "	usermod -a -G monkeysphere youruser"
	elog
	elog "Please be aware that you need to either re-login or run"
	elog
	elog "	newgrp - monkeysphere"
	elog
	elog "for the group membership to take effect."
}