nut/nut.spec

453 lines
17 KiB
RPMSpec
Raw Normal View History

#
# spec file for package nut (Version 2.2.2)
#
# Copyright (c) 2009 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/
#
Name: nut
BuildRequires: apache2-devel dbus-1-devel gd-devel hal-devel libneon-devel libopenssl-devel libusb-devel net-snmp-devel openssl-devel pkg-config tcpd-devel
# for directory ownership:
BuildRequires: pm-utils
License: GPL v2 or later
Group: Hardware/UPS
Provides: smartups
Obsoletes: smartups
Conflicts: apcupsd
Summary: Network UPS Tools Core (Unbreakable Power Supply Monitoring)
Version: 2.2.2
Release: 71
Url: http://www.networkupstools.org/
Source: %{name}-%{version}.tar.bz2
Source1: upsd.init
Source2: README.SUSE
Source3: upsd-early-powerdown.init
Source5: nut.firewall.in
Source6: nut-disable-hal-hid-ups.fdi
Source7: nut.sleep
Patch: nut-preconfig.patch
Patch3: nut-notifyflag.patch
Patch4: nut-powersave.patch
Patch6: nut-udev.patch
Patch8: nut-libtool.patch
Patch11: nut-intptr.patch
Patch12: nut-hal.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
PreReq: pwdutils /bin/chown
Requires: nut-package = %{version}
%define apache_serverroot %(%{_sbindir}/apxs2 -q datadir 2>/dev/null || %{_sbindir}/apxs -q PREFIX)
%define CGIPATH %{apache_serverroot}/cgi-bin
%define HTMLPATH %{apache_serverroot}/htdocs
%define MODELPATH %{_prefix}/lib/ups/driver
%define STATEPATH %{_localstatedir}/lib/ups
%define CONFPATH %{_sysconfdir}/ups
%define USER upsd
%define GROUP daemon
%define LBRACE (
%define RBRACE )
%define QUOTE "
%define BACKSLASH \\
# Collect all devices listed in ups-nut-device.fdi:
%define USBDRIVERS %(set -x ; bunzip2 <%{S:0} | fgrep -a -A4 usb_device.vendor_id | tr '%{BACKSLASH}n' '-' | tr 'a-z' 'A-Z' | sed 's/--/%{BACKSLASH}n/g' | sed 's/^.*USB_DEVICE%{BACKSLASH}.VENDOR_ID%{QUOTE} INT=%{QUOTE}0X%{BACKSLASH}%{LBRACE}[^%{QUOTE}]*%{BACKSLASH}%{RBRACE}%{QUOTE}.*USB_DEVICE%{BACKSLASH}.PRODUCT_ID%{QUOTE} INT=%{QUOTE}0X%{BACKSLASH}%{LBRACE}[^%{QUOTE}]*%{BACKSLASH}%{RBRACE}%{QUOTE}.*INFO%{BACKSLASH}.ADDONS%{QUOTE} TYPE=%{QUOTE}STRLIST%{QUOTE}>%{BACKSLASH}%{LBRACE}[^<]*%{BACKSLASH}%{RBRACE}<.*$/%{BACKSLASH}3=modalias%{LBRACE}usb:v%{BACKSLASH}1p%{BACKSLASH}2d*dc*dsc*dp*ic*isc*ip*%{RBRACE}/')
# Package provides driver for USB HID UPSes, but people can live with hal addon:
Enhances: %(set -x ; echo %{QUOTE}%{USBDRIVERS}%{QUOTE} | sed -n s/^HALD-ADDON-USBHID-UPS=//p | tr '%{BACKSLASH}n' ' ')
# Package provides the only avalailable driver for other USB UPSes:
Supplements: %(set -x ; echo %{QUOTE}%{USBDRIVERS}%{QUOTE} | sed '/^HALD-ADDON-USBHID-UPS=/d;s/^.*=//' | tr '%{BACKSLASH}n' ' ')
%description
Core package of Network UPS Tools.
Network UPS Tools is a collection of programs which provide a common
interface for monitoring and administering UPS hardware.
Detailed information about supported hardware can be found in
/usr/share/doc/packages/nut.
%package drivers-net
License: GPL v2 or later
Summary: Network UPS Tools - Extra Networking Drivers (for Network Monitoring)
Group: Hardware/UPS
Requires: %{name}-classic = %{version}
Enhances: %{name}-classic
# for update from openSUSE <= 10.3, SLE <= 10
Provides: nut:%{MODELPATH}/snmp-ups
%description drivers-net
Networking drivers for the Network UPS Tools. You will need them
altogether with nut-classic to provide UPS networking support.
Network UPS Tools is a collection of programs which provide a common
interface for monitoring and administering UPS hardware.
Detailed information about supported hardware can be found in
/usr/share/doc/packages/nut.
%package -n libupsclient1
License: GPL v2 or later
Summary: Network UPS Tools Library (Unbreakable Power Supply Monitoring)
Group: System/Libraries
%description -n libupsclient1
Shared library for the Network UPS Tools.
Network UPS Tools is a collection of programs which provide a common
interface for monitoring and administering UPS hardware.
Detailed information about supported hardware can be found in
/usr/share/doc/packages/nut.
%package classic
License: GPL v2 or later
Summary: Network UPS Tools Classic Package (Monitoring Server)
Group: Hardware/UPS
Requires: %{name} = %{version}
Provides: nut-package = %{version}
Conflicts: %{name}-hal
Requires: %{_bindir}/pgrep %{_bindir}/pkill %{_bindir}/grep %{_bindir}/fgrep %{_sbindir}/lsusb %{_bindir}/readlink
PreReq: %insserv_prereq pwdutils /bin/chown /bin/chmod %{_bindir}/fgrep %{_bindir}/grep %{_bindir}/sed %{_bindir}/head %{_bindir}/md5sum
Requires: powersave
# for update from openSUSE <= 10.3, SLE <= 10
Provides: nut:%{_sbindir}/upsmon
%description classic
Classic package of Network UPS Tools.
Network UPS Tools is a collection of programs which provide a common
interface for monitoring and administering UPS hardware.
This is the standard installation that uses a layered approach to
connect all of the NUT parts.
Drivers are provided for a wide assortment of equipment. They
understand the specific language of each UPS and map it back to a
compatibility layer. This means both an expensive "smart" protocol UPS
and a simple "power strip" model can be handled transparently.
This information is cached by the network server upsd, which then
answers queries from the clients. upsd contains a number of access
control features to limit the abilities of the clients. Only
authorized hosts may monitor or control your UPS hardware if you wish.
Since the notion of monitoring over the network is built into the
software, you can hang many systems off one large UPS and they will all
shut down together.
Clients such as upsmon check on the status of the hardware and do
things when necessary. The most important task is shutting down the
operating system cleanly before the UPS runs out of power. Other
programs are also provided to log UPS status regularly, monitor status
through your web browser, and more.
Detailed information about supported hardware can be found in
/usr/share/doc/packages/nut.
%package hal
License: GPL v2 or later
Summary: Network UPS Tools Support for HAL (HAL/D-BUS Integration)
Group: Hardware/UPS
Requires: %{name} = %{version}
Provides: nut-package = %{version}
Conflicts: %{name}-classic
Requires: hal >= 0.5.8
%description hal
HAL package of Network UPS Tools is intended for use with supported USB
devices on HAL enabled desktops (Gnome and KDE).
Using this approach, you don't have to configure NUT files, nor to
manually start components, nor to install a specific NUT client.
Upon plugging your USB UPS, the right driver will be automatically
launched, and the according Power Manager GUI will pop up.
Note that this feature is still beta and incomplete. But it represents
a major evolution, and a huge user experience improvement!
Network UPS Tools is a collection of programs which provide a common
interface for monitoring and administering UPS hardware.
Detailed information about supported hardware can be found in
/usr/share/doc/packages/nut.
%package cgi
License: GPL v2 or later
Summary: Network UPS Tools Web Server Support (UPS Status Pages)
Group: Hardware/UPS
Requires: %{name}-classic = %{version}
Enhances: %{name}-classic
Supplements: packageand(%{name}-classic:apache2)
# for update from openSUSE <= 10.3, SLE <= 10
Provides: nut:/srv/www/cgi-bin/upsstats.cgi
%description cgi
Web server support package for the Network UPS Tools.
Predefined URL is http://localhost/nut/index.html
Network UPS Tools is a collection of programs which provide a common
interface for monitoring and administering UPS hardware.
Detailed information about supported hardware can be found in
/usr/share/doc/packages/nut.
%package devel
License: GPL v2 or later
Summary: Network UPS Tools (Unbreakable Power Supply Monitoring)
Group: Development/Libraries/C and C++
Requires: %{name} = %{version} openssl-devel
%description devel
Network UPS Tools is a collection of programs which provide a common
interface for monitoring and administering UPS hardware.
Detailed information about supported hardware can be found in
/usr/share/doc/packages/nut.
%prep
%setup -q
cp -a %{S:1} %{S:2} %{S:3} %{S:5} %{S:7} .
cp -a %{S:6} 20-nut-disable-hal-hid-ups.fdi
mv upsd-early-powerdown.init upsd-early-powerdown
%patch
%patch3
%if %suse_version < 1110
%patch4
%endif
%if %suse_version < 1030
%patch6 -R
%endif
%patch8
sed -i "s/@UPSD_USER@/%{USER}/g" upsd.init conf/upsmon.conf.sample
%patch11
%if %suse_version > 1030
%patch12
%endif
%if %suse_version < 1030
sed -i 's:/usr/lib/pm-utils/functions:/etc/pm/functions:' nut.sleep
%endif
sed -i s:/usr/local/ups/bin:/bin: conf/upssched.conf.sample.in
%build
autoreconf -f -i
%configure --disable-static --with-pic --libexecdir=%_prefix/lib \
--sysconfdir=%{CONFPATH}\
--datadir=%{_datadir}/nut\
--with-all\
--with-dev\
--with-linux-hiddev=%{_includedir}/linux/hiddev.h\
--with-htmlpath=%{HTMLPATH}\
--with-cgipath=%{CGIPATH}\
--with-statepath=%{STATEPATH}\
--with-drvpath=%{MODELPATH}\
--with-user=%{USER}\
--with-group=%{GROUP} \
--with-udev-dir=/etc/udev
make %{?jobs:-j%jobs}
PORT=$(sed -n 's/#define PORT //p' config.log)
if test "$PORT" = 3493 ; then
PORT=nut
fi
sed s/@PORT@/$PORT/ <nut.firewall.in >nut.firewall
%install
make DESTDIR=$RPM_BUILD_ROOT install
mkdir -p $RPM_BUILD_ROOT%{STATEPATH}
# SuSE rc
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
install -m 755 upsd.init $RPM_BUILD_ROOT%{_sysconfdir}/init.d/upsd
ln -sf ../..%{_sysconfdir}/init.d/upsd $RPM_BUILD_ROOT%{_sbindir}/rcupsd
mkdir -p $RPM_BUILD_ROOT%{STATEPATH}
%if %suse_version < 1110
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/dbus-1/system.d
install -m 644 packaging/opensuse/upsd.dbus-1 $RPM_BUILD_ROOT%{_sysconfdir}/dbus-1/system.d/upsd.conf
%endif
rename .sample "" $RPM_BUILD_ROOT%{_sysconfdir}/ups/*.sample
%if %suse_version >= 1030
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services
cp nut.firewall $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/nut
%endif
mkdir -p $RPM_BUILD_ROOT%{_datadir}/hal/fdi/policy/20thirdparty
install -m 644 20-nut-disable-hal-hid-ups.fdi $RPM_BUILD_ROOT%{_datadir}/hal/fdi/policy/20thirdparty/
%if %suse_version >= 1030
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/pm-utils/sleep.d
install nut.sleep $RPM_BUILD_ROOT%{_prefix}/lib/pm-utils/sleep.d/99nut
%else
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/pm/sleep.d
install nut.sleep $RPM_BUILD_ROOT%{_sysconfdir}/pm/sleep.d/99nut
%endif
mkdir $RPM_BUILD_ROOT/bin
mv $RPM_BUILD_ROOT%{_bindir}/upssched-cmd $RPM_BUILD_ROOT/bin/upssched-cmd
# Rename web pages to not conflict with apache2-example-pages or user home page:
mkdir $RPM_BUILD_ROOT%{HTMLPATH}/nut $RPM_BUILD_ROOT%{CGIPATH}/nut
mv $RPM_BUILD_ROOT%{HTMLPATH}/*.{html,png} $RPM_BUILD_ROOT%{HTMLPATH}/nut/
mv $RPM_BUILD_ROOT%{CGIPATH}/*.cgi $RPM_BUILD_ROOT%{CGIPATH}/nut
%{__rm} -f %{buildroot}%{_libdir}/*.la
%pre
usr/sbin/useradd -r -o -g %{GROUP} -s /bin/false \
-c "UPS daemon" -d /sbin %{USER} 2>/dev/null || :
%post
# Be sure that all files are owned by a dedicated user.
bin/chown -R %{USER}:%{GROUP} %{STATEPATH}
%post -n libupsclient1 -p /sbin/ldconfig
%postun -n libupsclient1 -p /sbin/ldconfig
%pre classic
usr/sbin/useradd -r -o -g %{GROUP} -s /bin/false \
-c "UPS daemon" -d /sbin %{USER} 2>/dev/null || :
%post classic
%{fillup_and_insserv -f -n upsd}
# Generate initial passwords.
if usr/bin/fgrep -q "password = @UPSD_INITIAL_MASTER_PASSWORD@" %{CONFPATH}/{upsmon.conf,upsd.users} ; then
UPSD_INITIAL_MASTER_PASSWORD=$(usr/bin/head -c 20 /dev/urandom | usr/bin/md5sum | usr/bin/head -c 10)
usr/bin/sed -i s/@UPSD_INITIAL_MASTER_PASSWORD@/$UPSD_INITIAL_MASTER_PASSWORD/ %{CONFPATH}/{upsmon.conf,upsd.users}
fi
if usr/bin/fgrep -q "password = @UPSD_INITIAL_SLAVE_PASSWORD@" %{CONFPATH}/upsd.users ; then
UPSD_INITIAL_SLAVE_PASSWORD=$(usr/bin/head -c 20 /dev/urandom | usr/bin/md5sum | usr/bin/head -c 10)
usr/bin/sed -i s/@UPSD_INITIAL_SLAVE_PASSWORD@/$UPSD_INITIAL_SLAVE_PASSWORD/ %{CONFPATH}/upsd.users
fi
# Be sure that all files are owned by a dedicated user.
bin/chown %{USER}:root %{CONFPATH}/upsd.conf %{CONFPATH}/upsmon.conf %{CONFPATH}/upsd.users
bin/chmod 600 %{CONFPATH}/upsd.conf %{CONFPATH}/upsmon.conf %{CONFPATH}/upsd.users
# Install HALT_POWERDOWN_INSERT
if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="\(%{_sysconfdir}/init\.d/upsd try-powerdown\|\)"' etc/sysconfig/shutdown ; then
usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\).*"[[:space:]]*:\1%{_sysconfdir}/init.d/upsd try-powerdown":' etc/sysconfig/shutdown
else
# User configured Suspend-to-disc. Keep it unchanged and be silent.
if ! usr/bin/grep -q '^HALT_POWERDOWN_INSERT="/usr/bin/powersave -U' etc/sysconfig/shutdown ; then
echo >&2 "nut: WARNING: Unknown value of HALT_POWERDOWN_INSERT in %{_sysconfdir}/sysconfig/shutdown."
echo >&2 " Keeping unchanged. Should be:"
echo >&2 "HALT_POWERDOWN_INSERT=\"%{_sysconfdir}/init.d/upsd try-powerdown\""
echo >&2 "or"
echo >&2 "HALT_POWERDOWN_INSERT=\"/usr/bin/powersave -U\""
fi
fi
# Migrate Suspend to Disc to the new convention (bnc#449861):
# It was never on by default, but documentation up to 11.0 recommends
# "shutdown -z +0" for suspend to disc. It was discontinued before 11.0.
if fgrep "shutdown -z +0" /etc/ups/upsmon.conf ; then
sed -i 's:/sbin/shutdown -z +0:/usr/bin/powersave -U:;s:shutdown -z +0:/usr/bin/powersave -U:' /etc/ups/upsmon.conf
fi
# Silently remove %{_sysconfdir}/sysconfig/smartups. File is now obsolete and
# values are copied to not replaced config files.
# %{_sysconfdir}/sysconfig/smartups was last present in SuSE Linux 10.0
rm -f %{_sysconfdir}/sysconfig/smartups
%preun classic
%{stop_on_removal upsd}
%postun classic
%{restart_on_update upsd}
# Remove HALT_POWERDOWN_INSERT
if test $1 -eq 0 -a ! -f %{_sysconfdir}/init.d/upsd ; then
if usr/bin/grep -q '^HALT_POWERDOWN_INSERT="\(%{_sysconfdir}/init\.d/upsd try-powerdown\|/usr/bin/powersave -U\)"' etc/sysconfig/shutdown ; then
usr/bin/sed -i 's:^\(HALT_POWERDOWN_INSERT="\)\(%{_sysconfdir}/init\.d/upsd try-powerdown\|/usr/bin/powersave -U\)":\1":' etc/sysconfig/shutdown
else
echo >&2 "nut: 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 %{_sysconfdir}/init.d/upsd-early-powerdown ; then
echo >&2 "nut: WARNING: You may want to remove your %{_sysconfdir}/init.d/upsd-early-powerdown."
fi
fi
%insserv_cleanup
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc AUTHORS COPYING ChangeLog MAINTAINERS NEWS README README.SUSE UPGRADING upsd-early-powerdown docs/FAQ docs/*.txt docs/cables
%dir %{_prefix}/lib/ups
%{_datadir}/nut
%{_datadir}/hal/fdi/policy/20thirdparty/20-nut-disable-hal-hid-ups.fdi
%doc %{_mandir}/man8/*.*
%exclude %doc %{_mandir}/man8/ups*.*
%exclude %doc %{_mandir}/man8/netxml-ups*.*
%exclude %doc %{_mandir}/man8/snmp-ups*.*
%attr(700,%{USER},%{GROUP}) %{STATEPATH}
%dir %{MODELPATH}
%{MODELPATH}/*
%exclude %{MODELPATH}/snmp-ups
%exclude %{MODELPATH}/netxml-ups
%files drivers-net
%defattr(-,root,root)
%{MODELPATH}/snmp-ups
%{MODELPATH}/netxml-ups
%doc %{_mandir}/man8/netxml-ups*.*
%doc %{_mandir}/man8/snmp-ups*.*
%files -n libupsclient1
%defattr(-,root,root)
%{_libdir}/*.so.*
%files classic
%defattr(-,root,root)
%config(noreplace) %{CONFPATH}/hosts.conf
%config(noreplace) %attr(600,%{USER},root) %{CONFPATH}/upsd.conf
%config(noreplace) %attr(600,%{USER},root) %{CONFPATH}/upsd.users
%config(noreplace) %attr(600,%{USER},root) %{CONFPATH}/upsmon.conf
%dir %{CONFPATH}
%config(noreplace) %{CONFPATH}/ups.conf
%config(noreplace) %{CONFPATH}/upsset.conf
%config(noreplace) %{CONFPATH}/upssched.conf
%{_bindir}/*
/bin/*
%doc %{_mandir}/man5/*.*
%doc %{_mandir}/man8/ups*.*
%if %suse_version >= 1030
%{_prefix}/lib/pm-utils/sleep.d/99nut
%else
%{_sysconfdir}/pm/sleep.d/99nut
%endif
%{_sbindir}/*
%if %suse_version < 1110
%{_sysconfdir}/dbus-1/system.d/upsd.conf
%endif
%if %suse_version >= 1030
%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/nut
%endif
%{_sysconfdir}/init.d/upsd
%dir %{_sysconfdir}/udev
%dir %{_sysconfdir}/udev/rules.d
%{_sysconfdir}/udev/rules.d/*.rules
%files cgi
%defattr(-,root,root)
%{CGIPATH}/nut
%{HTMLPATH}/nut
%config(noreplace) %{CONFPATH}/upsstats-single.html
%config(noreplace) %{CONFPATH}/upsstats.html
%files hal
%defattr(-,root,root)
%{_datadir}/hal/fdi/information/20thirdparty/20-ups-nut-device.fdi
%{_prefix}/lib/hal/*
%files devel
%defattr(-,root,root)
%{_includedir}/*.h
%{_libdir}/*.so
%{_libdir}/pkgconfig/*.pc
%doc %{_mandir}/man3/*.*
%changelog