summaryrefslogtreecommitdiffstats
path: root/SPECS/python-onionbalance.spec
blob: fee15fecf55bfaa11aa4e16d1fd393cfbb6bdf34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
%global tarname OnionBalance
%global pkgname onionbalance
%global sum Load-balancing for Tor onion services

# EL7 has a too old sphinx version
# to support generating of docs
%if 0%{?fedora} || 0%{?rhel} >= 8
%global with_python3 1
%global with_docs 1
%global main_pkg python3-%{pkgname}
%else
%global with_python3 0
%global with_docs 0
%global main_pkg python2-%{pkgname}
%if 0%{?rhel} == 7
%global for_el7 1
%endif
%endif

# test libs are too old for running tests on EL7 & F24
%if 0%{?fedora} >= 25
%global with_test 1
%endif

%{!?_pkgdocdir: %global _pkgdocdir %{_docdir}/%{main_pkg}-%{version}}

%global toruser toranon

Name:           python-%{pkgname}
Version:        0.1.6
Release:        1%{?dist}
Summary:        %{sum}

License:        GPLv3
URL:            http://pypi.python.org/pypi/%{tarname}
Source0:        https://github.com/DonnchaC/%{pkgname}/releases/download/%{version}/%{pkgname}-%{version}.tar.gz
Source1:        onionbalance.service
Source2:        onionbalance.tmpfiles
Source3:        onionbalance.logrotate
Source4:        docs-conf.py
Source5:        onionbalance.torrc.example
Source6:        README.fedora

BuildArch: noarch

BuildRequires: systemd-units

BuildRequires:  python2-devel
BuildRequires:  python-setuptools
%if 0%{?for_el7}
BuildRequires:  python-stem
%else
BuildRequires:  python2-stem
%endif
BuildRequires:  PyYAML
BuildRequires:  python2-crypto
BuildRequires:  python2-future
BuildRequires:  python-setproctitle
%if 0%{?with_test}
BuildRequires:  python2-pexpect
BuildRequires:  python2-pytest
BuildRequires:  python2-pytest-mock
%endif
%if 0%{?with_docs}
BuildRequires:  python2-sphinxcontrib-autoprogram
%endif

%if 0%{?with_python3}
BuildRequires:  python3-devel
BuildRequires:  python3-setuptools
BuildRequires:  python3-stem
BuildRequires:  python3-PyYAML
BuildRequires:  python3-crypto
BuildRequires:  python3-future
BuildRequires:  python3-setproctitle
BuildRequires:  python3-sphinxcontrib-autoprogram
%if 0%{?with_test}
BuildRequires:  python3-pytest
BuildRequires:  python3-pytest-mock
BuildRequires:  python3-pexpect
%endif
%endif

BuildRequires: systemd


%description
OnionBalance provides load-balancing and redundancy for Tor
onion services by distributing requests to multiple back-end
Tor instances.

%package -n python2-%{pkgname}
Summary:   %{sum}
Requires:  python-stem
Requires:  PyYAML
%if 0%{?for_el7}
Requires:  python-setuptools
%else
Requires:  python2-setuptools
%endif
Requires:  python2-crypto
Requires:  python2-future
Requires:  python-setproctitle
%{?python_provide:%python_provide python2-%{pkgname}}
%if 0%{?with_python3}

%package -n python3-%{pkgname}
Summary:   %{sum}
Requires:  python3-stem
Requires:  python3-PyYAML
Requires:  python3-setuptools
Requires:  python3-crypto
Requires:  python3-future
Requires:  python3-setproctitle
%{?python_provide:%python_provide python3-%{pkgname}}
%endif
Requires: tor
Requires: logrotate
Requires(pre): shadow-utils
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd


%description -n python2-%{pkgname}
OnionBalance provides load-balancing and redundancy for Tor
onion services by distributing requests to multiple back-end
Tor instances.
%if 0%{?with_python3}

%description -n python3-%{pkgname}
OnionBalance provides load-balancing and redundancy for Tor
onion services by distributing requests to multiple back-end
Tor instances.
This package contains systemd files as well as logrotate rules.
%else
This package contains systemd files as well as logrotate rules.
%endif

%prep
%autosetup -n %{pkgname}-%{version}

%build
find . -name '*.pyc' -delete
%py2_build
%if 0%{?with_python3}
%py3_build
%endif
%if 0%{?with_docs}
# restore conf that is missing in egg
cp %{SOURCE4} docs/conf.py
PYTHONPATH=. sphinx-build -N -v -v -v -v -E -bhtml docs/ docs/_build/html
PYTHONPATH=. sphinx-build -N -E -bman docs docs/_build/man
# Fix hidden-file-or-dir warnings
rm -rf docs/_build/html/.doctrees docs/_build/html/.buildinfo
%endif

