app-admin/vault: use get_golibdir for library installation
[gentoo.git] / app-admin / vault / vault-0.4.1.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit eutils fcaps golang-build systemd user
8
9 EGO_PN="github.com/hashicorp/${PN}/..."
10 DESCRIPTION="A tool for managing secrets"
11 HOMEPAGE="https://vaultproject.io/"
12 SRC_URI="https://${EGO_PN%/*}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
13 SLOT="0"
14 LICENSE="MPL-2.0"
15 KEYWORDS="~amd64"
16 IUSE=""
17
18 RESTRICT="test"
19
20 DEPEND="dev-go/go-oauth2:="
21 RDEPEND=""
22
23 STRIP_MASK="*.a"
24
25 S="${WORKDIR}/${P}"
26
27 FILECAPS=(
28         -m 755 'cap_ipc_lock=+ei' usr/bin/${PN}
29 )
30
31 pkg_setup() {
32         enewgroup ${PN}
33         enewuser ${PN} -1 -1 -1 ${PN}
34 }
35
36 src_unpack() {
37         local x
38
39         default
40         mv "${S}" "${S}_"
41         mkdir -p "$(dirname "${S}/src/${EGO_PN%/*}")" || die
42         mv "${S}_" "${S}/src/${EGO_PN%/*}" || die
43
44         # Create a writable GOROOT in order to avoid sandbox violations.
45         export GOROOT="${WORKDIR}/goroot"
46         cp -sR "${EPREFIX}"/usr/lib/go "${GOROOT}" || die
47         rm -rf "${GOROOT}"/{src,pkg/$(go env GOOS)_$(go env GOARCH)}/"${EGO_PN%/*}" || die
48
49         export GOPATH=${S}:${S}/src/github.com/hashicorp/vault/Godeps/_workspace:$(get_golibdir_gopath)
50
51         while read -r -d '' x; do
52                 rm -rf "${GOROOT}/src/${x}" "${GOROOT}/pkg/$(go env GOOS)_$(go env GOARCH)/${x}"{,.a} || die
53         done < <(find "${P}/src/github.com/hashicorp/vault/Godeps/_workspace/src" -maxdepth 3 -mindepth 3 -type d -print0)
54 }
55
56 src_compile() {
57         go build -v -work -x ${EGO_BUILD_FLAGS} "${EGO_PN}" || die
58         go install -v -work -x ${EGO_BUILD_FLAGS} "${EGO_PN}" || die
59 }
60
61 src_install() {
62         local x
63
64         newinitd "${FILESDIR}/${PN}.initd" "${PN}"
65         newconfd "${FILESDIR}/${PN}.confd" "${PN}"
66         systemd_dounit "${FILESDIR}/${PN}.service"
67
68         keepdir /etc/${PN}.d
69         insinto /etc/${PN}.d
70         doins "${FILESDIR}/"*.json.example
71
72         keepdir /var/log/${PN}
73         fowners ${PN}:${PN} /var/log/${PN}
74
75         dobin "${S}/bin/${PN}"
76
77         find "${S}"/src/${EGO_PN%/*} -mindepth 1 -maxdepth 1 -type f -delete || die
78
79         while read -r -d '' x; do
80                 x=${x#${S}/src}
81                 [[ -d ${S}/pkg/$(go env GOOS)_$(go env GOARCH)/${x} ||
82                         -f ${S}/pkg/$(go env GOOS)_$(go env GOARCH)/${x}.a ]] && continue
83                 rm -rf "${S}"/src/${x}
84         done < <(find "${S}"/src/${EGO_PN%/*} -mindepth 1 -maxdepth 1 -type d -print0)
85         insopts -m0644 -p # preserve timestamps for bug 551486
86         insinto $(dirname "$(get_golibdir)/pkg/$(go env GOOS)_$(go env GOARCH)/${EGO_PN%/*}")
87         doins -r "${S}"/pkg/$(go env GOOS)_$(go env GOARCH)/${EGO_PN%/*}
88         insinto $(dirname "$(get_golibdir)/src/${EGO_PN%/*}")
89         doins -r "${S}"/src/${EGO_PN%/*}
90 }