# spec for building a weewx rpm for redhat or suse systems # License: GPLv3 # Author: (c) 2013 Matthew Wall # Adapted for COPR by Ben Cotton # redhat, fedora, centos %if "%{_vendor}" == "redhat" #define relos %{?dist:%{dist}} %define relos .rhel %define platform redhat %define initdir %{_initrddir} # on redhat, must install serial and/or usb using easy_install or pip %define deps , python-setuptools %define html_root /var/www/html/weewx %endif %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 Summary: weather software Name: weewx Version: 3.9.2 Release: 1%{?dist} Group: Applications/Science Source: https://github.com/weewx/weewx/archive/v%{version}.tar.gz URL: http://www.weewx.com License: GPLv3 Requires: python, python-configobj, python-cheetah, python-imaging, %{deps} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n) BuildArch: noarch BuildRequires: python, python-configobj %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} # 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 --daemon --pidfile=/var/run/weewx.pid /etc/weewx/weewx.conf%' \ > %{buildroot}%{initdir}/weewx.service %else cat util/init.d/weewx.%{platform} | sed \ -e 's%WEEWX_BIN=.*%WEEWX_BIN=/usr/bin/weewxd%' \ -e 's%WEEWX_CFG=.*%WEEWX_CFG=/etc/weewx/weewx.conf%' \ > %{buildroot}%{initdir}/weewx %endif # make a copy of the generic-for-this-platform configuration file cp %{buildroot}%{dst_cfg_dir}/weewx.conf %{buildroot}%{dst_cfg_dir}/weewx.conf.dist # create symlinks to the code entry points ln -s ../share/weewx/weewxd %{buildroot}%{_bindir}/weewxd ln -s ../share/weewx/wee_config %{buildroot}%{_bindir}/wee_config ln -s ../share/weewx/wee_database %{buildroot}%{_bindir}/wee_database ln -s ../share/weewx/wee_debug %{buildroot}%{_bindir}/wee_debug ln -s ../share/weewx/wee_device %{buildroot}%{_bindir}/wee_device ln -s ../share/weewx/wee_extension %{buildroot}%{_bindir}/wee_extension ln -s ../share/weewx/wee_import %{buildroot}%{_bindir}/wee_import ln -s ../share/weewx/wee_reports %{buildroot}%{_bindir}/wee_reports ln -s ../share/weewx/wunderfixer %{buildroot}%{_bindir}/wunderfixer # pre-compile the python code python -m compileall %{buildroot}%{dst_bin_dir} %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 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/share/weewx/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/share/weewx/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 %{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 %{_bindir}/wunderfixer %doc %{dst_doc_dir}/ %config(noreplace) %{dst_cfg_dir}/ %config(noreplace) %{dst_user_dir}/extensions.py %changelog * Sun Dec 22 2019 Ben Cotton - 3.9.2-1 - Initial COPR packaging