%install
%py2_install
%if 0%{?with_python3}
cp %{buildroot}/%{_bindir}/%{pkgname} %{buildroot}/%{_bindir}/%{pkgname}-py2
cp %{buildroot}/%{_bindir}/%{pkgname}-config %{buildroot}/%{_bindir}/%{pkgname}-config-py2

%py3_install
%endif

%if 0%{?for_el7}
# EL7 isn't yet that new, but given it's only a little change btw. 3.11 & 3.10
# it's fine to downgrade that requirement
sed -i 's/PyYAML>=3.11/PyYAML>=3.10/' %{buildroot}/%{python2_sitelib}/*.egg-info/requires.txt
%endif

install -d        %{buildroot}/etc/logrotate.d
install -d        %{buildroot}/%{_sysconfdir}/%{pkgname}
install -d        %{buildroot}/%{_localstatedir}/log/%{pkgname}
install -d        %{buildroot}/%{_localstatedir}/lib/%{pkgname}
install -d -m 755 %{buildroot}/%{_unitdir}
install -d -m 755 %{buildroot}/%{_tmpfilesdir}

install -p -m 644 %{SOURCE1} %{buildroot}/%{_unitdir}/%{pkgname}.service
install -p -m 644 %{SOURCE2} %{buildroot}/%{_tmpfilesdir}/%{pkgname}.conf
install -p -m 644 %{SOURCE3} %{buildroot}/%{_sysconfdir}/logrotate.d/%{pkgname}.conf
%if 0%{?with_docs}
install -d -m 755 %{buildroot}/%{_mandir}/man1
cp docs/_build/man/%{pkgname}* %{buildroot}/%{_mandir}/man1/
%endif

install -p -m 644 %{SOURCE5} .
install -p -m 644 %{SOURCE6} .

%check
# on some versions test libs are too old to run
%if 0%{?with_test}
py.test   --ignore=test/functional
py.test-3 --ignore=test/functional
%endif

%pre -n %{main_pkg}
getent passwd %{pkgname} >/dev/null || \
    useradd -r -g %{toruser} -d %{_localstatedir}/lib/%{pkgname} -s /sbin/nologin \
    -c "%{pkgname} daemon user" %{pkgname}
exit 0

%post -n %{main_pkg}
%systemd_post onionbalance.service

%preun -n %{main_pkg}
%systemd_preun onionbalance.service

%postun -n %{main_pkg}
%systemd_postun_with_restart onionbalance.service

%files -n python2-%{pkgname}
%doc README.rst
%doc README.fedora
%doc onionbalance.torrc.example
%license COPYING
%doc docs/_build/html
%doc %attr(0644,root,root) %{_mandir}/man1/%{pkgname}*
%{python2_sitelib}/*
%if 0%{?with_python3}
%{_bindir}/%{pkgname}-py2
%{_bindir}/%{pkgname}-config-py2
%else
%{_bindir}/%{pkgname}
%{_bindir}/%{pkgname}-config
%{_unitdir}/%{pkgname}.service
%{_tmpfilesdir}/%{pkgname}.conf
%dir %attr(0750,root,%{toruser}) %{_sysconfdir}/%{pkgname}
%dir %attr(0750,%{pkgname},%{toruser}) %{_localstatedir}/log/%{pkgname}
%dir %attr(0750,%{pkgname},%{toruser}) %{_localstatedir}/lib/%{pkgname}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{pkgname}.conf
%endif

%if 0%{?with_python3}
%files -n python3-%{pkgname}
%doc README.rst
%doc README.fedora
%doc onionbalance.torrc.example
%license COPYING
%{python3_sitelib}/*
%{_bindir}/%{pkgname}
%{_bindir}/%{pkgname}-config
%{_unitdir}/%{pkgname}.service
%{_tmpfilesdir}/%{pkgname}.conf
%dir %attr(0750,root,%{toruser}) %{_sysconfdir}/%{pkgname}
%dir %attr(0750,%{pkgname},%{toruser}) %{_localstatedir}/log/%{pkgname}
%dir %attr(0750,%{pkgname},%{toruser}) %{_localstatedir}/lib/%{pkgname}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{pkgname}.conf
%if 0%{?with_docs}
%doc docs/_build/html
%doc %attr(0644,root,root) %{_mandir}/man1/%{pkgname}*
%endif
%endif

%changelog
* Fri Jan 20 2017 Marcel Haerry <mh+fedora@scrit.ch> - 0.1.6-1
  initial release