-# TODO:
-# - update paths and pld patches
-# - avoid messing in halt script in %post
+#
+# Conditional build:
+%bcond_without test # without TEST support
+%bcond_without usb # without USB support
+%bcond_without net # without network support
+%bcond_without cgi # with CGI program support
+%bcond_with snmp # with SNMP support
+#
Summary: Power management software for APC UPS hardware
Summary(pl): Oprogramowanie do zarz±dzania energi± dla UPS-ów APC
Name: apcupsd
-Version: 3.10.5
+Version: 3.12.1
Release: 0.1
License: GPL v2
Group: Networking/Daemons
Source0: http://dl.sourceforge.net/apcupsd/%{name}-%{version}.tar.gz
-Patch0: %{name}-paths.patch
-Patch1: %{name}-pld.patch
-#Patch1: apcups-makefile.patch
-#Patch2: %{name}-Makefile-fix.patch
+# Source0-md5: d2e710176430a28d624500e145d9ffe3
+Source1: %{name}.init
+Source2: %{name}.logrotate
+Source3: %{name}.sysconfig
+Patch0: %{name}-configure.patch
URL: http://www.apcupsd.com/
-Requires(post,preun): /sbin/chkconfig
+BuildRequires: autoconf
+BuildRequires: automake
+%{?with_snmp:BuildRequires: net-snmp-devel}
Requires(post): fileutils
+Requires(post,preun): /sbin/chkconfig
+Requires: rc-scripts
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%define _sysconfdir /etc/apcupsd
+%define _cgidir /home/services/httpd/cgi-bin
%description
UPS power management under Linux for APCC Products. It allows your
odpowiednio uruchamia kontrolowany shutdown przy d³u¿szej awarii
zasilania.
+%package cgi
+Summary: upsstats - Web-based UPS status viewer
+Summary(pl): upsstats - oparta na WWW przegl±darka stanu UPS-a
+Group: Applications/Networking
+Requires: webserver
+
+%description cgi
+upsstats.cgi builds a lightweight web page containing basic UPS status
+information.
+
+%description cgi -l pl
+upsstats.cgi tworzy lekk± stronê WWW zawieraj±c± podstawowe informacje
+o stanie UPS-a.
+
%prep
%setup -q
-#%patch0 -p1 -- configure should be patched to move files from /var/log to /var/lib
-#%patch1 -p1 -- probably should be updated
-#%patch2 -p0
+#%patch0 -p1
%build
-%configure2_13
+cd autoconf
+cp -f /usr/share/automake/config.sub .
+%{__autoconf}
+cp -f configure ..
+cd ..
+
+%configure \
+ --with-log-dir=%{_var}/log \
+ --with-stat-dir=%{_var}/lib/apcupsd \
+%if %{with cgi}
+ --enable-cgi \
+ --with-cgi-bin=/home/services/httpd/cgi-bin \
+%endif
+ %{?with_test:--enable-test} \
+%if %{with net}
+ --enable-net \
+ --enable-master-slave \
+%endif
+ %{?with_snmp:--enable-snmp} \
+ %{?with_usb:--enable-usb}
+
%{__make}
%install
rm -rf $RPM_BUILD_ROOT
-#install -d $RPM_BUILD_ROOT{/etc/rc.d/init.d,/var/log,/var/lib/apcupsd}
+install -d $RPM_BUILD_ROOT/etc/{apcupsd,logrotate.d,rc.d/init.d,sysconfig} \
+ $RPM_BUILD_ROOT/var/{log,lib/apcupsd}
%{__make} install \
DESTDIR=$RPM_BUILD_ROOT
-install platforms/redhat/apcupsd $RPM_BUILD_ROOT/etc/rc.d/init.d/apcupsd
-#install platforms/pld/apcupsd $RPM_BUILD_ROOT/etc/rc.d/init.d/apcupsd
+install %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/apcupsd
+install %{SOURCE2} $RPM_BUILD_ROOT/etc/logrotate.d/apcupsd
+install %{SOURCE3} $RPM_BUILD_ROOT/etc/sysconfig/apcupsd
-touch $RPM_BUILD_ROOT/var/log/apcupsd.log
+touch $RPM_BUILD_ROOT/var/log/apcupsd.events
touch $RPM_BUILD_ROOT/var/lib/apcupsd/apcupsd.status
-touch $RPM_BUILD_ROOT/var/lib/apcupsd/apcupsd.events
+
+cat > $RPM_BUILD_ROOT/etc/rc.d/init.d/halt << EOF
+#!/bin/sh
+/etc/rc.d/init.d/apcupsd powerdown
+EOF
%clean
rm -rf $RPM_BUILD_ROOT
%post
/sbin/chkconfig --add apcupsd
-
-#if !(grep /sbin/powersc /etc/rc.d/init.d/halt > /dev/null); then
-cp -f /etc/rc.d/init.d/halt /etc/rc.d/init.d/halt.rpmorig
-#sed -e '/# Now halt or reboot./i\' \
-# -e '\
-# See if this is a powerfail situation.\
-
-echo '
-if [ -f /etc/apcupsd/powerfail ]; then\
- echo "APCUPSD to the Rescue!"\
- echo\
- /etc/apcupsd/apccontrol killpower \
- echo\
- sleep 120\
- exit 1\
-fi\
-' > /etc/rc.d/init.d/halt
-#' /etc/rc.d/init.d/halt.rpmorig > /etc/rc.d/init.d/halt
-#fi
-chmod 754 /etc/rc.d/init.d/halt
+if [ -f /var/lock/subsys/apcupsd ]; then
+ /etc/rc.d/init.d/apcupsd restart >&2
+else
+ echo "Run \"/etc/rc.d/init.d/apcupsd start\" to start apcupsd daemon."
+fi
%preun
if [ "$1" = "0" ]; then
+ if [ -f /var/lock/subsys/apcupsd ]; then
+ /etc/rc.d/init.d/apcupsd stop >&2
+ fi
/sbin/chkconfig --del apcupsd
fi
%files
%defattr(644,root,root,755)
-%doc ChangeLog Developers doc/{README.apcaccess,developers_manual,home-page,logo,manual}
-%{_mandir}/man8/apcupsd.*
+%doc ChangeLog Developers
%attr(755,root,root) %{_sbindir}/*
-#%attr(755,root,root) %config /sbin/powersc
-%attr(640,root,root) %config(noreplace) %{_sysconfdir}/apcupsd.conf
+%attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/apcupsd.conf
+%attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/apcupsd
+%attr(754,root,root) %{_sysconfdir}/apccontrol
+%attr(754,root,root) %{_sysconfdir}/changeme
+%attr(754,root,root) %{_sysconfdir}/commfailure
+%attr(754,root,root) %{_sysconfdir}/commok
+#%attr(754,root,root) %{_sysconfdir}/mainsback
+%attr(754,root,root) %{_sysconfdir}/masterconnect
+%attr(754,root,root) %{_sysconfdir}/mastertimeout
+%attr(754,root,root) %{_sysconfdir}/onbattery
+%attr(754,root,root) %{_sysconfdir}/offbattery
+%if %{with cgi}
+%config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/hosts.conf
+%config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/multimon.conf
+%{_sysconfdir}/apcupsd.css
+%endif
%attr(754,root,root) /etc/rc.d/init.d/apcupsd
-%ghost /var/log/apcupsd.log
-%ghost /var/lib/apcupsd/apcupsd.status
-%ghost /var/lib/apcupsd/apcupsd.events
+%attr(754,root,root) /etc/rc.d/init.d/halt
+%attr(640,root,root) %config(noreplace) %verify(not md5 mtime size) /etc/logrotate.d/apcupsd
+%dir %{_sysconfdir}
+%dir /var/lib/apcupsd
+%attr(640,root,root) %ghost /var/log/apcupsd.events
+%attr(640,root,root) %ghost /var/lib/apcupsd/apcupsd.status
+%{_mandir}/man8/apcupsd.*
+
+%files cgi
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_cgidir}/*.cgi