File apcupsd.spec of Package apcupsd.import4958

#
# spec file for package apcupsd
#
# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

# norootforbuild


Name:           apcupsd
BuildRequires:  apache2-devel distribution-release dos2unix gcc-c++ gconf2-devel gd-devel gnome-vfs2-devel gtk2-devel mailx ncurses-devel net-snmp-devel tcpd-devel update-desktop-files
BuildRequires:  sysvinit
Group:          Hardware/UPS
License:        GPLv2+
Summary:        APC UPS Daemon (Powerful Daemon for APC UPSs)
Version:        3.14.6
Release:        13.<RELEASE16>
Url:            http://www.apcupsd.com/
Source:         apcupsd-%{version}.tar.bz2
Source1:        apcupsd.init
Source2:        README.SUSE
Source3:        apcupsd-early-powerdown.init
Patch:          apcupsd-suse.patch
Patch1:         apcupsd-gpp.patch
Patch3:         apcupsd-powersave.patch
Patch5:         apcupsd-largebuf-overflow.patch
Patch8:         apcupsd-3.14.5-const.patch
Patch9:         apcupsd-3.14.6-undef-MIB-for-new-net-snmp.diff
Patch10:        apcupsd-3.14.1-cloexec.patch
PreReq:         %fillup_prereq %insserv_prereq /usr/bin/sed /usr/bin/grep
Requires:       /usr/bin/mail
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%define apache_serverroot %(/usr/sbin/apxs2 -q datadir 2>/dev/null || /usr/sbin/apxs -q PREFIX)

%description
Controls and monitors the status of an APC UPS under Linux. Allows your
computer or server to run for a specified length of time on UPS power
then executes a controlled shutdown in the case of an extended power
failure. Find APC on the Internet at http://www.apc.com/.

APC also made their PowerChute plus available for download at
http://www.apc.com/tools/download/.

%package gui
License:        GPLv2+
Group:          Hardware/UPS
Summary:        APC UPS Monitor GUI (for APC UPSs)
Requires:       %{name} = %{version}

%description gui
Controls and monitors the status of an APC UPS under Linux. Allows your
computer or server to run for a specified length of time on UPS power
then executes a controlled shutdown in the case of an extended power
failure. Find APC on the Internet at http://www.apc.com/.

APC also made their PowerChute plus available for download at
http://www.apc.com/tools/download/.

%prep
%setup -q
rm include/tcpd.h
cp -a %{S:1} platforms/suse/apcupsd.in
cp -a %{S:2} .
cp -a %{S:3} apcupsd-early-powerdown
chmod +x apcupsd-early-powerdown
%patch
%patch1
%if %suse_version < 1110
%patch3
%endif
chmod -x kernstodo
%patch5
%patch8
%patch9
%patch10 -p1

%build
%{suse_update_config autoconf}
# Incomplete:
#cd autoconf
#aclocal
#autoconf
#cp configure ..
#cd ..
%if "%suse_version" == "910"
export CFLAGS="$RPM_OPT_FLAGS -DHID_MAX_USAGES=1024"
%endif
%configure\
	--sbindir=/sbin\
	--sysconfdir=%{_sysconfdir}/apcupsd\
	--enable-usb\
	--enable-nls\
	--with-cgi-bin=%{apache_serverroot}/cgi-bin
make %{?jobs:-j %jobs}
cp -a src/apcupsd src/apcupsd-lite
make clean
%configure\
	--sysconfdir=%{_sysconfdir}/apcupsd\
	--with-libwrap\
	--enable-all\
	--enable-nls\
	--with-cgi-bin=%{apache_serverroot}/cgi-bin
make %{?jobs:-j %jobs}

