icingadb.spec 3.41 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}

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

%if "%{_vendor}" == "suse"
%global golang_pkg      go
%else # suse
%global golang_pkg      golang
Markus Frosch's avatar
Markus Frosch committed
16
%if 0%{?el7:1}
17
%global golang_scl      go-toolset-7
Markus Frosch's avatar
Markus Frosch committed
18
%endif # el7
Markus Frosch's avatar
Markus Frosch committed
19
%endif # suse
20 21 22 23 24 25 26 27 28 29 30 31 32 33

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

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

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

%{?systemd_requires}
BuildRequires:  systemd

Noah Hilverling's avatar
Noah Hilverling committed
55 56
%define debug_package %nil

Noah Hilverling's avatar
Noah Hilverling committed
57 58
Requires:       icinga-redis

59
%if "%{_vendor}" == "suse"
60 61 62 63 64 65 66
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
67
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
68 69 70 71 72 73 74 75

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

%description
Icinga DB

%prep
76
%setup -q
Alexander A. Klimov's avatar
Alexander A. Klimov committed
77 78

%build
Noah Hilverling's avatar
Noah Hilverling committed
79
export GO111MODULE=on
80 81 82 83 84 85 86 87

%gobuild .

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

Noah Hilverling's avatar
Noah Hilverling committed
88
#%%gotest ./...
Alexander A. Klimov's avatar
Alexander A. Klimov committed
89 90

%install
91 92 93 94 95
install -d -m 0755 %{buildroot}%{_sbindir}
install -d -m 0755 %{buildroot}%{configdir}
install -d -m 0755 %{buildroot}%{_unitdir}

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

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

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

Alexander A. Klimov's avatar
Alexander A. Klimov committed
106 107 108 109
%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
110 111 112 113
%if "%{_vendor}" == "suse"
%service_add_pre %{service}
%endif # suse

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

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

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

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
140
#%%doc AUTHORS COPYING README.md
141 142 143
%{_sbindir}/icingadb
%{_unitdir}/%{service}

Markus Frosch's avatar
Markus Frosch committed
144 145 146 147
%if "%{_vendor}" == "suse"
%{_sbindir}/rc%{name}
%endif # suse

Markus Frosch's avatar
Markus Frosch committed
148 149 150
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/schema

151
%defattr(0640,icingadb,icingadb,0750)
152 153

%dir %{configdir}
154
%config(noreplace) %{configdir}/icingadb.ini
155 156 157 158

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