icingadb.spec 2.72 KB
Newer Older
Alexander A. Klimov's avatar
Alexander A. Klimov committed
1 2
%define revision 1

3 4 5 6 7 8 9
%global provider        git.icinga
%global provider_tld    com
%global project         icingadb
%global repo            icingadb
%global provider_prefix %{provider}.%{provider_tld}/%{project}/%{repo}
%global import_path     %{provider_prefix}

Markus Frosch's avatar
Markus Frosch committed
10 11 12
%global commit          f10596b960b05a492f4524c123a2522d4626a6e0
%global shortcommit     %(c=%{commit}; echo ${c:0:7})

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
%global golang_scl      go-toolset-7

%if 0%{?golang_scl:1}
%global golang_scl_prefix %{golang_scl}-
%global golang_scl_enable scl enable %{golang_scl} --
%endif

%if ! 0%{?gobuild:1}
%define gobuild(o:) %{?golang_scl_enable} go build -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n')" -a -v -x %{?**};
%endif

%if ! 0%{?gopath:1}
%define gopath %(%{?golang_scl_enable} go env GOPATH)
%endif

Alexander A. Klimov's avatar
Alexander A. Klimov committed
28
Name:       icingadb
Markus Frosch's avatar
Markus Frosch committed
29
Version:    0.0.0.%{shortcommit}
Alexander A. Klimov's avatar
Alexander A. Klimov committed
30 31 32 33
Release:    %{revision}%{?dist}
Summary:    Icinga DB
Group:      System Environment/Daemons
License:    GPLv2+
34
URL:        https://%{provider_prefix}
35
Source0:    https://%{import_path}/-/archive/%{commit}/%{repo}-%{version}.tar.gz
Alexander A. Klimov's avatar
Alexander A. Klimov committed
36 37

BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}
38 39 40

BuildRequires:  %{?golang_scl_prefix}golang >= 1.10
BuildRequires:  git
Alexander A. Klimov's avatar
Alexander A. Klimov committed
41 42 43 44 45 46

%{?systemd_requires}
BuildRequires:  systemd

Requires(pre):  shadow-utils

47
%if "%{_vendor}" == "suse"
Alexander A. Klimov's avatar
Alexander A. Klimov committed
48 49
Provides:   user(icingadb)
Provides:   group(icingadb)
50
%endif
Alexander A. Klimov's avatar
Alexander A. Klimov committed
51 52 53 54 55 56 57 58

%define configdir %{_sysconfdir}/%{name}
%define service %{name}.service

%description
Icinga DB

%prep
Markus Frosch's avatar
Markus Frosch committed
59
%setup -q -n %{name}-%{commit}
Alexander A. Klimov's avatar
Alexander A. Klimov committed
60 61

%build
62 63 64 65 66 67 68 69 70 71 72 73 74 75
mkdir -p src/%{provider}.%{provider_tld}/%{project}
ln -s ../../../ src/%{import_path}

export GOPATH=$(pwd):%{gopath}

pushd src/%{import_path}
%gobuild .
popd

%check
%if ! 0%{?gotest:1}
%global gotest %{?golang_scl_enable} go test
%endif

76 77 78
export GOPATH=$(pwd):%{gopath}

pushd src/%{import_path}
Markus Frosch's avatar
Markus Frosch committed
79
%gotest ./...
80
popd
Alexander A. Klimov's avatar
Alexander A. Klimov committed
81 82

%install
83 84 85 86 87 88 89
install -d -m 0755 %{buildroot}%{_sbindir}
install -d -m 0755 %{buildroot}%{configdir}
install -d -m 0755 %{buildroot}%{_unitdir}

install -m 0755 icingadb %{buildroot}%{_sbindir}/
install -m 0644 etc/config_production.ini %{buildroot}%{configdir}/config.ini
install -m 0644 etc/%{service} %{buildroot}%{_unitdir}/
Alexander A. Klimov's avatar
Alexander A. Klimov committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

%pre
getent group icingadb >/dev/null || groupadd -r icingadb
getent passwd icingadb >/dev/null || useradd -r -g icingadb -d / -s /sbin/nologin -c 'Icinga DB' icingadb

%post
%systemd_post %{service}

%preun
%systemd_preun %{service}

%postun
%systemd_postun %{service}

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
109 110
#%%doc AUTHORS COPYING
%doc README.md
111 112 113
%{_sbindir}/icingadb
%{_unitdir}/%{service}

114
%defattr(0640,icingadb,icingadb,0750)
115 116 117

%dir %{configdir}
%config(noreplace) %{configdir}/config.ini
118 119 120 121

%changelog
* Mon Sep 24 2018 Markus Frosch <markus.frosch@icinga.com> 0.0.0-0
- Initial package