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/
#


%define apache_serverroot %(%{_sbindir}/apxs2 -q datadir 2>/dev/null || %{_sbindir}/apxs -q PREFIX)
Name:           apcupsd
Version:        3.14.13
Release:        0
Summary:        APC UPS Daemon (Powerful Daemon for APC UPSs)
License:        GPL-2.0
Group:          Hardware/UPS
Url:            http://www.apcupsd.com/
Source:         http://downloads.sourceforge.net/project/apcupsd/apcupsd%%20-%%20Stable/%{version}/apcupsd-%{version}.tar.gz
Source1:        apcupsd.init
Source2:        README.SUSE
Source4:        %{name}.hibernate
Source5:        %{name}.sysconfig
Source6:        %{name}.logrotate
Source7:        apcupsd-httpd.conf
Source8:        http://downloads.sourceforge.net/project/apcupsd/apcupsd%%20-%%20Stable/%{version}/apcupsd-%{version}.tar.gz.sig
Source9:        %{name}.keyring
Source10:       %{name}.firewall
# PATCH-FIX-OPENSUSE apcupsd-suse.patch sbrabec@suse.cz -- Do not perform halt script alternation on install.
Patch0:         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-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
# PATCH-FIX-OPENSUSE apcupsd-3.14.1-cloexec.patch cristian.rodriguez@opensuse.org -- Close the socket on exec - avoid leaked file descriptors, patch from Fedora.
Patch10:        apcupsd-3.14.1-cloexec.patch
# PATCH-FIX-OPENSUSE apcupsd-3.14.8-systemd.patch p.drouand@gmail.com -- systemd support
Patch11:        apcupsd-3.14.8-systemd.patch
# PATCH-FIX-OPENSUSE apcupsd-3.14.8-cxxld.patch p.drouand@gmail.com -- fix FTBFS, c++ linking needs -lstdc++ explicitly
Patch12:        apcupsd-3.14.8-cxxld.patch
# PATCH-FIX-OPENSUSE apcupsd-3.14.9-fixgui.patch rhbz#578276 p.drouand@gmail.com -- fix crash in gui
Patch13:        apcupsd-3.14.9-fixgui.patch
# PATCH-FIX-OPENSUSE fix-fsf-adress.patch p.drouand@gmail.com -- FSF adress is incorrect
Patch14:        fix-fsf-adress.patch
# PATCH-FEATURE-OPENSUSE apcupsd-pm-utils.patch sbrabec@suse.cz -- Use pm-utils in openSUSE < 13.1 and SLE < 12
Patch15:        apcupsd-pm-utils.patch
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:  libusb-devel
BuildRequires:  mailx
BuildRequires:  ncurses-devel
BuildRequires:  net-snmp-devel
BuildRequires:  tcpd-devel
BuildRequires:  update-desktop-files
BuildRequires:  xorg-x11-devel
Requires:       %{_bindir}/mail
Requires(post): %fillup_prereq
# sed and grep are still prerequred to finish upgrade from sysvinit scripts:
Requires(post): %{_bindir}/sed %{_bindir}/grep
Suggests:       logrotate
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} > 1210
BuildRequires:  systemd-rpm-macros
BuildRequires:  systemd-sysvinit
%else
BuildRequires:  sysvinit
%endif
%if 0%{?suse_version} >= 1310
BuildRequires:  systemd
%else
BuildRequires:  pm-utils
%endif
%if 0%{?suse_version} > 1220
%{?systemd_requires}
%else
Requires(post): %insserv_prereq
%endif

%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 %{_datadir}/automake*/config.{guess,sub} autoconf/
cp -a %{SOURCE1} platforms/suse/apcupsd.in
cp -a %{SOURCE2} %{SOURCE4} %{SOURCE5} .
%patch0
# To be surely in sync with tcpd API, build against system header. It requires a patch.
rm include/tcpd.h
%patch1
%patch2
%patch9
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
sed -i '/^#!/d' %{SOURCE1}
%if 0%{?suse_version} < 1310
%patch15
%endif

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

%install
make DESTDIR=%{buildroot} install %{?_smp_mflags}
install -m744 platforms/apccontrol \
              %{buildroot}%{_sysconfdir}/%{name}/apccontrol
%if 0%{?suse_version} > 1220
ln -sf %{_sbindir}/service %{buildroot}/%{_sbindir}/rc%{name}
%else
mkdir -p %{buildroot}%{_initddir}
ln -sf ../..%{_initddir}/%{name} %{buildroot}/%{_sbindir}/rc%{name}
%endif
%suse_update_desktop_file gapcmon
chmod 644 %{buildroot}/%{_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 %{buildroot}/%{_datadir}/hal
%if 0%{?suse_version} >= 1310
mkdir -p %{buildroot}%{_libexecdir}/systemd/system-sleep
sed "s:@PWRFAILDIR@:%{_sysconfdir}/%{name}:g" <%{name}.hibernate >%{buildroot}%{_libexecdir}/systemd/system-sleep/apcupsd.sh
chmod +x %{buildroot}%{_libexecdir}/systemd/system-sleep/apcupsd.sh
%else
mkdir -p %{buildroot}%{_sysconfdir}/pm/sleep.d
sed "s:@PWRFAILDIR@:%{_sysconfdir}/%{name}:g" <%{name}.hibernate >%{buildroot}%{_sysconfdir}/pm/sleep.d/99apcupsd
chmod +x %{buildroot}%{_sysconfdir}/pm/sleep.d/99%{name}
%endif
mkdir -p %{buildroot}%{_localstatedir}/adm/fillup-templates
cp %{name}.sysconfig %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}

