Files
weewx/pkg/weewx.spec.in
2013-10-19 01:50:55 +00:00

166 lines
5.2 KiB
RPMSpec

# spec for building a weewx rpm for redhat or suse systems
# $Id$
# License: GPLv3
# Author: (c) 2013 Matthew Wall
# suse
%if 0%{?suse_version}
#%define relos .suse%{suse_version}
%define relos .suse
%define platform suse
%define initdir /etc/init.d
%define deps , python-pyserial, python-usb
%endif
%if 0%{?sles_version}
#%define relos .sles%{sles_version}
%define relos .sles
%define platform suse
%define initdir /etc/init.d
%define deps , python-pyserial, python-usb
%endif
# 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
%endif
%global relnum 1
%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
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
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 the 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 skins %{buildroot}%{dst_cfg_dir}
cp -r util/apache %{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}
# copy the setup script so we can do config file merges if necessary
cp weewx.conf %{buildroot}%{dst_cfg_dir}/weewx.conf.dist
cp setup.py %{buildroot}%{dst_bin_dir}
cp merge_config.py %{buildroot}%{dst_bin_dir}
# remove stuff that should not go out
rm %{buildroot}%{dst_cfg_dir}/skins/Standard/backgrounds/butterfly.jpg
rm %{buildroot}%{dst_cfg_dir}/skins/Standard/backgrounds/drops.gif
rm %{buildroot}%{dst_cfg_dir}/skins/Standard/backgrounds/flower.jpg
rm %{buildroot}%{dst_cfg_dir}/skins/Standard/backgrounds/leaf.jpg
rm %{buildroot}%{dst_cfg_dir}/skins/Standard/backgrounds/night.gif
# patch paths in files we care about
cat weewx.conf | sed \
-e 's%station_type =.*%station_type = Simulator%' \
-e 's%^WEEWX_ROOT =.*%WEEWX_ROOT = /%' \
-e 's%SKIN_ROOT =.*%SKIN_ROOT = /etc/weewx/skins%' \
-e 's%HTML_ROOT =.*%HTML_ROOT = /var/www/html/weewx%' \
-e 's%archive/weewx.sdb%/var/lib/weewx/weewx.sdb%' \
-e 's%archive/stats.sdb%/var/lib/weewx/stats.sdb%' \
> %{buildroot}%{dst_cfg_dir}/weewx.conf
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
chmod 755 %{buildroot}%{initdir}/weewx
# create symlinks to the code entry points
ln -s ../share/weewx/weewxd %{buildroot}%{_bindir}/weewxd
ln -s ../share/weewx/wee_reports %{buildroot}%{_bindir}/wee_reports
ln -s ../share/weewx/wee_config_database %{buildroot}%{_bindir}/wee_config_database
ln -s ../share/weewx/wee_config_fousb %{buildroot}%{_bindir}/wee_config_fousb
ln -s ../share/weewx/wee_config_vantage %{buildroot}%{_bindir}/wee_config_vantage
ln -s ../share/weewx/wee_config_ws28xx %{buildroot}%{_bindir}/wee_config_ws28xx
# pre-compile the python code
python -m compileall %{buildroot}%{dst_bin_dir}
%post
python -m compileall %{dst_bin_dir}
if [ "$1" = "1" ]; then
# this is a new installation
chkconfig weewx on
%{initdir}/weewx start
elif [ "$1" = "2" ]; then
# this is an upgrade
# merge changes to weewx.conf
if [ -f %{cfg_file}.dist ]; then
NEWVER=`/usr/share/weewx/merge_config.py --version`
OLDVER=`grep version %{cfg_file} | sed -e 's/\s*version\s*=\s*//'`
echo saving previous config file as %{cfg_file}-$OLDVER
mv %{cfg_file} %{cfg_file}-$OLDVER
echo saving distribution config file as %{cfg_file}-$NEWVER
cp -p %{cfg_file}.dist %{cfg_file}-$NEWVER
echo merging previous and distribution into %{cfg_file}
/usr/share/weewx/merge_config.py --install-dir / --a %{cfg_file}-$NEWVER --b %{cfg_file}-$OLDVER --c %{cfg_file}
fi
# do a full restart not just a HUP
%{initdir}/weewx stop
%{initdir}/weewx start
fi
%preun
if [ "$1" = "0" ]; then
# this is an uninstall, so stop and remove everything
%{initdir}/weewx stop
chkconfig weewx off
fi
# otherwise this is an upgrade (1), so do nothing
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root)
%attr(755,root,root) %{initdir}/weewx
%{dst_bin_dir}/
%{_bindir}/weewxd
%{_bindir}/wee_reports
%{_bindir}/wee_config_database
%{_bindir}/wee_config_fousb
%{_bindir}/wee_config_vantage
%{_bindir}/wee_config_ws28xx
%doc %{dst_doc_dir}/
%config(noreplace) %{dst_cfg_dir}/
%changelog