icingadb.spec 3.47 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 58 59

%{?systemd_requires}
BuildRequires:  systemd

Requires(pre):  shadow-utils

60
%if "%{_vendor}" == "suse"
Alexander A. Klimov's avatar
Alexander A. Klimov committed
61 62
Provides:   user(icingadb)
Provides:   group(icingadb)
Markus Frosch's avatar
Markus Frosch committed
63
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
64 65 66 67 68 69 70 71

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

%description
Icinga DB

%prep
Markus Frosch's avatar
Markus Frosch committed
72
%setup -q -n %{name}-%{commit}
Alexander A. Klimov's avatar
Alexander A. Klimov committed
73 74

%build
75 76 77 78 79 80 81 82 83 84 85 86 87 88
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

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

pushd src/%{import_path}
Markus Frosch's avatar
Markus Frosch committed
92
%gotest ./...
93
popd
Alexander A. Klimov's avatar
Alexander A. Klimov committed
94 95

%install
96 97 98 99 100 101 102
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
103

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

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

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

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

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

%clean
rm -rf %{buildroot}

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

Markus Frosch's avatar
Markus Frosch committed
147 148 149 150
%if "%{_vendor}" == "suse"
%{_sbindir}/rc%{name}
%endif # suse

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

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

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