dev-util/rebar: version bump to 2.5.1
[gentoo.git] / app-admin / consul / consul-9999.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit git-r3 golang-base systemd user
8
9 KEYWORDS=""
10 DESCRIPTION="A tool for service discovery, monitoring and configuration"
11 HOMEPAGE="http://www.consul.io"
12 GO_PN="github.com/hashicorp/consul"
13 EGIT_REPO_URI="git://${GO_PN}.git"
14 LICENSE="MPL-2.0"
15 SLOT="0"
16 IUSE="test web"
17 RESTRICT="test"
18
19 DEPEND=">=dev-lang/go-1.4:=
20         dev-go/go-crypto:=
21         test? ( dev-go/go-tools )
22         web? (
23                 dev-ruby/sass
24                 dev-ruby/uglifier
25         )"
26 RDEPEND=""
27 SRC_URI=""
28
29 STRIP_MASK="*.a"
30 S="${WORKDIR}/src/${GO_PN}"
31 EGIT_CHECKOUT_DIR="${S}"
32
33 pkg_setup() {
34         enewgroup consul
35         enewuser consul -1 -1 /var/lib/${PN} consul
36 }
37
38 src_unpack() {
39         git-r3_src_unpack
40         cd "${S}" || die
41
42         # Create a writable GOROOT in order to avoid sandbox violations
43         # or other interference from installed instances.
44         export GOPATH="${WORKDIR}:$(get_golibdir_gopath)" GOROOT="${WORKDIR}/goroot"
45         cp -sR "${EPREFIX}"/usr/lib/go "${GOROOT}" || die
46
47         # Use latest versions of some packages, in case of incompatible
48         # API changes
49         rm -rf "${GOROOT}/src/${GO_PN%/*}" \
50                 "${GOROOT}/pkg/linux_${ARCH}/${GO_PN%/*}" || die
51
52         # Fetch dependencies
53         emake deps
54
55         # Avoid interference from installed instances
56         while read -r path; do
57                 rm -rf "${GOROOT}/src/${path#${WORKDIR}/src}" \
58                 "${GOROOT}/pkg/linux_${ARCH}/${path#${WORKDIR}/src}" || die
59         done < <(find "${WORKDIR}"/src -maxdepth 3 -mindepth 3 -type d)
60 }
61
62 src_prepare() {
63         # Disable tests that fail under network-sandbox
64         sed -e 's:TestServer_StartStop:_TestServer_StartStop:' \
65                 -i consul/server_test.go || die
66         sed -e 's:TestRetryJoin(:_TestRetryJoin(:' \
67                 -i command/agent/command_test.go || die
68 }
69
70 src_compile() {
71         emake
72
73         if use web; then
74                 pushd ui >/dev/null || die
75                 emake dist
76         fi
77 }
78
79 src_install() {
80         local x
81
82         dobin bin/*
83         rm -rf bin
84
85         keepdir /etc/consul.d
86         insinto /etc/consul.d
87         doins "${FILESDIR}/"*.json.example
88
89         for x in /var/{lib,log}/${PN}; do
90                 keepdir "${x}"
91                 fowners consul:consul "${x}"
92         done
93
94         if use web; then
95                 insinto /var/lib/${PN}/ui
96                 doins -r ui/dist/*
97         fi
98
99         newinitd "${FILESDIR}/consul.initd" "${PN}"
100         newconfd "${FILESDIR}/consul.confd" "${PN}"
101         systemd_dounit "${FILESDIR}/consul.service"
102
103         find "${WORKDIR}"/{pkg,src} -name '.git*' -exec rm -rf {} \; 2>/dev/null
104         find "${WORKDIR}"/src/${GO_PN} -mindepth 1 -maxdepth 1 -type f -delete
105         while read -r -d '' x; do
106                 x=${x#${WORKDIR}/src}
107                 [[ -d ${WORKDIR}/pkg/${KERNEL}_${ARCH}/${x} ||
108                         -f ${WORKDIR}/pkg/${KERNEL}_${ARCH}/${x}.a ]] && continue
109                 rm -rf "${WORKDIR}"/src/${x}
110         done < <(find "${WORKDIR}"/src/${GO_PN} -mindepth 1 -maxdepth 1 -type d -print0)
111         insopts -m0644 -p # preserve timestamps for bug 551486
112         insinto /usr/lib/go/pkg/${KERNEL}_${ARCH}/${GO_PN%/*}
113         doins -r "${WORKDIR}"/pkg/${KERNEL}_${ARCH}/${GO_PN}
114         insinto /usr/lib/go/src/${GO_PN%/*}
115         doins -r "${WORKDIR}"/src/${GO_PN}
116 }