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

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

10
%global golang_min_version 1.11
Markus Frosch's avatar
Markus Frosch committed
11 12 13 14 15 16

%if "%{_vendor}" == "suse"
%global golang_pkg      go
%else # suse
%global golang_pkg      golang
%endif # suse
17 18 19 20 21 22 23 24 25 26 27 28 29 30

%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
31
Name:       icingadb
32
Version:    0.0.0
Alexander A. Klimov's avatar
Alexander A. Klimov committed
33 34 35
Release:    %{revision}%{?dist}
Summary:    Icinga DB
Group:      System Environment/Daemons
Markus Frosch's avatar
Markus Frosch committed
36 37 38
%if "%{_vendor}" == "suse"
License:    GPL-2.0-or-later
%else
Markus Frosch's avatar
Markus Frosch committed
39
License:    GPLv2+
Markus Frosch's avatar
Markus Frosch committed
40
%endif # suse
41
URL:        https://%{provider_prefix}
42
Source0:    https://%{import_path}/archive/v%{version}.tar.gz
Alexander A. Klimov's avatar
Alexander A. Klimov committed
43 44

BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}
45

Markus Frosch's avatar
Markus Frosch committed
46
BuildRequires:  %{?golang_scl_prefix}%{golang_pkg} >= %{golang_min_version}
47
BuildRequires:  git
Alexander A. Klimov's avatar
Alexander A. Klimov committed
48 49 50 51

%{?systemd_requires}
BuildRequires:  systemd

Noah Hilverling's avatar
Noah Hilverling committed
52 53
%define debug_package %nil

Noah Hilverling's avatar
Noah Hilverling committed
54 55
Requires:       icinga-redis

56
%if "%{_vendor}" == "suse"
57 58 59 60 61 62 63
PreReq:         permissions
Provides:       user(icingadb)
Provides:       group(icingadb)
Requires(pre):  shadow
Requires(post): shadow
%else # suse
Requires(pre):  shadow-utils
Markus Frosch's avatar
Markus Frosch committed
64
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
65 66 67 68 69 70 71 72

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

%description
Icinga DB

%prep
73
%setup -q
Alexander A. Klimov's avatar
Alexander A. Klimov committed
74 75

%build
Noah Hilverling's avatar
Noah Hilverling committed
76
export GO111MODULE=on
77 78 79 80 81 82 83 84

%gobuild .

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

Noah Hilverling's avatar
Noah Hilverling committed
85
#%%gotest ./...
Alexander A. Klimov's avatar
Alexander A. Klimov committed
86 87

%install
88 89 90 91 92
install -d -m 0755 %{buildroot}%{_sbindir}
install -d -m 0755 %{buildroot}%{configdir}
install -d -m 0755 %{buildroot}%{_unitdir}

install -m 0755 icingadb %{buildroot}%{_sbindir}/
93
install -m 0644 icingadb.ini %{buildroot}%{configdir}/icingadb.ini
94
install -m 0644 etc/%{service} %{buildroot}%{_unitdir}/
Alexander A. Klimov's avatar
Alexander A. Klimov committed
95

Markus Frosch's avatar
Markus Frosch committed
96 97 98
install -d -m 0755 %{buildroot}%{_datadir}/%{name}
(umask 0022 && cp -rv etc/schema %{buildroot}%{_datadir}/%{name}/)

Markus Frosch's avatar
Markus Frosch committed
99 100 101 102
%if "%{_vendor}" == "suse"
ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}
%endif # suse

Alexander A. Klimov's avatar
Alexander A. Klimov committed
103 104 105 106
%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

Markus Frosch's avatar
Markus Frosch committed
107 108 109 110
%if "%{_vendor}" == "suse"
%service_add_pre %{service}
%endif # suse

Alexander A. Klimov's avatar
Alexander A. Klimov committed
111
%post
Markus Frosch's avatar
Markus Frosch committed
112 113 114
%if "%{_vendor}" == "suse"
%service_add_post %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
115
%systemd_post %{service}
Markus Frosch's avatar
Markus Frosch committed
116
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
117 118

%preun
Markus Frosch's avatar
Markus Frosch committed
119 120 121
%if "%{_vendor}" == "suse"
%service_del_preun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
122
%systemd_preun %{service}
Markus Frosch's avatar
Markus Frosch committed
123
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
124 125

%postun
Markus Frosch's avatar
Markus Frosch committed
126 127 128
%if "%{_vendor}" == "suse"
%service_del_postun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
129
%systemd_postun %{service}
Markus Frosch's avatar
Markus Frosch committed
130
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
131 132 133 134 135 136

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
137
#%%doc AUTHORS COPYING README.md
138 139 140
%{_sbindir}/icingadb
%{_unitdir}/%{service}

Markus Frosch's avatar
Markus Frosch committed
141 142 143 144
%if "%{_vendor}" == "suse"
%{_sbindir}/rc%{name}
%endif # suse

Markus Frosch's avatar
Markus Frosch committed
145 146 147
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/schema

148
%defattr(0640,icingadb,icingadb,0750)
149 150

%dir %{configdir}
151
%config(noreplace) %{configdir}/icingadb.ini
152 153 154 155

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