File apcupsd.spec of Package apcupsd

#
# spec file for package apcupsd
#
# Copyright (c) 2015 SUSE LINUX 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/
#


Name:           apcupsd
BuildRequires:  apache2-devel
BuildRequires:  automake
BuildRequires:  distribution-release
BuildRequires:  dos2unix
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  gconf2-devel
BuildRequires:  gd-devel
BuildRequires:  gnome-vfs2-devel
BuildRequires:  gtk2-devel
BuildRequires:  mailx
BuildRequires:  ncurses-devel
BuildRequires:  net-snmp-devel
BuildRequires:  pm-utils
BuildRequires:  tcpd-devel
BuildRequires:  update-desktop-files
BuildRequires:  xorg-x11-devel
%if 0%{?suse_version} <= 1140
BuildRequires:  sysvinit
%else
%if 0%{?suse_version} >= 1220
BuildRequires:  systemd-sysvinit
%else
BuildRequires:  sysvinit-init
%endif
%endif
Summary:        APC UPS Daemon (Powerful Daemon for APC UPSs)
License:        GPL-2.0
Group:          Hardware/UPS
Version:        3.14.10
Release:        0
Url:            http://www.apcupsd.com/
Source:         apcupsd-%{version}.tar.bz2
Source1:        apcupsd.init
Source2:        README.SUSE
Source3:        apcupsd-early-powerdown.init
Source4:        apcupsd.hibernate
Source5:        apcupsd.sysconfig
Source6:        apcupsd.logrotate 
Source7:        apcupsd-httpd.conf
# PATCH-FIX-OPENSUSE apcupsd-suse.patch sbrabec@suse.cz -- Do not perform halt script alternation on install.
Patch:          apcupsd-suse.patch
# PATCH-FIX-OPENSUSE apcupsd-gpp.patch sbrabec@suse.cz -- Build against C++ unfriendly system tcpd.h. See below.
Patch1:         apcupsd-gpp.patch
# PATCH-FEATURE-OPENSUSE apcupsd-hibernate.patch sbrabec@suse.cz -- Support for hibernation on powerfail.
Patch2:         apcupsd-hibernate.patch
# PATCH-FEATURE-OPENSUSE apcupsd-powersave.patch sbrabec@suse.cz -- Call powersave-notify in distros where it is available.
Patch3:         apcupsd-powersave.patch
# PATCH-FIX-OPENSUSE apcupsd-3.14.6-undef-MIB-for-new-net-snmp.diff seife@opensuse.org -- Fix build with newer net-snmp by undefining MIB.
Patch9:         apcupsd-3.14.6-undef-MIB-for-new-net-snmp.diff
Patch10:        apcupsd-3.14.1-cloexec.patch
# systemd support
Patch11:        apcupsd-3.14.8-systemd.patch
#fix FTBFS, c++ linking needs -lstdc++ explicitly
Patch12:        apcupsd-3.14.8-cxxld.patch
# fix crash in gui, rhbz#578276
Patch13:        apcupsd-3.14.9-fixgui.patch
# FSF adress is incorrect
Patch14:        fix-fsf-adress.patch
# PATCH-FIX-UPSTREAM apcupsd-3.14.10-nodbg.patch matwey.kornilov@gmail.com brc#1053324
Patch15:        apcupsd-3.14.10-nodbg.patch
PreReq:         %fillup_prereq
%if 0%{?suse_version} < 1220
PreReq:         %insserv_prereq /usr/bin/sed /usr/bin/grep
%endif
Requires:       /usr/bin/mail
%if 0%{?suse_version} >= 1220
%{?systemd_requires}
%endif
Suggests:       logrotate
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 cgi
Summary:        Web interface for apcupsd
Group:          Hardware/UPS
Requires:       %{name} = %{version}

%description cgi
A CGI interface to the APC UPS monitoring daemon.

%package gui

Summary:        APC UPS Monitor GUI (for APC UPSs)
Group:          Hardware/UPS
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
#This is needed as apcupsd doesn't recognize ppc64 correctly
cp /usr/share/automake*/config.{guess,sub} autoconf/ 
cp -a %{S:1} platforms/suse/apcupsd.in
cp -a %{S:2} %{S:4} %{S:5} .
cp -a %{S:3} apcupsd-early-powerdown
chmod +x apcupsd-early-powerdown
%patch
# To be surely in sync with tcpd API, build against system header. It requires a patch.
rm include/tcpd.h
%patch1
%patch2
%if %suse_version < 1110
%patch3
%endif
chmod -x kernstodo
%patch9
%patch10 -p1
%patch11 -p1 -b .systemd
%patch12 -p1 -b .cxxld
%patch13 -p1 -b .fixgui
%patch14 -p1
%patch15 -p1

sed -i '/^#!/d' %{SOURCE1}

%build
%configure\
	--sysconfdir=%{_sysconfdir}/%{name}\
	--with-libwrap\
	--enable-all\
	--enable-nls\
	--with-cgi-bin=%{apache_serverroot}/cgi-bin
