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

Markus Frosch's avatar
Markus Frosch committed
13 14 15 16 17 18
%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
19
%if 0%{?el7:1}
20
%global golang_scl      go-toolset-7
Markus Frosch's avatar
Markus Frosch committed
21
%endif # el7
Markus Frosch's avatar
Markus Frosch committed
22
%endif # suse
23 24 25 26 27 28 29 30 31 32 33 34 35 36

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

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

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

%{?systemd_requires}
BuildRequires:  systemd

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

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

%description
Icinga DB

%prep
Markus Frosch's avatar
Markus Frosch committed
75
%setup -q -n %{name}-%{commit}
Alexander A. Klimov's avatar
Alexander A. Klimov committed
76 77

%build
78 79 80 81 82 83 84 85 86 87 88 89 90 91
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

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

pushd src/%{import_path}
Markus Frosch's avatar
Markus Frosch committed
95
%gotest ./...
96
popd
Alexander A. Klimov's avatar
Alexander A. Klimov committed
97 98

%install
99 100 101 102 103 104 105
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
106

Markus Frosch's avatar
Markus Frosch committed
107 108 109 110
%if "%{_vendor}" == "suse"
ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}
%endif # suse

Alexander A. Klimov's avatar
Alexander A. Klimov committed
111 112 113 114
%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
115 116 117 118
%if "%{_vendor}" == "suse"
%service_add_pre %{service}
%endif # suse

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

%preun
Markus Frosch's avatar
Markus Frosch committed
127 128 129
%if "%{_vendor}" == "suse"
%service_del_preun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
130
%systemd_preun %{service}
Markus Frosch's avatar
Markus Frosch committed
131
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
132 133

%postun
Markus Frosch's avatar
Markus Frosch committed
134 135 136
%if "%{_vendor}" == "suse"
%service_del_postun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
137
%systemd_postun %{service}
Markus Frosch's avatar
Markus Frosch committed
138
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
139 140 141 142 143 144

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
145 146
#%%doc AUTHORS COPYING
%doc README.md
147 148 149
%{_sbindir}/icingadb
%{_unitdir}/%{service}

Markus Frosch's avatar
Markus Frosch committed
150 151 152 153
%if "%{_vendor}" == "suse"
%{_sbindir}/rc%{name}
%endif # suse

154
%defattr(0640,icingadb,icingadb,0750)
155 156 157

%dir %{configdir}
%config(noreplace) %{configdir}/config.ini
158 159 160 161

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