Files
weewx/pkg/weewx.spec.in
2017-02-09 22:58:14 -05:00

179 lines
5.7 KiB
RPMSpec

# spec for building a weewx rpm for redhat or suse systems
# 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
%global dst_user_dir %{dst_bin_dir}/user
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 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 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}
# 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%^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%SQLITE_ROOT = .*%SQLITE_ROOT = /var/lib/weewx%' \
> %{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
# 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
chkconfig weewx on
%{initdir}/weewx start
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
%{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_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