-
Notifications
You must be signed in to change notification settings - Fork 300
/
weewx.spec.in
226 lines (201 loc) · 6.98 KB
/
weewx.spec.in
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
# spec for building a weewx rpm for redhat or suse systems
# License: GPLv3
# Author: (c) 2013-2020 Matthew Wall
# the operating system release number is specified externaly, so that we can
# do cross-release (but not cross-platform) packaging.
%define os_target OSREL
# suse 12: python2
%if 0%{?suse_version} && "%{os_target}" == "12"
%define relos .suse12
%define platform suse
%define initdir /etc/systemd/system
%define deps python , python-configobj , python-cheetah , python-imaging , python-pyserial, python-usb
%define python python
%define html_root /srv/www/htdocs/weewx
%endif
# suse 15: python3
%if 0%{?suse_version} && "%{os_target}" == "15"
%define relos .suse15
%define platform suse
%define initdir /etc/systemd/system
%define deps python3, python3-setuptools, python3-configobj, python3-Cheetah3, python3-Pillow, python3-pyserial, python3-usb
%define python python3
%define html_root /var/www/html/weewx
%endif
# suse linux enterprise server
%if 0%{?sles_version}
%define relos .sles
%define platform suse
%define initdir /etc/systemd/system
#define initdir /etc/init.d
%define deps python , python-configobj , python-cheetah , python-imaging , python-pyserial, python-usb
%define html_root /srv/www/htdocs/weewx
%define python python
%endif
# rh8: python3 on redhat, fedora, centos
%if "%{_vendor}" == "redhat" && "%{os_target}" == "8"
%define relos .el8
%define platform redhat
%define initdir %{_initrddir}
# must install cheetah from epel-release or using pip3
%define deps python3, python3-setuptools, python3-configobj, python3-pillow, python3-pyserial, python3-pyusb
%define python python3
%define html_root /var/www/html/weewx
# Disable Fedora's shebang mangling script,
# which errors out on any file with versionless `python` in its shebang
# See: https://github.com/atom/atom/issues/21937
%undefine __brp_mangle_shebangs
%endif
%global relnum RPMREVISION
%global release %{relnum}%{?relos:%{relos}}
%global dst_bin_dir %{_datadir}/%{name}
%global dst_doc_dir %{_defaultdocdir}/%{name}-%{version}
%global dst_cfg_dir %{_sysconfdir}/%{name}
%global cfg_file %{dst_cfg_dir}/weewx.conf
%global dst_user_dir %{dst_bin_dir}/user
%define entry_points weewxd wee_config wee_database wee_debug wee_device wee_extension wee_import wee_reports
Summary: weather software
Name: weewx
Version: WEEWX_VERSION
Release: %{release}
Group: Applications/Science
Source: %{name}-%{version}.tar.gz
URL: http://www.weewx.com
License: GPLv3
AutoReqProv: no
Requires: %{deps}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
BuildArch: noarch
%description
weewx interacts with a weather station to produce graphs, reports, and HTML
pages. weewx can upload data to weather services such as WeatherUnderground,
PWSweather.com, or CWOP.
%prep
%setup -q
%build
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{dst_bin_dir}
mkdir -p %{buildroot}%{dst_doc_dir}
mkdir -p %{buildroot}%{dst_cfg_dir}
mkdir -p %{buildroot}%{initdir}
mkdir -p %{buildroot}/etc/default
# copy files from the source tree
cp -r bin/* %{buildroot}%{dst_bin_dir}
cp -r ../../docs/* %{buildroot}%{dst_doc_dir}
cp -r examples %{buildroot}%{dst_doc_dir}
cp -r skins %{buildroot}%{dst_cfg_dir}
cp -r util/apache %{buildroot}%{dst_cfg_dir}
cp -r util/import %{buildroot}%{dst_cfg_dir}
cp -r util/logrotate.d %{buildroot}%{dst_cfg_dir}
cp -r util/logwatch %{buildroot}%{dst_cfg_dir}
cp -r util/rsyslog.d %{buildroot}%{dst_cfg_dir}
cp -r util/udev %{buildroot}%{dst_cfg_dir}
# patch paths in files we care about
cat weewx.conf | sed \
-e 's%^WEEWX_ROOT =.*%WEEWX_ROOT = /%' \
-e 's%SKIN_ROOT =.*%SKIN_ROOT = /etc/weewx/skins%' \
-e 's:HTML_ROOT = public_html:HTML_ROOT = %{html_root}:' \
-e 's%SQLITE_ROOT = .*%SQLITE_ROOT = /var/lib/weewx%' \
> %{buildroot}%{dst_cfg_dir}/weewx.conf
%if "%{initdir}" == "/etc/systemd/system"
cat util/systemd/weewx.service | sed \
-e 's%ExecStart=.*%ExecStart=/usr/bin/weewxd /etc/weewx/weewx.conf%' \
> %{buildroot}%{initdir}/weewx.service
%else
cp util/init.d/weewx.%{platform} %{buildroot}%{initdir}/weewx
%endif
# make a copy of the generic configuration file
cp %{buildroot}%{dst_cfg_dir}/weewx.conf %{buildroot}%{dst_cfg_dir}/weewx.conf.dist
# create the entry points
for f in %{entry_points}; do \
cp util/scripts/$f %{buildroot}%{_bindir}/$f; \
done
# massage the shebangs in the entry points to pacify fascist redhat build tools
for f in %{entry_points}; do \
sed -i -e 's:/usr/bin/env python:/usr/bin/%{python}:' %{buildroot}/usr/share/weewx/$f; \
done
# configure application layout
cat util/default/weewx | sed \
-e 's%WEEWX_PYTHON=.*%WEEWX_PYTHON=%{python}%' \
-e 's%WEEWX_BINDIR=.*%WEEWX_BINDIR=/usr/share/weewx%' \
-e 's%WEEWX_BIN=.*%WEEWX_BIN=/usr/bin/weewxd%' \
-e 's%WEEWX_CFG=.*%WEEWX_CFG=/etc/weewx/weewx.conf%' \
> %{buildroot}/etc/default/weewx
%pre
if [ "$1" = "2" ]; then
# this is an upgrade
if [ -f %{cfg_file} ]; then
echo saving previous config as %{cfg_file}.prev
cp -p %{cfg_file} %{cfg_file}.prev
fi
fi
%post
# pre-compile the python code
%{python} -m compileall %{dst_bin_dir}
if [ "$1" = "1" ]; then
# this is a new installation
# create a sane configuration file with simulator as the station type
/usr/bin/wee_config --install --dist-config=/etc/weewx/weewx.conf.dist --output=/etc/weewx/weewx.conf --driver=weewx.drivers.simulator --no-prompt --no-backup
if [ -f /etc/systemd/system/weewx.service ]; then
systemctl enable weewx
systemctl start weewx
else
chkconfig weewx on
%{initdir}/weewx start
fi
elif [ "$1" = "2" ]; then
# this is an upgrade
# update previous config and merge with dist into to weewx.conf
if [ -f %{cfg_file}.dist -a -f %{cfg_file}.prev ]; then
OLDVER=`grep version %{cfg_file}.prev | sed -e 's/\s*version\s*=\s*//'`
echo saving previous config as %{cfg_file}-$OLDVER
mv %{cfg_file}.prev %{cfg_file}-$OLDVER
echo merging configs into %{cfg_file}
/usr/bin/wee_config --upgrade --config=%{cfg_file}-$OLDVER --dist-config=%{cfg_file}.dist --output=%{cfg_file} --no-prompt --no-backup
fi
# do a full restart not just a HUP
if [ -f /etc/systemd/system/weewx.service ]; then
systemctl stop weewx
systemctl start weewx
else
%{initdir}/weewx stop
%{initdir}/weewx start
fi
fi
%preun
if [ "$1" = "0" ]; then
# this is an uninstall, so stop and remove everything
if [ -f /etc/systemd/system/weewx.service ]; then
systemctl stop weewx
systemctl disable weewx
else
%{initdir}/weewx stop
chkconfig weewx off
fi
fi
# otherwise this is an upgrade (1), so do nothing
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root)
%if "%{initdir}" == "/etc/systemd/system"
%{initdir}/weewx.service
%else
%attr(755,root,root) %{initdir}/weewx
%endif
%{_sysconfdir}/default/weewx
%{dst_bin_dir}/
%{_bindir}/weewxd
%{_bindir}/wee_config
%{_bindir}/wee_database
%{_bindir}/wee_debug
%{_bindir}/wee_device
%{_bindir}/wee_extension
%{_bindir}/wee_import
%{_bindir}/wee_reports
%doc %{dst_doc_dir}/
%config(noreplace) %{dst_cfg_dir}/
%config(noreplace) %{dst_user_dir}/extensions.py
%changelog