%install
%makeinstall
mkdir -p $RPM_BUILD_ROOT/sbin
install src/apcupsd-lite $RPM_BUILD_ROOT/sbin
ln -sf ../../etc/init.d/apcupsd $RPM_BUILD_ROOT/usr/sbin/rcapcupsd
%suse_update_desktop_file gapcmon
chmod 644 $RPM_BUILD_ROOT/usr/share/pixmaps/*.png
# fix docu permissions
rm examples/safe.apccontrol.in
find examples users_guide -type f | xargs chmod 644
# fix end-of-line encoding
dos2unix -o examples/status/SmartUPS-vs-650.status examples/snoopdecode.c examples/rpt/Smart-UPS-1500.rpt \
	examples/rpt/Back-UPS-ES-550.rpt examples/rpt/Back-UPS-CS-650.rpt examples/rpt/Back-UPS-BR-800.rpt

%post
%{fillup_and_insserv apcupsd}
# HALT_POWERDOWN_INSERT is supported since SuSE Linux 10.1, SLES 10.
# Install HALT_POWERDOWN_INSERT
if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="\(/etc/apcupsd/apccontrol killpower\|/etc/init\.d/apcupsd try-powerdown\|\)"' etc/sysconfig/shutdown ; then
  usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\).*"[[:space:]]*:\1/etc/init.d/apcupsd try-powerdown":' etc/sysconfig/shutdown
else
  echo >&2 "apcupsd: WARNING: Unknown value of HALT_POWERDOWN_INSERT in /etc/sysconfig/shutdown."
  echo >&2 "         Keeping unchanged. Should be:"
  echo >&2 "HALT_POWERDOWN_INSERT=\"/etc/init.d/apcupsd try-powerdown\""
fi
# NOTE: Up to SuSE Linux 10.0, SLES 9 installation modified /etc/init.d/halt.local.
# Now it is obsolete and should be removed.
if [ -f etc/init.d/halt.local ]
then
    if usr/bin/grep -q "XXX APCUPSD - DO NOT EDIT XXX" etc/init.d/halt.local ; then
# NOTE: SuSE Linux 8.2, SLES 8 and older have had a bug: Last "fi"
# command was not commented by $MAGICWORD and was not replaced during
# update. This script tries to detect such orphan "fi".
	usr/bin/sed -i ':1;/XXX APCUPSD - DO NOT EDIT XXX/,+1s/^fi$/& # XXX APCUPSD - DO NOT EDIT XXX/;t1;/XXX APCUPSD - DO NOT EDIT XXX/d' etc/init.d/halt.local
    fi
fi

%preun
%{stop_on_removal apcupsd}

%postun
# Remove HALT_POWERDOWN_INSERT
if test $1 -eq 0 -a ! -f /etc/init.d/apcupsd ; then
  if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="\(/etc/init\.d/apcupsd try-powerdown\)"' etc/sysconfig/shutdown ; then
    usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\)\(/etc/init\.d/apcupsd try-powerdown\)":\1":' etc/sysconfig/shutdown
  else
    echo >&2 "apcupsd: WARNING: Unknown value of HALT_POWERDOWN_INSERT in /etc/sysconfig/shutdown."
    echo >&2 "         Keeping unchanged. Should be:"
    echo >&2 "HALT_POWERDOWN_INSERT=\"\""
  fi
  if test -f etc/init.d/apcupsd-early-powerdown ; then
    echo >&2 "apcupsd: WARNING: You may want to remove your /etc/init.d/apcupsd-early-powerdown."
  fi
fi
%{restart_on_update apcupsd}
%{insserv_cleanup}

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc apcupsd-early-powerdown COPYING ChangeLog* DISCLAIMER Developers INSTALL README.SUSE ReleaseNotes kernstodo examples/
/sbin/apcupsd-lite
%dir %{_datadir}/hal
%dir %{_datadir}/hal/fdi
%dir %{_datadir}/hal/fdi/policy
%dir %{_datadir}/hal/fdi/policy/20thirdparty
%{_datadir}/hal/fdi/policy/20thirdparty/*.fdi
%{_sbindir}/apcupsd
%{_sbindir}/apcaccess
%{_sbindir}/apctest
%{_sbindir}/rcapcupsd
%{_sbindir}/smtp
/etc/init.d/apcupsd
%dir %{_sysconfdir}/apcupsd/
%{_sysconfdir}/apcupsd/apccontrol
%config(noreplace)%{_sysconfdir}/apcupsd/apcupsd.conf
%{_sysconfdir}/apcupsd/changeme
%{_sysconfdir}/apcupsd/commfailure
%{_sysconfdir}/apcupsd/commok
%config(noreplace) %{_sysconfdir}/apcupsd/hosts.conf
%config(noreplace) %{_sysconfdir}/apcupsd/multimon.conf
%{_sysconfdir}/apcupsd/onbattery
%{_sysconfdir}/apcupsd/offbattery
%{_sysconfdir}/apcupsd/apcupsd.css
%{apache_serverroot}/cgi-bin/multimon.cgi
%{apache_serverroot}/cgi-bin/upsfstats.cgi
%{apache_serverroot}/cgi-bin/upsstats.cgi
%{apache_serverroot}/cgi-bin/upsimage.cgi
%doc %{_mandir}/man?/*.*

%files gui
%defattr(-,root,root)
%{_bindir}/gapcmon
%{_datadir}/applications/gapcmon.desktop
%{_datadir}/pixmaps/*.png

%changelog