%global debug_package %{nil}
%global pversion 2.15.2
%global pname prometheus-%{pversion}.linux-amd64
%global commit d9613e5c466c6e9de548c4dae1b9aabf9aaf7c57

Name:           prometheus
Version:        2.15.2
Release:        0.1%{?dist}
Summary:        The Prometheus monitoring system and time series database.
License:        ASL 2.0
URL:            https://prometheus.io
Source0:	https://github.com/prometheus/%{name}/archive/%{commit}/%{name}-%{commit}.tar.gz
Source1:        %{name}.service
Source2:	%{name}.sysconfig
Source3:        https://storage.googleapis.com/golang/go1.13.6.linux-amd64.tar.gz
BuildRequires:  systemd
Requires(pre): shadow-utils
%{?systemd_requires}

%pre
getent group %{name} >/dev/null || groupadd -r %{name}
getent passwd %{name} >/dev/null || \
    useradd -r -g %{name} -d %{_sharedstatedir}/%{name} -s /sbin/nologin \
    -c "Prometheus monitoring" %{name}
exit 0

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service

%description
The Prometheus monitoring system and time series database.

%prep
%setup -q -c
%setup -q -T -D -a 3

%build

mkdir -p goapp/src/github.com/prometheus
mv %{name}-%{commit} goapp/src/github.com/prometheus/%{name}
export GOROOT=${PWD}/go
export GOPATH=${PWD}/goapp
export PATH=${PWD}/go/bin:${PATH}
# go install github.com/prometheus/%{name}
#cd goapp/src/github.com/prometheus/%{name}
go install github.com/prometheus/%{name}/cmd/{prometheus,promtool}

%install
rm -rf $RPM_BUILD_ROOT
%{__install} -d $RPM_BUILD_ROOT%{_bindir}
%{__install} -v -D -t $RPM_BUILD_ROOT%{_bindir} goapp/bin/prometheus
%{__install} -v -D -t $RPM_BUILD_ROOT%{_bindir} goapp/bin/promtool
%{__install} -d $RPM_BUILD_ROOT%{_unitdir}
%{__install} -v -D -t $RPM_BUILD_ROOT%{_unitdir} %{SOURCE1}
%{__install} -d -m 0755 %{buildroot}%{_sysconfdir}/%{name}
%{__install} -m 644 -t %{buildroot}%{_sysconfdir}/%{name} goapp/src/github.com/prometheus/%{name}/documentation/examples/prometheus.yml
%{__install} -d $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
%{__install} -m 644 -T %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_datadir}/%{name}/consoles $RPM_BUILD_ROOT%{_datadir}/%{name}/console_libraries
%{__install} -v -D -t $RPM_BUILD_ROOT%{_datadir}/%{name}/console_libraries goapp/src/github.com/prometheus/%{name}/console_libraries/*
%{__install} -v -D -t $RPM_BUILD_ROOT%{_datadir}/%{name}/consoles goapp/src/github.com/prometheus/%{name}/consoles/*

%{__install} -d -m 0755 %{buildroot}%{_sharedstatedir}/%{name}

%files
%license goapp/src/github.com/prometheus/%{name}/LICENSE
%doc goapp/src/github.com/prometheus/%{name}/NOTICE
%{_bindir}/%{name}
%{_bindir}/promtool
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/consoles
%dir %{_datadir}/%{name}/console_libraries
%{_datadir}/%{name}/consoles/*
%{_datadir}/%{name}/console_libraries/*
%dir %attr(-,%{name},%{name}) %{_sharedstatedir}/%{name}
%{_unitdir}/%{name}.service
%config(noreplace) %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}

%changelog
* Mon Aug 22 2016 Paul Komkoff <i@stingr.net>
- foo