# systemd support and remove initd support for opensuse 12.2 and higher
%if 0%{?suse_version} > 1210
install -p -D -m644 %{name}.service %{buildroot}%{_unitdir}/%{name}.service
install -p -D -m755 %{name}_shutdown %{buildroot}%{_libexecdir}/systemd/system-shutdown/%{name}_shutdown
rm %{buildroot}%{_initddir}/%{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

# firewall config
install -m 644 -D %{SOURCE5} %{buildroot}/%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}

%pre
%if 0%{?suse_version} > 1220
%service_add_pre %{name}.service
%endif

%post
%if 0%{?suse_version} > 1220
%fillup_only
%service_add_post %{name}.service
# Remove HALT_POWERDOWN_INSERT, it is not needed with systemd (it was last time filled in 13.1).
# We need to handle only the last form, which was already used in SLE11.
if test -f etc/sysconfig/shutdown ; then
  if usr/bin/grep -q '^HALT_POWERDOWN_INSERT=' etc/sysconfig/shutdown ; then
    if ! usr/bin/grep -q '^HALT_POWERDOWN_INSERT=""' etc/sysconfig/shutdown ; then
      if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="%{_sysconfdir}/init\.d/apcupsd try-powerdown"' etc/sysconfig/shutdown ; then
        usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\)%{_sysconfdir}/init\.d/apcupsd try-powerdown":\1":' etc/sysconfig/shutdown
      else
        echo >&2 "apcupsd: WARNING: Unknown value of HALT_POWERDOWN_INSERT in %{_sysconfdir}/sysconfig/shutdown."
        echo >&2 "         Keeping unchanged. If it still exists, it should be:"
        echo >&2 "HALT_POWERDOWN_INSERT=\"\""
      fi
    fi
  fi
fi
# User installed file, by default in docdir. Not needed any more, and will never be.
rm -f etc/init.d/apcupsd-early-powerdown
%else
%{fillup_and_insserv %{name}}
# HALT_POWERDOWN_INSERT is supported since SuSE Linux 10.1, SLES 10.
# Install HALT_POWERDOWN_INSERT
if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="\(%{_sysconfdir}/apcupsd/apccontrol killpower\|%{_sysconfdir}/init\.d/apcupsd try-powerdown\|\)"' etc/sysconfig/shutdown ; then
  usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\).*"[[:space:]]*:\1%{_initddir}/apcupsd try-powerdown":' etc/sysconfig/shutdown
else
  echo >&2 "%{name}: WARNING: Unknown value of HALT_POWERDOWN_INSERT in %{_sysconfdir}/sysconfig/shutdown."
  echo >&2 "         Keeping unchanged. Should be:"
  echo >&2 "HALT_POWERDOWN_INSERT=\"%{_initddir}/apcupsd try-powerdown\""
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 %{_initddir}/%{name} ; then
  if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="\(%{_sysconfdir}/init\.d/apcupsd try-powerdown\)"' etc/sysconfig/shutdown ; then
    usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\)\(%{_sysconfdir}/init\.d/apcupsd try-powerdown\)":\1":' etc/sysconfig/shutdown
  else
    echo >&2 "apcupsd: WARNING: Unknown value of HALT_POWERDOWN_INSERT in %{_sysconfdir}/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 "%{name}: WARNING: You may want to remove your %{_initddir}/apcupsd-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
%{_sbindir}/rc%{name}
%if 0%{?suse_version} <= 1220
%{_initddir}/%{name}
%else
%{_unitdir}/%{name}.service
%{_libexecdir}/systemd/system-shutdown/%{name}_shutdown
%endif
%if 0%{?suse_version} >= 1310
%{_libexecdir}/systemd/system-sleep/%{name}.sh
%else
%{_sysconfdir}/pm/sleep.d/99%{name}
%endif
%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
%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{name}
%attr(0755,root,root) %{_sysconfdir}/apcupsd/apccontrol
%{_mandir}/man?/*.*
%{_localstatedir}/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
%{apache_serverroot}/cgi-bin/multimon.cgi
%{apache_serverroot}/cgi-bin/upsfstats.cgi
%{apache_serverroot}/cgi-bin/upsstats.cgi
%{apache_serverroot}/cgi-bin/upsimage.cgi

%changelog
openSUSE Build Service is sponsored by