make %{?_smp_mflags}

%install
%makeinstall
install -m744 platforms/apccontrol \
              $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/apccontrol
%if 0%{?suse_version} < 1220
mkdir -p $RPM_BUILD_ROOT%{_initrddir}
ln -sf ../../etc/init.d/%{name} $RPM_BUILD_ROOT/%{_sbindir}/rc%{name}
%endif
%suse_update_desktop_file gapcmon
chmod 644 $RPM_BUILD_ROOT/%{_datadir}/pixmaps/*.png
# Cleanup for later doc macro processing
chmod -x examples/*.c
rm examples/*.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
# hid-ups.rpt is duplicate by BackUPS.rpt
%fdupes -s examples/rpt/

rm -r $RPM_BUILD_ROOT/%{_datadir}/hal
mkdir -p $RPM_BUILD_ROOT/etc/pm/sleep.d
sed "s:@PWRFAILDIR@:%{_sysconfdir}/%{name}:g" <%{name}.hibernate >$RPM_BUILD_ROOT/etc/pm/sleep.d/99apcupsd
chmod +x $RPM_BUILD_ROOT/etc/pm/sleep.d/99%{name}
mkdir -p $RPM_BUILD_ROOT/var/adm/fillup-templates
cp %{name}.sysconfig $RPM_BUILD_ROOT/var/adm/fillup-templates/sysconfig.%{name}

# systemd support and remove initd support for opensuse 12.2 and higher
%if 0%{?suse_version} >= 1220
install -p -D -m644 %{name}.service $RPM_BUILD_ROOT%{_unitdir}/%{name}.service
install -p -D -m755 %{name}_shutdown $RPM_BUILD_ROOT/usr/lib/systemd/system-shutdown/%{name}_shutdown
rm $RPM_BUILD_ROOT/etc/init.d/%{name}
%endif

install -d %{buildroot}%{_sysconfdir}/logrotate.d
install -m0644 %{SOURCE6} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
install -d %{buildroot}%{_sysconfdir}/apache2/conf.d/
install -m0644 %{SOURCE7} %{buildroot}%{_sysconfdir}/apache2/conf.d/%{name}.conf

%post
%{fillup_only}
%if 0%{?suse_version} >= 1220
%service_add_post %{name}.service
%else
# 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/%{name}/apccontrol killpower\|/etc/init\.d/%{name} try-powerdown\|\)"' etc/sysconfig/shutdown ; then
  usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\).*"[[:space:]]*:\1/etc/init.d/%{name} 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
%endif

%preun
%if 0%{?suse_version} >= 1220
%service_del_preun %{name}.service
%else
%{stop_on_removal apcupsd}
%endif

%postun
%if 0%{?suse_version} >= 1220
%service_del_postun %{name}.service
%else
# Remove HALT_POWERDOWN_INSERT
if test $1 -eq 0 -a ! -f /etc/init.d/%{name} ; then
  if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="\(/etc/init\.d/%{name} try-powerdown\)"' etc/sysconfig/shutdown ; then
    usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\)\(/etc/init\.d/%{name} try-powerdown\)":\1":' etc/sysconfig/shutdown
  else
    echo >&2 "%{name}: 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/%{name}-early-powerdown ; then
    echo >&2 "%{name}: WARNING: You may want to remove your /etc/init.d/%{name}-early-powerdown."
  fi
fi
%{restart_on_update apcupsd}
%{insserv_cleanup}
%endif

%files
%defattr(-,root,root)
%doc COPYING ChangeLog examples ReleaseNotes README.SUSE
%{_sbindir}/%{name}
%{_sbindir}/apcaccess
%{_sbindir}/apctest
%{_sbindir}/smtp
%if 0%{?suse_version} < 1220
%{_initrddir}/%{name}
%{_sbindir}/rc%{name}
%else
%{_unitdir}/%{name}.service
/usr/lib/systemd/system-shutdown/%{name}_shutdown
%endif
/etc/pm/sleep.d/99%{name}
%dir %{_sysconfdir}/%{name}/
%config(noreplace) %{_sysconfdir}/%{name}/changeme
%config(noreplace) %{_sysconfdir}/%{name}/commfailure
%config(noreplace) %{_sysconfdir}/%{name}/commok
%config(noreplace) %{_sysconfdir}/%{name}/onbattery
%config(noreplace) %{_sysconfdir}/%{name}/offbattery
%config(noreplace) %{_sysconfdir}/logrotate.d/apcupsd
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%attr(0755,root,root) %{_sysconfdir}/apcupsd/apccontrol
%{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?/*.*
/var/adm/fillup-templates/sysconfig.*

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

%files cgi
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/apache2/conf.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.css
%config(noreplace) %{_sysconfdir}/%{name}/hosts.conf
%config(noreplace) %{_sysconfdir}/%{name}/multimon.conf

%changelog